refactor: 优化变量和私有嵌套类的命名

- 将循环计数器变量从 'i' 重命名为更具描述性的 'itemIndex',提高代码可读性
- 将 JdbcExecutor 重命名为 TransactionJdbcExecutor 以更好地反映其事务处理功能
This commit is contained in:
2026-05-27 03:55:36 +08:00
parent b37dbde2b3
commit ee68cb4d00
2 changed files with 10 additions and 10 deletions

View File

@@ -225,19 +225,19 @@ class JdbcOperationSupport {
}
final int paramsSize = params.size();
int batchCount = (paramsSize + batchSize - 1) / batchSize;
final int batchCount = (paramsSize + batchSize - 1) / batchSize;
final BatchUpdateResult result = new BatchUpdateResult(paramsSize, batchCount, batchSize);
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int i = 0;
int itemIndex = 0;
int batchIndex = 0;
for (Object[] ps : params) {
i++;
itemIndex++;
fillStatement(stmt, ps);
stmt.addBatch();
final int indexInBatch = i % batchSize;
if (indexInBatch == 0 || i >= paramsSize) {
final int indexInBatch = itemIndex % batchSize;
if (indexInBatch == 0 || itemIndex >= paramsSize) {
try {
int[] updateCounts = stmt.executeBatch();
result.recordSuccessBatch(batchIndex, updateCounts);
@@ -248,7 +248,7 @@ class JdbcOperationSupport {
updateCounts = ((BatchUpdateException) e).getUpdateCounts();
}
else {
int n = (i >= paramsSize && indexInBatch != 0) ? indexInBatch : batchSize;
int n = (itemIndex >= paramsSize && indexInBatch != 0) ? indexInBatch : batchSize;
updateCounts = new int[n];
Arrays.fill(updateCounts, UNKNOWN_COUNT);
}

View File

@@ -204,7 +204,7 @@ public class SimpleJdbcTemplate implements JdbcOperations {
final boolean autoCommit = conn.getAutoCommit();
try {
conn.setAutoCommit(false);
operations.accept(new JdbcExecutor(conn));
operations.accept(new TransactionJdbcExecutor(conn));
conn.commit();
}
catch (Exception e) {
@@ -240,7 +240,7 @@ public class SimpleJdbcTemplate implements JdbcOperations {
final boolean autoCommit = conn.getAutoCommit();
try {
conn.setAutoCommit(false);
if (operations.test(new JdbcExecutor(conn))) {
if (operations.test(new TransactionJdbcExecutor(conn))) {
conn.commit();
}
else {
@@ -264,11 +264,11 @@ public class SimpleJdbcTemplate implements JdbcOperations {
// #endregion
private static final class JdbcExecutor implements JdbcOperations {
private static final class TransactionJdbcExecutor implements JdbcOperations {
private final Connection conn;
private JdbcExecutor(Connection conn) {
private TransactionJdbcExecutor(Connection conn) {
this.conn = conn;
}