Skip to content

Commit 92b1982

Browse files
leebs0521m-a-king
authored andcommitted
feat: QueryDsl 의존성 추가 (#28)
* build(query-dsl): QueryDsl 의존성 추가 * chore: QueryDsl Q클래스 .gitignore 추가 * feat: QueryDsl Config 추가 * feat: location 도메인 queryDsl 적용 * chore: 불필요한 import 제거 * chore: 개행 추가
1 parent fea0b5d commit 92b1982

File tree

6 files changed

+92
-3
lines changed

6 files changed

+92
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ out/
3636
### VS Code ###
3737
.vscode/
3838

39+
### resources
40+
/src/main/generated/
3941

4042
### env file ###
41-
*.env
43+
*.env

build.gradle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ dependencies {
3737
runtimeOnly 'com.h2database:h2'
3838
runtimeOnly 'com.mysql:mysql-connector-j'
3939

40+
// Querydsl
41+
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
42+
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
43+
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
44+
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
45+
4046
// OAuth & Security
4147
implementation 'org.springframework.boot:spring-boot-starter-oauth2-authorization-server'
4248
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
@@ -62,6 +68,24 @@ dependencies {
6268
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
6369
}
6470

71+
// Querydsl 설정
72+
def generated = 'src/main/generated'
73+
74+
// QClass 파일 생성 위치를 지정
75+
tasks.withType(JavaCompile).configureEach {
76+
options.getGeneratedSourceOutputDirectory().set(file(generated))
77+
}
78+
79+
// java source set 에 querydsl QClass 위치 추가
80+
sourceSets {
81+
main.java.srcDirs += [ generated ]
82+
}
83+
84+
// gradle clean 시에 QClass 디렉토리 삭제
85+
clean {
86+
delete file(generated)
87+
}
88+
6589
tasks.named('test') {
6690
useJUnitPlatform()
6791
jvmArgs("-XX:+EnableDynamicAgentLoading")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.somemore.global.configure;
2+
3+
import com.querydsl.jpa.impl.JPAQueryFactory;
4+
import jakarta.persistence.EntityManager;
5+
import jakarta.persistence.PersistenceContext;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
@Configuration
10+
public class QueryDslConfig {
11+
12+
@PersistenceContext
13+
private EntityManager em;
14+
15+
@Bean
16+
public JPAQueryFactory jpaQueryFactory() {
17+
return new JPAQueryFactory(em);
18+
}
19+
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.somemore.location.repository;
2+
3+
import com.somemore.location.domain.Location;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface LocationJpaRepository extends JpaRepository<Location, Long> {
7+
8+
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.somemore.location.repository;
22

33
import com.somemore.location.domain.Location;
4-
import org.springframework.data.jpa.repository.JpaRepository;
4+
import java.util.Optional;
55

6-
public interface LocationRepository extends JpaRepository<Location, Long> {
6+
public interface LocationRepository {
77

8+
Location save(Location location);
9+
10+
Optional<Location> findById(Long id);
11+
12+
void deleteAllInBatch();
813
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.somemore.location.repository;
2+
3+
import com.querydsl.jpa.impl.JPAQueryFactory;
4+
import com.somemore.location.domain.Location;
5+
import java.util.Optional;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.stereotype.Repository;
8+
9+
@RequiredArgsConstructor
10+
@Repository
11+
public class LocationRepositoryImpl implements LocationRepository {
12+
13+
private final LocationJpaRepository locationJpaRepository;
14+
private final JPAQueryFactory queryFactory;
15+
16+
@Override
17+
public Location save(Location location) {
18+
return locationJpaRepository.save(location);
19+
}
20+
21+
@Override
22+
public Optional<Location> findById(Long id) {
23+
return locationJpaRepository.findById(id);
24+
}
25+
26+
@Override
27+
public void deleteAllInBatch() {
28+
locationJpaRepository.deleteAllInBatch();
29+
}
30+
}

0 commit comments

Comments
 (0)