From 8fc316337d09929f51bebb415b6ed9c2d230efdc Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 27 May 2026 05:01:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E8=8E=B7=E5=8F=96=20updat?= =?UTF-8?q?eCounts=20=E7=9A=84=E9=80=BB=E8=BE=91=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E5=88=B0=E7=8B=AC=E7=AB=8B=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将异常处理中获取 updateCounts 的逻辑提取为独立的私有方法 getUpdateCountsInternal,提高代码可读性和可维护性。 --- .../xyz/zhouxy/jdbc/JdbcOperationSupport.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/xyz/zhouxy/jdbc/JdbcOperationSupport.java b/src/main/java/xyz/zhouxy/jdbc/JdbcOperationSupport.java index d77a7dc..f60ebc4 100644 --- a/src/main/java/xyz/zhouxy/jdbc/JdbcOperationSupport.java +++ b/src/main/java/xyz/zhouxy/jdbc/JdbcOperationSupport.java @@ -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