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()) {
|
||||
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 -> {
|
||||
try {
|
||||
int batchSize = pss.getBatchSize();
|
||||
InterruptibleBatchPreparedStatementSetter ipss =
|
||||
(pss instanceof InterruptibleBatchPreparedStatementSetter ibpss ? ibpss : null);
|
||||
if (JdbcUtils.supportsBatchUpdates(ps.getConnection())) {
|
||||
|
@ -1050,7 +1053,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
|||
}
|
||||
ps.addBatch();
|
||||
}
|
||||
return batchSize > 0 ? ps.executeBatch() : new int[] {};
|
||||
return ps.executeBatch();
|
||||
}
|
||||
else {
|
||||
List<Integer> rowsAffected = new ArrayList<>();
|
||||
|
|
Loading…
Reference in New Issue