diff --git a/build.gradle b/build.gradle index 05f9835..84b85eb 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,11 @@ dependencies { // DB implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'com.mysql:mysql-connector-j' + // Query DSL + 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" // Redis implementation 'org.springframework.boot:spring-boot-starter-data-redis' // Security @@ -49,3 +54,5 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +def querydslDir = "src/main/generated" \ No newline at end of file diff --git a/src/main/java/side/onetime/domain/Event.java b/src/main/java/side/onetime/domain/Event.java index 0881b8e..b14ed97 100644 --- a/src/main/java/side/onetime/domain/Event.java +++ b/src/main/java/side/onetime/domain/Event.java @@ -39,15 +39,12 @@ public class Event extends BaseEntity { private Category category; @OneToMany(mappedBy = "event",cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @BatchSize(size = 100) private List members; @OneToMany(mappedBy = "event",cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @BatchSize(size = 100) private List schedules; @OneToMany(mappedBy = "event",cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @BatchSize(size = 100) private List eventParticipations; @Builder diff --git a/src/main/java/side/onetime/domain/Member.java b/src/main/java/side/onetime/domain/Member.java index 0baabb3..667ac21 100644 --- a/src/main/java/side/onetime/domain/Member.java +++ b/src/main/java/side/onetime/domain/Member.java @@ -35,7 +35,6 @@ public class Member extends BaseEntity { private String pin; @OneToMany(mappedBy = "member", cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @BatchSize(size = 100) private List selections; @Builder diff --git a/src/main/java/side/onetime/domain/Schedule.java b/src/main/java/side/onetime/domain/Schedule.java index 7c2abb8..98f0e1a 100644 --- a/src/main/java/side/onetime/domain/Schedule.java +++ b/src/main/java/side/onetime/domain/Schedule.java @@ -35,7 +35,6 @@ public class Schedule extends BaseEntity { private String time; @OneToMany(mappedBy = "schedule",cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @BatchSize(size = 100) private List selections; @Builder diff --git a/src/main/java/side/onetime/domain/User.java b/src/main/java/side/onetime/domain/User.java index 592ad89..334ccf2 100644 --- a/src/main/java/side/onetime/domain/User.java +++ b/src/main/java/side/onetime/domain/User.java @@ -36,11 +36,9 @@ public class User extends BaseEntity { private String providerId; @OneToMany(mappedBy = "user",cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @BatchSize(size = 100) private List selections; @OneToMany(mappedBy = "user",cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @BatchSize(size = 100) private List eventParticipations; @Builder diff --git a/src/main/java/side/onetime/global/config/QueryDslConfig.java b/src/main/java/side/onetime/global/config/QueryDslConfig.java new file mode 100644 index 0000000..dd8e648 --- /dev/null +++ b/src/main/java/side/onetime/global/config/QueryDslConfig.java @@ -0,0 +1,18 @@ +package side.onetime.global.config; + +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 entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} \ No newline at end of file diff --git a/src/main/java/side/onetime/repository/EventRepository.java b/src/main/java/side/onetime/repository/EventRepository.java index 42e5097..f85dafa 100644 --- a/src/main/java/side/onetime/repository/EventRepository.java +++ b/src/main/java/side/onetime/repository/EventRepository.java @@ -2,11 +2,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import side.onetime.domain.Event; +import side.onetime.repository.custom.EventRepositoryCustom; import java.util.Optional; import java.util.UUID; -public interface EventRepository extends JpaRepository { +public interface EventRepository extends JpaRepository, EventRepositoryCustom { Optional findByEventId(UUID eventId); boolean existsByEventId(UUID eventId); } \ No newline at end of file diff --git a/src/main/java/side/onetime/repository/custom/EventRepositoryCustom.java b/src/main/java/side/onetime/repository/custom/EventRepositoryCustom.java new file mode 100644 index 0000000..fac70a2 --- /dev/null +++ b/src/main/java/side/onetime/repository/custom/EventRepositoryCustom.java @@ -0,0 +1,7 @@ +package side.onetime.repository.custom; + +import side.onetime.domain.Event; + +public interface EventRepositoryCustom { + void deleteUserEvent(Event event); +} \ No newline at end of file diff --git a/src/main/java/side/onetime/repository/custom/EventRepositoryImpl.java b/src/main/java/side/onetime/repository/custom/EventRepositoryImpl.java new file mode 100644 index 0000000..e5b0803 --- /dev/null +++ b/src/main/java/side/onetime/repository/custom/EventRepositoryImpl.java @@ -0,0 +1,40 @@ +package side.onetime.repository.custom; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import side.onetime.domain.Event; + +import static side.onetime.domain.QEvent.event; +import static side.onetime.domain.QEventParticipation.eventParticipation; +import static side.onetime.domain.QMember.member; +import static side.onetime.domain.QSchedule.schedule; +import static side.onetime.domain.QSelection.selection; + +@RequiredArgsConstructor +public class EventRepositoryImpl implements EventRepositoryCustom { + + private final JPAQueryFactory queryFactory; + + @Override + public void deleteUserEvent(Event e) { + queryFactory.delete(selection) + .where(selection.schedule.event.eq(e)) + .execute(); + + queryFactory.delete(eventParticipation) + .where(eventParticipation.event.eq(e)) + .execute(); + + queryFactory.delete(schedule) + .where(schedule.event.eq(e)) + .execute(); + + queryFactory.delete(member) + .where(member.event.eq(e)) + .execute(); + + queryFactory.delete(event) + .where(event.eq(e)) + .execute(); + } +} \ No newline at end of file diff --git a/src/main/java/side/onetime/service/EventService.java b/src/main/java/side/onetime/service/EventService.java index 66baf90..2ebb2ba 100644 --- a/src/main/java/side/onetime/service/EventService.java +++ b/src/main/java/side/onetime/service/EventService.java @@ -294,6 +294,6 @@ public void removeUserCreatedEvent(String authorizationHeader, String eventId) { throw new EventParticipationException(EventParticipationErrorResult._IS_NOT_USERS_CREATED_EVENT_PARTICIPATION); } - eventRepository.delete(event); + eventRepository.deleteUserEvent(event); } } \ No newline at end of file