You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2022/09/05 16:20:26 UTC

[shardingsphere] branch master updated: Refactor JDBCBackendTransactionManager and LocalTransactionManager (#20809)

This is an automated email from the ASF dual-hosted git repository.

menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d121934c35 Refactor JDBCBackendTransactionManager and LocalTransactionManager (#20809)
9d121934c35 is described below

commit 9d121934c35fde77662a8bc37bf6d4bf24da9423
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Sep 6 00:20:17 2022 +0800

    Refactor JDBCBackendTransactionManager and LocalTransactionManager (#20809)
---
 .../jdbc/transaction/JDBCBackendTransactionManager.java | 13 +++++++++++--
 .../jdbc/transaction/LocalTransactionManager.java       | 17 +++++++++++++----
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java
index f1da4ffbb75..56c57e3bd67 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/JDBCBackendTransactionManager.java
@@ -155,8 +155,17 @@ public final class JDBCBackendTransactionManager implements TransactionManager<V
         if (exceptions.isEmpty()) {
             return null;
         }
-        SQLException ex = new SQLException("");
-        exceptions.forEach(ex::setNextException);
+        SQLException ex = null;
+        int count = 0;
+        for (SQLException each : exceptions) {
+            if (0 == count) {
+                ex = each;
+            } else {
+                // TODO use recursion to setNextException with chain, not overlap 
+                ex.setNextException(each);
+            }
+            count++;
+        }
         throw ex;
     }
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java
index a646c5af4ba..ddc56784882 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java
@@ -111,12 +111,21 @@ public final class LocalTransactionManager implements TransactionManager<Void> {
         return null;
     }
     
-    private void throwSQLExceptionIfNecessary(final Collection<SQLException> exceptions) throws SQLException {
+    private Void throwSQLExceptionIfNecessary(final Collection<SQLException> exceptions) throws SQLException {
         if (exceptions.isEmpty()) {
-            return;
+            return null;
+        }
+        SQLException ex = null;
+        int count = 0;
+        for (SQLException each : exceptions) {
+            if (0 == count) {
+                ex = each;
+            } else {
+                // TODO use recursion to setNextException with chain, not overlap 
+                ex.setNextException(each);
+            }
+            count++;
         }
-        SQLException ex = new SQLException("");
-        exceptions.forEach(ex::setNextException);
         throw ex;
     }
 }