Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ out/
### VS Code ###
.vscode/

### resources
/src/main/generated/

### env file ###
*.env
*.env
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ dependencies {
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'

// Querydsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// OAuth & Security
implementation 'org.springframework.boot:spring-boot-starter-oauth2-authorization-server'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
Expand All @@ -58,6 +64,24 @@ dependencies {
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

// Querydsl 설정
def generated = 'src/main/generated'

// QClass 파일 생성 위치를 지정
tasks.withType(JavaCompile).configureEach {
options.getGeneratedSourceOutputDirectory().set(file(generated))
}

// java source set 에 querydsl QClass 위치 추가
sourceSets {
main.java.srcDirs += [ generated ]
}

// gradle clean 시에 QClass 디렉토리 삭제
clean {
delete file(generated)
}

tasks.named('test') {
useJUnitPlatform()
jvmArgs("-XX:+EnableDynamicAgentLoading")
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/somemore/global/configure/QueryDslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.somemore.global.configure;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QueryDslConfig {

@PersistenceContext
private EntityManager em;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(em);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.somemore.location.repository;

import com.somemore.location.domain.Location;
import org.springframework.data.jpa.repository.JpaRepository;

public interface LocationJpaRepository extends JpaRepository<Location, Long> {

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.somemore.location.repository;

import com.somemore.location.domain.Location;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;

public interface LocationRepository extends JpaRepository<Location, Long> {
public interface LocationRepository {

Location save(Location location);

Optional<Location> findById(Long id);

void deleteAllInBatch();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.somemore.location.repository;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.somemore.location.domain.Location;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class LocationRepositoryImpl implements LocationRepository {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 좋은 것 같아요!


private final LocationJpaRepository locationJpaRepository;
private final JPAQueryFactory queryFactory;

@Override
public Location save(Location location) {
return locationJpaRepository.save(location);
}

@Override
public Optional<Location> findById(Long id) {
return locationJpaRepository.findById(id);
}

@Override
public void deleteAllInBatch() {
locationJpaRepository.deleteAllInBatch();
}
}
Loading