From 71eaf33332955c4dc82036da1cb7ac2fa7266e26 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Thu, 5 Dec 2024 20:52:09 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[#286]=20chore(.gitignore):=20Qclass?= =?UTF-8?q?=EB=A5=BC=20ignore=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bf9eeb1d..4b05952c 100644 --- a/.gitignore +++ b/.gitignore @@ -180,4 +180,7 @@ Temporary Items .idea/ # Ignore application-local.yml -src/main/resources/application-local.yml \ No newline at end of file +src/main/resources/application-local.yml + +## Ignore Qclass +src/main/generated/querydsl From 1d6e0c073571e85dd0d000055ccfff552d3f62a6 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Thu, 5 Dec 2024 20:52:33 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[#286]=20chore(build.gradle):=20QueryDSL=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index dd665e45..b0225719 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,9 @@ configurations { compileOnly { extendsFrom annotationProcessor } + + // Configure libraries related to QueryDSL to be required only at compile-time and add QueryDSL configuration to the compile classpath. + querydsl.extendsFrom compileClasspath } repositories { @@ -25,6 +28,11 @@ repositories { maven { url "https://repo.spring.io/snapshot" } } +// Set global variables used in the project +ext { + set('queryDslVersion', "5.0.0") +} + dependencies { // Spring implementation 'org.springframework.boot:spring-boot-starter-web' @@ -74,9 +82,15 @@ dependencies { implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4' implementation 'io.awspring.cloud:spring-cloud-starter-aws-secrets-manager-config:2.4.4' - //coolsms + // coolsms implementation 'net.nurigo:sdk:4.3.0' implementation 'net.nurigo:javaSDK:2.2' + + // QueryDSL + implementation "com.querydsl:querydsl-jpa:${queryDslVersion}:jakarta" + annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" } jar { @@ -85,4 +99,23 @@ jar { tasks.named('test') { useJUnitPlatform() -} \ No newline at end of file +} + +// Set the directory path where the Q-Class will be generated. +def queryDslSrcDir = 'src/main/generated/querydsl/' + +// When executing the JavaCompile task, set the output directory for the generated source code to queryDslSrcDir +tasks.withType(JavaCompile).configureEach { + options.getGeneratedSourceOutputDirectory().set(file(queryDslSrcDir)) +} + +// Add the Q-Class files to the directory path recognized as source code. +// This ensures that the Q-Class is treated as a regular Java class and included in the classpath during compilation and execution. +sourceSets { + main.java.srcDirs += [queryDslSrcDir] +} + +// Configure the clean task to delete the specified directory, automatically removing the generated Q-Class. +clean { + delete file(queryDslSrcDir) +} From 6e9ac0db0dbe6be1e76f9b51a429b863294b84f4 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Thu, 5 Dec 2024 20:53:25 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[#286]=20feat(JpaAuditingConfig):=20JPAQuer?= =?UTF-8?q?yFactory=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JPA 환경을 구성하고 QueryDSL을 사용할 수 있도록 설정하는 클래스 - 매번 EntityManager를 주입받아서 구성해야 하는 JPAQueryFactory를 bean으로 등록하여 간편하게 사용하기 위한 목적으로 구성 --- .../global/common/config/JpaAuditingConfig.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java b/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java index c148863c..1a1d1ad7 100644 --- a/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java +++ b/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java @@ -1,9 +1,23 @@ package com.beat.global.common.config; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + @Configuration @EnableJpaAuditing public class JpaAuditingConfig { + + @PersistenceContext + private EntityManager em; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(em); + } } From 11a335182f44444d3b4651b306327a9df06185ed Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Fri, 6 Dec 2024 16:29:20 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[#286]=20feat(QueryDslConfig):=20QueryDsl?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20Config=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/common/config/QueryDslConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/beat/global/common/config/QueryDslConfig.java diff --git a/src/main/java/com/beat/global/common/config/QueryDslConfig.java b/src/main/java/com/beat/global/common/config/QueryDslConfig.java new file mode 100644 index 00000000..69ef11ac --- /dev/null +++ b/src/main/java/com/beat/global/common/config/QueryDslConfig.java @@ -0,0 +1,20 @@ +package com.beat.global.common.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.querydsl.jpa.impl.JPAQueryFactory; + +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + +@Configuration +public class QueryDslConfig { + @PersistenceContext + private EntityManager em; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(em); + } +} From 5fe4d69833c1f68055afc84693c19b97595d52b7 Mon Sep 17 00:00:00 2001 From: DongHoon Lee Date: Fri, 6 Dec 2024 16:29:49 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[#286]=20refactor(JpaAuditingConfig):=20Jpa?= =?UTF-8?q?AuditingConfig=20=EB=A1=A4=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/common/config/JpaAuditingConfig.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java b/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java index 1a1d1ad7..c148863c 100644 --- a/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java +++ b/src/main/java/com/beat/global/common/config/JpaAuditingConfig.java @@ -1,23 +1,9 @@ package com.beat.global.common.config; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import com.querydsl.jpa.impl.JPAQueryFactory; - -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; - @Configuration @EnableJpaAuditing public class JpaAuditingConfig { - - @PersistenceContext - private EntityManager em; - - @Bean - public JPAQueryFactory jpaQueryFactory() { - return new JPAQueryFactory(em); - } }