-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat/CK-236] JdbcTemplate을 이용하여 bulk insert를 적용한다 #198
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package co.kirikiri.persistence.goalroom; | ||
|
||
import co.kirikiri.domain.goalroom.GoalRoomMember; | ||
import java.util.List; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class GoalRoomMemberDao { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
public GoalRoomMemberDao(final JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
public void saveAll(final List<GoalRoomMember> goalRoomMembers) { | ||
final String sql = "INSERT INTO goal_room_member " | ||
+ "(goal_room_id, member_id, role, joined_at, accomplishment_rate)" | ||
+ "VALUES (?, ?, ?, ?, ?)"; | ||
jdbcTemplate.batchUpdate(sql, goalRoomMembers, goalRoomMembers.size(), ((ps, goalRoomMember) -> { | ||
ps.setLong(1, goalRoomMember.getGoalRoom().getId()); | ||
ps.setLong(2, goalRoomMember.getMember().getId()); | ||
ps.setString(3, goalRoomMember.getRole().name()); | ||
ps.setObject(4, goalRoomMember.getJoinedAt()); | ||
ps.setDouble(5, goalRoomMember.getAccomplishmentRate()); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
import co.kirikiri.domain.goalroom.GoalRoom; | ||
import co.kirikiri.domain.goalroom.GoalRoomPendingMember; | ||
import co.kirikiri.domain.member.vo.Identifier; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface GoalRoomPendingMemberRepository extends JpaRepository<GoalRoomPendingMember, Long>, | ||
GoalRoomPendingMemberQueryRepository { | ||
|
@@ -28,4 +29,8 @@ Optional<GoalRoomPendingMember> findByGoalRoomAndMemberIdentifier( | |
+ "where g=:goalRoom " | ||
+ "and gp.member = m") | ||
List<GoalRoomPendingMember> findAllByGoalRoom(@Param("goalRoom") final GoalRoom goalRoom); | ||
|
||
@Modifying | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Modifying을 붙여야 하는 이유가 JPA에서 동작을 추론가능한 메서드명일 경우라서 그런건가요? |
||
@Query("DELETE FROM GoalRoomPendingMember gp WHERE gp.id IN :ids") | ||
void deleteAllByIdIn(@Param("ids") final List<Long> ids); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,8 @@ public List<GoalRoom> findByRoadmap(final Roadmap roadmap) { | |
@Override | ||
public List<GoalRoom> findAllRecruitingGoalRoomsByStartDateEarlierThan(final LocalDate date) { | ||
return selectFrom(goalRoom) | ||
.innerJoin(goalRoom.goalRoomPendingMembers.values, goalRoomPendingMember) | ||
.fetchJoin() | ||
Comment on lines
+119
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. join이 안되어있었네요..👍 |
||
.where(statusCond(GoalRoomStatus.RECRUITING)) | ||
.where(equalOrEarlierStartDateThan(date)) | ||
.fetch(); | ||
|
2 changes: 1 addition & 1 deletion
2
backend/kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미 Service가 Repository 계층에 의존하고 있으니 DAO 대신 Repository 계층을 만드는건 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이미 JpaRepository를 상속받는 GoalRoomMemberRepository가 존재해서 만들기가 애매했어요..!
그래서 기존
GoalRoomMemberRepository
가GoalRoomMemberJdbcRepository
라는 인터페이스를 상속받도록 했어요!GoalRoomMemberJdbcRepository
인터페이스는saveAllInBatch
라는 메서드를 구현하도록 했고,GoalRoomMemberJdbcRepositoryImpl
구현체를 만들어서 batch insert 작업해주었습니다.구조가 조금 복잡한 것 같은데 괜찮은지 확인부탁드립니다!