-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat/CK-236] JdbcTemplate을 이용하여 bulk insert를 적용한다 (#198)
* refactor: 기존 saveAll, deleteAll을 bulk insert로 개선 * refactor: Dao 대신 Repository 계층에 의존하도록 수정 - JdbcRepository 추상화
- Loading branch information
Showing
13 changed files
with
105 additions
and
49 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...kirikiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberJdbcRepository.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,9 @@ | ||
package co.kirikiri.persistence.goalroom; | ||
|
||
import co.kirikiri.domain.goalroom.GoalRoomMember; | ||
import java.util.List; | ||
|
||
public interface GoalRoomMemberJdbcRepository { | ||
|
||
void saveAllInBatch(final List<GoalRoomMember> goalRoomMembers); | ||
} |
30 changes: 30 additions & 0 deletions
30
...kiri/src/main/java/co/kirikiri/persistence/goalroom/GoalRoomMemberJdbcRepositoryImpl.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,30 @@ | ||
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 GoalRoomMemberJdbcRepositoryImpl implements GoalRoomMemberJdbcRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
public GoalRoomMemberJdbcRepositoryImpl(final JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@Override | ||
public void saveAllInBatch(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
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
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
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
Oops, something went wrong.