분류 전체보기 1341

Ch06. 스프링 데이터 JPA가 제공하는 Querydsl 기능 - Querydsl Web 지원

공식 URL: https://docs.spring.io/spring-data/jpa/docs/2.2.3.RELEASE/reference/html/#core.web.type-safe Spring Data JPA - Reference Documentation Example 108. Using @Transactional at query methods @Transactional(readOnly = true) public interface UserRepository extends JpaRepository { List findByLastname(String lastname); @Modifying @Transactional @Query("delete from User u where u.active = false") ..

실전! Querydsl 2022.01.02

Ch06. 스프링 데이터 JPA가 제공하는 Querydsl 기능 - 인터페이스 지원(QuerydslPredicateExecutor)

여기서 소개하는 기능은 제약이 커서 복잡한 실무 환경에서 사용하기에는 많이 부족하다. 그래도 스프링 데이터에서 제공하는 기능이므로 간단히 소개하고, 왜 부족한지 설명하겠다 인터페이스 지원 - QuerydslPredicateExecutor 공식 URL: https://docs.spring.io/spring-data/jpa/docs/2.2.3.RELEASE/reference/html/#core.extensions.querydsl Spring Data JPA - Reference Documentation Example 108. Using @Transactional at query methods @Transactional(readOnly = true) public interface UserRepository e..

실전! Querydsl 2022.01.02

Ch05. 실무 활용(스프링 데이터 JPA와 Querydsl) - 스프링 데이터 페이징 활용(CountQuery 최적화, 컨트롤러 개발)

CountQuery 최적화 때에 따라서 Count 쿼리를 생략 가능할 수가 있다. 스프링 데이터 라이브러리가 제공 count 쿼리가 생략 가능한 경우 생략해서 처리 페이지 시작이면서 컨텐츠 사이즈가 페이지 사이즈보다 작을 때 마지막 페이지 일 때 (offset + 컨텐츠 사이즈를 더해서 전체 사이즈 구함) 컨트롤러 개발 스프링 데이터 정렬(Sort) JPAQuery query = queryFactory .selectFrom(member); for (Sort.Order o : pageable.getSort()) { PathBuilder pathBuilder = new PathBuilder(member.getType(), member.getMetadata()); query.orderBy(new OrderSp..

실전! Querydsl 2022.01.02

Ch05. 실무 활용(스프링 데이터 JPA와 Querydsl) - 스프링 데이터 페이징 활용(Querydsl 페이징 연동)

스프링 데이터의 Page, Pageable을 활용해보자. 전체 카운트를 한 번에 조회하는 단순한 방법 데이터 내용과 전체 카운트를 별도로 조회하는 방법 CountQuery와 PageQuery 같이 동작 쿼리를 실행할 때, Count 도 같이 실행돼서 가지고 온다. 새로 Page 객체를 만들어서 반환해 주면된다. CountQuery와 PageQuery 따로 동작 성능 최적화를 위해 사용한다 Count쿼리에서 굳이 Join을 할 필요가 없이 다르게 동작할 경우, count쿼리를 따로 동작시켜 성능 최적화를 할 수 있다.

실전! Querydsl 2022.01.02

Ch05. 실무 활용(스프링 데이터 JPA와 Querydsl) - 사용자 정의 리포지토리

SpringDataJpa는 내가 원하는 구현 코드를 넣기 위해서는 사용자 정의 인터페이스를 만들어야 한다. 사용자 정의 리포지토리 사용법 사용자 정의 인터페이스 작성 사용자 정의 인터페이스 구현 스프링 데이터 리포지토리에 사용자 정의 인터페이스 상속 public class MemberRepositoryImpl implements MemberRepositoryCustom{ private final JPAQueryFactory queryFactory; public MemberRepositoryImpl(EntityManager em) { this.queryFactory = new JPAQueryFactory(em); } @Override public List search(MemberSearchCondition..

실전! Querydsl 2022.01.02

Ch04. 실무 활용(순수 JPA와 Querydsl) - 순수 JPA 리포지토리와 Querydsl

순수 JPA Repository 만들기 @Repository //@RequiredArgsConstructor //이걸 사용해 줄수도 있다. public class MemberJpaRepository { private final EntityManager em; //queryDSL을 사용하기 위한 주입 //동시성 문제는 발생하지 않는다 -> entityManager에 의존하고 있기 때문에 private final JPAQueryFactory queryFactory; public MemberJpaRepository(EntityManager em,JPAQueryFactory jpaQueryFactory) { this.em = em; this.queryFactory = new JPAQueryFactory(em);..

실전! Querydsl 2022.01.01

Ch03. 중급 문법 - SQL function 호출하기

SQL function은 JPA와 같이 Dialect에 등록된 내용만 호출할 수 있다. 현재는 H2 DB를 사용하기 때문에 H2 Dialect에 등록되어 있는 함수를 사용할 수가 있다. 추가로 내가 등록하고 싶다면 JPA 기본편을 참조해서 application.yml에 추가 설정을 해야 된다. lower 같은 ansi 표준 함수들은 querydsl이 상당 부분 내장하고 있다. 따라서 다음과 같이 처리해도 결과는 같다.

실전! Querydsl 2021.12.31