-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fee4119
commit 653a38e
Showing
11 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ToString | ||
@Builder | ||
public class User { | ||
|
||
private Integer id; | ||
|
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/wangzaiplus/test/service/batch/BatchProcessMapper.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.wangzaiplus.test.service.batch; | ||
|
||
import java.util.List; | ||
|
||
public interface BatchProcessMapper<T> { | ||
|
||
void batchInsert(List<T> list); | ||
|
||
void batchUpdate(List<T> list); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/wangzaiplus/test/service/batch/mapperproxy/MapperProxy.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.wangzaiplus.test.service.batch.mapperproxy; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.wangzaiplus.test.service.batch.BatchProcessMapper; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
|
||
import java.util.List; | ||
|
||
import static com.wangzaiplus.test.common.Constant.MAX_SIZE_PER_TIME; | ||
|
||
public class MapperProxy<T> implements BatchProcessMapper<T> { | ||
|
||
private BatchProcessMapper batchProcessMapper; | ||
|
||
public MapperProxy(BatchProcessMapper batchProcessMapper) { | ||
this.batchProcessMapper = batchProcessMapper; | ||
} | ||
|
||
@Override | ||
public void batchInsert(List<T> list) { | ||
if (CollectionUtils.isEmpty(list)) { | ||
return; | ||
} | ||
|
||
List<List<T>> partition = Lists.partition(list, MAX_SIZE_PER_TIME); | ||
for (List<T> batchList : partition) { | ||
batchProcessMapper.batchInsert(batchList); | ||
} | ||
} | ||
|
||
@Override | ||
public void batchUpdate(List<T> list) { | ||
if (CollectionUtils.isEmpty(list)) { | ||
return; | ||
} | ||
|
||
List<List<T>> partition = Lists.partition(list, MAX_SIZE_PER_TIME); | ||
for (List<T> batchList : partition) { | ||
batchProcessMapper.batchUpdate(batchList); | ||
} | ||
} | ||
|
||
} |
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