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

zhangliang 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 83f22b4  Revert #14780 changes in Proxy backend (#14801)
83f22b4 is described below

commit 83f22b494f1a89429cc5ced57ec5944a7ac1484d
Author: 吴伟杰 <[email protected]>
AuthorDate: Sun Jan 16 00:37:10 2022 +0800

    Revert #14780 changes in Proxy backend (#14801)
---
 .../jdbc/connection/JDBCBackendConnection.java       | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
index a9bba20..206faa9 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
@@ -83,6 +83,11 @@ public final class JDBCBackendConnection implements 
BackendConnection<Void>, Exe
     
     @Override
     public List<Connection> getConnections(final String dataSourceName, final 
int connectionSize, final ConnectionMode connectionMode) throws SQLException {
+        return connectionSession.getTransactionStatus().isInTransaction()
+                ? getConnectionsWithTransaction(dataSourceName, 
connectionSize, connectionMode) : 
getConnectionsWithoutTransaction(dataSourceName, connectionSize, 
connectionMode);
+    }
+    
+    private List<Connection> getConnectionsWithTransaction(final String 
dataSourceName, final int connectionSize, final ConnectionMode connectionMode) 
throws SQLException {
         Collection<Connection> connections;
         synchronized (cachedConnections) {
             connections = cachedConnections.get(dataSourceName);
@@ -110,10 +115,17 @@ public final class JDBCBackendConnection implements 
BackendConnection<Void>, Exe
     private List<Connection> createNewConnections(final String dataSourceName, 
final int connectionSize, final ConnectionMode connectionMode) throws 
SQLException {
         Preconditions.checkNotNull(connectionSession.getSchemaName(), "Current 
schema is null.");
         List<Connection> result = 
ProxyContext.getInstance().getBackendDataSource().getConnections(connectionSession.getSchemaName(),
 dataSourceName, connectionSize, connectionMode);
-        if (connectionSession.getTransactionStatus().isInTransaction()) {
-            for (Connection each : result) {
-                replayMethodsInvocation(each);
-            }
+        for (Connection each : result) {
+            replayMethodsInvocation(each);
+        }
+        return result;
+    }
+    
+    private List<Connection> getConnectionsWithoutTransaction(final String 
dataSourceName, final int connectionSize, final ConnectionMode connectionMode) 
throws SQLException {
+        Preconditions.checkNotNull(connectionSession.getSchemaName(), "Current 
schema is null.");
+        List<Connection> result = 
ProxyContext.getInstance().getBackendDataSource().getConnections(connectionSession.getSchemaName(),
 dataSourceName, connectionSize, connectionMode);
+        synchronized (cachedConnections) {
+            cachedConnections.putAll(dataSourceName, result);
         }
         return result;
     }

Reply via email to