Skip to content

Commit

Permalink
[improve] support rewriteBatchedStatements=true (#6269)
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAchao committed Jun 21, 2024
1 parent 1cfc059 commit ae237fb
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.ibatis.logging.LogFactory;

import java.io.Serializable;
import java.sql.Statement;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static <T> boolean saveBatch(Collection<T> entityList, int batchSize) {
}
Class<T> entityClass = getEntityClass(entityList);
List<BatchResult> batchResults = SqlHelper.execute(entityClass, baseMapper -> baseMapper.insert(entityList, batchSize));
return batchResults.stream().flatMapToInt(r -> IntStream.of(r.getUpdateCounts())).allMatch(i -> i > 0);
return batchResults.stream().flatMapToInt(r -> IntStream.of(r.getUpdateCounts())).allMatch(i -> i > 0 || i == Statement.SUCCESS_NO_INFO);
}

/**
Expand All @@ -112,7 +113,7 @@ public static <T> boolean saveOrUpdateBatch(Collection<T> entityList, int batchS
}
Class<T> entityClass = getEntityClass(entityList);
List<BatchResult> batchResults = SqlHelper.execute(entityClass, baseMapper -> baseMapper.insertOrUpdate(entityList, batchSize));
return batchResults.stream().flatMapToInt(r -> IntStream.of(r.getUpdateCounts())).allMatch(i -> i > 0);
return batchResults.stream().flatMapToInt(r -> IntStream.of(r.getUpdateCounts())).allMatch(i -> i > 0 || i == Statement.SUCCESS_NO_INFO);
}

/**
Expand Down Expand Up @@ -195,7 +196,7 @@ public static <T> boolean updateBatchById(Collection<T> entityList) {
public static <T> boolean updateBatchById(Collection<T> entityList, int batchSize) {
Class<T> entityClass = getEntityClass(entityList);
List<BatchResult> batchResults = SqlHelper.execute(entityClass, baseMapper -> baseMapper.updateById(entityList, batchSize));
return batchResults.stream().flatMapToInt(r -> IntStream.of(r.getUpdateCounts())).allMatch(i -> i > 0);
return batchResults.stream().flatMapToInt(r -> IntStream.of(r.getUpdateCounts())).allMatch(i -> i > 0 || i == Statement.SUCCESS_NO_INFO);
}

/**
Expand Down

0 comments on commit ae237fb

Please sign in to comment.