forked from plusone/simple-jdbc
refactor: 将获取 updateCounts 的逻辑提取到独立方法
将异常处理中获取 updateCounts 的逻辑提取为独立的私有方法 getUpdateCountsInternal,提高代码可读性和可维护性。
This commit is contained in:
@@ -243,15 +243,7 @@ class JdbcOperationSupport {
|
||||
result.recordSuccessBatch(batchIndex, updateCounts);
|
||||
}
|
||||
catch (Exception e) {
|
||||
final int[] updateCounts;
|
||||
if (e instanceof BatchUpdateException) {
|
||||
updateCounts = ((BatchUpdateException) e).getUpdateCounts();
|
||||
}
|
||||
else {
|
||||
int n = (itemIndex >= paramsSize && indexInBatch != 0) ? indexInBatch : batchSize;
|
||||
updateCounts = new int[n];
|
||||
Arrays.fill(updateCounts, UNKNOWN_COUNT);
|
||||
}
|
||||
final int[] updateCounts = getUpdateCountsInternal(paramsSize, batchSize, itemIndex, indexInBatch, e);
|
||||
result.recordErrorBatch(batchIndex, updateCounts, e);
|
||||
if (!quietly) {
|
||||
result.interrupt();
|
||||
@@ -268,6 +260,23 @@ class JdbcOperationSupport {
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] getUpdateCountsInternal(final int paramsSize,
|
||||
final int batchSize,
|
||||
final int itemIndex,
|
||||
final int indexInBatch,
|
||||
final Exception e) {
|
||||
final int[] updateCounts;
|
||||
if (e instanceof BatchUpdateException) {
|
||||
updateCounts = ((BatchUpdateException) e).getUpdateCounts();
|
||||
}
|
||||
else {
|
||||
int n = (itemIndex >= paramsSize && indexInBatch != 0) ? indexInBatch : batchSize;
|
||||
updateCounts = new int[n];
|
||||
Arrays.fill(updateCounts, UNKNOWN_COUNT);
|
||||
}
|
||||
return updateCounts;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region - internal
|
||||
|
||||
Reference in New Issue
Block a user