-
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: 파일에서 DB 저장 bulk insert 최적화 및 불필요한 csv 파일 생성 차단
- Loading branch information
1 parent
ea45b52
commit 58fca5f
Showing
5 changed files
with
97 additions
and
14 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
src/main/java/com/spaceclub/global/annotation/profanity/domain/ProfanityRepository.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...om/spaceclub/global/annotation/profanity/domain/repository/ProfanityCustomRepository.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,11 @@ | ||
package com.spaceclub.global.annotation.profanity.domain.repository; | ||
|
||
import com.spaceclub.global.annotation.profanity.domain.Profanity; | ||
|
||
import java.util.List; | ||
|
||
public interface ProfanityCustomRepository { | ||
|
||
void bulkInsert(List<Profanity> profanities); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...paceclub/global/annotation/profanity/domain/repository/ProfanityCustomRepositoryImpl.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,43 @@ | ||
package com.spaceclub.global.annotation.profanity.domain.repository; | ||
|
||
import com.spaceclub.global.annotation.profanity.domain.Profanity; | ||
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 ProfanityCustomRepositoryImpl implements ProfanityCustomRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
@Override | ||
public void bulkInsert(List<Profanity> profanities) { | ||
String sql = "INSERT INTO profanity (ban_word, use_count, created_at, last_modified_at) " + | ||
"VALUES (?, ?, ?, ?)"; | ||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { | ||
|
||
@Override | ||
public void setValues(PreparedStatement ps, int i) throws SQLException { | ||
Profanity profanity = profanities.get(i); | ||
ps.setString(1, profanity.getBanWord()); | ||
ps.setLong(2, profanity.getUseCount()); | ||
ps.setObject(3, now); // created date | ||
ps.setObject(4, now); // last modified date | ||
} | ||
|
||
@Override | ||
public int getBatchSize() { | ||
return profanities.size(); | ||
} | ||
|
||
}); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...java/com/spaceclub/global/annotation/profanity/domain/repository/ProfanityRepository.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,20 @@ | ||
package com.spaceclub.global.annotation.profanity.domain.repository; | ||
|
||
import com.spaceclub.global.annotation.profanity.domain.Profanity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface ProfanityRepository extends JpaRepository<Profanity, Long>, ProfanityCustomRepository { | ||
|
||
@Query("SELECT MAX(p.lastModifiedAt) FROM Profanity p") | ||
LocalDateTime findLatestModifiedDate(); | ||
|
||
boolean existsByBanWord(String word); | ||
|
||
Profanity findByBanWord(String banWord); | ||
|
||
void deleteByBanWord(String word); | ||
|
||
} |
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