批量插入

2018-06-21 06:55:07来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

/**
* 批量插入
* @param mergerDtos
* @param mergerId
*/
private void batchSaveMergerItem(List<MergerDto> mergerDtos, Long mergerId){
if (CollectionUtils.isNotEmpty(mergerDtos)) {
for (MergerDto mergerDto : mergerDtos) {
List<Long> ids = mergerDto.getIds();

int size = ids.size();
List<TrMergerMemberItemEo> batch = initList(size,BizConstant.DB_MAX_BATCH_NUM);
boolean flushFlag = false;
for (int i = 0; i < size; i++) {
if ( ((i+1) % BizConstant.DB_MAX_BATCH_NUM == 0 )
||( i == size -1)) {
flushFlag = true;
}
TrMergerMemberItemEo trMergerMemberItemEo = new TrMergerMemberItemEo();
trMergerMemberItemEo.setMergerId(mergerId);
trMergerMemberItemEo.setTableName(mergerDto.getTableName());
trMergerMemberItemEo.setBizId(ids.get(i));
batch.add(trMergerMemberItemEo);
if (flushFlag) {
trMergerMemberItemDas.insertBatch(batch);
if (i != size -1) {
flushFlag = false;
batch = initList(size,BizConstant.DB_MAX_BATCH_NUM);
}
}
}
}
}
}

private List initList(int size, int maxSize){
List list ;
if (size > maxSize) {
list = new ArrayList<>(maxSize);
} else {
list = new ArrayList<>(size);
}
return list;
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:控制台报错:java.lang.ClassNotFoundException: javax.xml.bind

下一篇:Apache Maven(四):依赖