-
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.
게시글 등록/ 수정시 이미지를 batch insert 하도록 수정함 (#528)
* feat: 이미지 저장시 batch insert 하도록 수정 * feat: 게시글 수정시에도 이미지 정보를 batch update를 사용하도록 수정함
- Loading branch information
Showing
4 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...ain/java/edonymyeon/backend/image/postimage/repository/PostImageInfoCustomRepository.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,10 @@ | ||
package edonymyeon.backend.image.postimage.repository; | ||
|
||
import edonymyeon.backend.image.postimage.domain.PostImageInfo; | ||
|
||
import java.util.List; | ||
|
||
public interface PostImageInfoCustomRepository { | ||
|
||
void batchSave(final List<PostImageInfo> imageInfos, final Long postId); | ||
} |
36 changes: 36 additions & 0 deletions
36
...java/edonymyeon/backend/image/postimage/repository/PostImageInfoCustomRepositoryImpl.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,36 @@ | ||
package edonymyeon.backend.image.postimage.repository; | ||
|
||
import edonymyeon.backend.image.postimage.domain.PostImageInfo; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.jdbc.core.BatchPreparedStatementSetter; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
public class PostImageInfoCustomRepositoryImpl implements PostImageInfoCustomRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
@Override | ||
public void batchSave(final List<PostImageInfo> imageInfos, final Long postId) { | ||
final LocalDateTime now = LocalDateTime.now(); | ||
jdbcTemplate.batchUpdate("INSERT INTO post_image_info (created_at, post_id, store_name) values (?, ?, ?)", | ||
new BatchPreparedStatementSetter() { | ||
@Override | ||
public void setValues(final PreparedStatement ps, final int i) throws SQLException { | ||
ps.setObject(1, now); | ||
ps.setLong(2, postId); | ||
ps.setString(3, imageInfos.get(i).getStoreName()); | ||
} | ||
|
||
@Override | ||
public int getBatchSize() { | ||
return imageInfos.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