Polish "Avoid calling executeBatch() with an empty batch"
See gh-27154
This commit is contained in:
parent
2d7bf83d8d
commit
f9cffcce05
|
@ -1036,10 +1036,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Executing SQL batch update [" + sql + "]");
|
logger.debug("Executing SQL batch update [" + sql + "]");
|
||||||
}
|
}
|
||||||
|
int batchSize = pss.getBatchSize();
|
||||||
|
if (batchSize == 0) {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
|
||||||
int[] result = execute(sql, (PreparedStatementCallback<int[]>) ps -> {
|
int[] result = execute(sql, (PreparedStatementCallback<int[]>) ps -> {
|
||||||
try {
|
try {
|
||||||
int batchSize = pss.getBatchSize();
|
|
||||||
InterruptibleBatchPreparedStatementSetter ipss =
|
InterruptibleBatchPreparedStatementSetter ipss =
|
||||||
(pss instanceof InterruptibleBatchPreparedStatementSetter ibpss ? ibpss : null);
|
(pss instanceof InterruptibleBatchPreparedStatementSetter ibpss ? ibpss : null);
|
||||||
if (JdbcUtils.supportsBatchUpdates(ps.getConnection())) {
|
if (JdbcUtils.supportsBatchUpdates(ps.getConnection())) {
|
||||||
|
@ -1050,7 +1053,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||||
}
|
}
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
}
|
}
|
||||||
return batchSize > 0 ? ps.executeBatch() : new int[] {};
|
return ps.executeBatch();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
List<Integer> rowsAffected = new ArrayList<>();
|
List<Integer> rowsAffected = new ArrayList<>();
|
||||||
|
|
Loading…
Reference in New Issue