-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NoticeJdbcRepository): Batch insert를 위한 NoticeJdbcRepository 구현
- Loading branch information
1 parent
a46c2e6
commit ed75bad
Showing
6 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/com/kustacks/kuring/notice/domain/NoticeJdbcRepository.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,64 @@ | ||
package com.kustacks.kuring.notice.domain; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.jdbc.core.BatchPreparedStatementSetter; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class NoticeJdbcRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
@Transactional | ||
public void saveAllCategoryNotices(List<Notice> notices) { | ||
jdbcTemplate.batchUpdate("INSERT INTO notice (article_id, category_name, important, posted_dt, subject, updated_dt, url, dtype) values (?, ?, ?, ?, ?, ?, ?, 'Notice')", | ||
new BatchPreparedStatementSetter() { | ||
@Override | ||
public void setValues(PreparedStatement ps, int i) throws SQLException { | ||
Notice notice = notices.get(i); | ||
ps.setString(1, notice.getArticleId()); | ||
ps.setString(2, notice.getCategoryName().toUpperCase()); | ||
ps.setInt(3, notice.isImportant() ? 1 : 0); | ||
ps.setString(4, notice.getPostedDate()); | ||
ps.setString(5, notice.getSubject()); | ||
ps.setString(6, notice.getUpdatedDate()); | ||
ps.setString(7, notice.getUrl()); | ||
} | ||
|
||
@Override | ||
public int getBatchSize() { | ||
return notices.size(); | ||
} | ||
}); | ||
} | ||
|
||
@Transactional | ||
public void saveAllDepartmentNotices(List<DepartmentNotice> departmentNotices) { | ||
jdbcTemplate.batchUpdate("INSERT INTO notice (article_id, category_name, important, posted_dt, subject, updated_dt, url, dtype) values (?, ?, ?, ?, ?, ?, ?, 'DepartmentNotice')", | ||
new BatchPreparedStatementSetter() { | ||
@Override | ||
public void setValues(PreparedStatement ps, int i) throws SQLException { | ||
DepartmentNotice departmentNotice = departmentNotices.get(i); | ||
ps.setString(1, departmentNotice.getArticleId()); | ||
ps.setString(2, departmentNotice.getCategoryName().toUpperCase()); | ||
ps.setInt(3, departmentNotice.isImportant() ? 1 : 0); | ||
ps.setString(4, departmentNotice.getPostedDate()); | ||
ps.setString(5, departmentNotice.getSubject()); | ||
ps.setString(6, departmentNotice.getUpdatedDate()); | ||
ps.setString(7, departmentNotice.getUrl()); | ||
} | ||
|
||
@Override | ||
public int getBatchSize() { | ||
return departmentNotices.size(); | ||
} | ||
}); | ||
} | ||
} |
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