Skip to content

Commit

Permalink
[refactor] JPAQueryFactory를 BeanContainer로 생성 후 관리하도록 변경
Browse files Browse the repository at this point in the history
- 기존 로직은 메서드에서 매번 팩토리를 생성
- 매번 메서드마다 팩토리를 생성하는 코드 중복이 일어남
- 팩토리를 매번 생성하면 성능적인 오버헤드가 생김
- 팩토리는 Thread-Safe한 객체기 때문에 싱글톤으로 관리되어도 아무런 문제가 없다.
  • Loading branch information
Hyeon-Uk committed Aug 16, 2024
1 parent c77bcb0 commit 0706db9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/main/java/camp/woowak/lab/web/config/QuerydslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package camp.woowak.lab.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.querydsl.jpa.impl.JPAQueryFactory;

import jakarta.persistence.EntityManager;

@Configuration
public class QuerydslConfig {
@Bean
public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
return new JPAQueryFactory(entityManager);
}
}
7 changes: 4 additions & 3 deletions src/main/java/camp/woowak/lab/web/dao/store/StoreDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
@Repository
@Transactional(readOnly = true)
public class StoreDao {
@PersistenceContext
private EntityManager entityManager;
private final JPAQueryFactory qf;
public StoreDao(JPAQueryFactory qf) {
this.qf = qf;
}

public StoreInfoResponse findAllStoreList() {
JPAQueryFactory qf = new JPAQueryFactory(entityManager);
QStore store = QStore.store;

List<Store> fetchResult = qf.select(store)
Expand Down

0 comments on commit 0706db9

Please sign in to comment.