Polish "Avoid calling executeBatch() with an empty batch"

See gh-27154
This commit is contained in:
Stephane Nicoll 2023-08-26 17:05:39 +02:00
parent 2d7bf83d8d
commit f9cffcce05
1 changed files with 5 additions and 2 deletions

View File

@ -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<>();