-
Notifications
You must be signed in to change notification settings - Fork 2
feat: 기이수성적 데이터 추가 시, batch insert 적용 #69
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3612605
feat: JdbcTemplate을 활용하여 batchInsert 인터페이스 및 구현체 추가
whxogus215 6bc26fc
fix: INSERT 쿼리문 수정
whxogus215 d267cb4
refactor: extractData가 batchInsert를 사용하도록 변경
whxogus215 ea650c3
chore: 깃 서브모듈 변경사항 커밋 추가
whxogus215 b9a71c8
chore: 깃 서브모듈 변경사항 커밋 추가
whxogus215 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
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/gimmegonghakauth/dao/CustomCompletedCoursesDao.java
This file contains hidden or 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,11 @@ | ||
| package com.example.gimmegonghakauth.dao; | ||
|
|
||
| import com.example.gimmegonghakauth.domain.CompletedCoursesDomain; | ||
| import java.util.List; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| public interface CustomCompletedCoursesDao { | ||
|
|
||
| @Transactional | ||
| void saveAll(List<CompletedCoursesDomain> completedCourses); | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/gimmegonghakauth/dao/CustomCompletedCoursesDaoImpl.java
This file contains hidden or 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,38 @@ | ||
| package com.example.gimmegonghakauth.dao; | ||
|
|
||
| import com.example.gimmegonghakauth.domain.CompletedCoursesDomain; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.SQLException; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.jdbc.core.BatchPreparedStatementSetter; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class CustomCompletedCoursesDaoImpl implements CustomCompletedCoursesDao { | ||
|
|
||
| private final JdbcTemplate jdbcTemplate; | ||
|
|
||
| @Override | ||
| public void saveAll(List<CompletedCoursesDomain> completedCourses) { | ||
| String sql = "insert into completed_course (course_id, semester, user_id, year) values (?,?,?,?)"; | ||
|
|
||
| jdbcTemplate.batchUpdate( | ||
| sql, | ||
| new BatchPreparedStatementSetter() { | ||
| @Override | ||
| public void setValues(PreparedStatement ps, int i) throws SQLException { | ||
| CompletedCoursesDomain course = completedCourses.get(i); | ||
| ps.setLong(1, course.getCoursesDomain().getCourseId()); | ||
| ps.setString(2, course.getSemester()); | ||
| ps.setLong(3, course.getUserDomain().getId()); | ||
| ps.setInt(4, course.getYear()); | ||
| } | ||
|
|
||
| @Override | ||
| public int getBatchSize() { | ||
| return completedCourses.size(); | ||
| } | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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.
운영 환경에서만 batch insert 옵션을 추가해도 괜찮은가요??
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.
제가 질문의 의도를 잘 이해하지 못했습니다 😢
현재 dev와 prod에 해당 옵션을 추가한 상태인데 그 외에 다른 곳에는 적용하지 않아도되냐는 의미일까요?
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.
아 질문할때 prod에만 해당 옵션이 추가된 것으로 잘못 보았네요..! test에는 해당 로직이 사용되지 않으니 dev와 prod에만 추가하는게 맞네요 확인했습니다👍