You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/09/30 12:15:40 UTC

[shardingsphere] branch master updated: Fixes #10507, add test case. (#12832)

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 2b308cf  Fixes #10507, add test case. (#12832)
2b308cf is described below

commit 2b308cf31dc75f4034608b5c323318995fb977ba
Author: yx9o <ya...@163.com>
AuthorDate: Thu Sep 30 20:15:06 2021 +0800

    Fixes #10507, add test case. (#12832)
---
 .../jdbc/core/connection/ShardingSphereConnection.java    |  4 +++-
 .../core/connection/ShardingSphereConnectionTest.java     | 15 ++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index 00c1ed4..f46df67 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -235,7 +235,9 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter im
             this.autoCommit = autoCommit;
             recordMethodInvocation(Connection.class, "setAutoCommit", new Class[]{boolean.class}, new Object[]{autoCommit});
             getForceExecuteTemplate().execute(getCachedConnections().values(), connection -> connection.setAutoCommit(autoCommit));
-            TransactionHolder.setInTransaction();
+            if (!autoCommit) {
+                TransactionHolder.setInTransaction();
+            }
             return;
         }
         if (autoCommit != transactionManager.isInTransaction()) {
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
index 0dafb74..e29db7c 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
@@ -19,14 +19,15 @@ package org.apache.shardingsphere.driver.jdbc.core.connection;
 
 import org.apache.shardingsphere.driver.jdbc.core.fixture.BASEShardingSphereTransactionManagerFixture;
 import org.apache.shardingsphere.driver.jdbc.core.fixture.XAShardingSphereTransactionManagerFixture;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.infra.database.DefaultSchema;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
 import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.TransactionHolder;
 import org.apache.shardingsphere.transaction.context.TransactionContexts;
 import org.apache.shardingsphere.transaction.core.TransactionOperationType;
 import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -53,7 +54,7 @@ import static org.mockito.Mockito.when;
 
 public final class ShardingSphereConnectionTest {
     
-    private static Map<String, DataSource> dataSourceMap = new HashMap<>();
+    private static Map<String, DataSource> dataSourceMap;
     
     private ShardingSphereConnection connection;
     
@@ -115,6 +116,14 @@ public final class ShardingSphereConnectionTest {
     }
     
     @Test
+    public void assertLOCALTransactionOperation() throws SQLException {
+        connection.setAutoCommit(true);
+        assertFalse(TransactionHolder.isTransaction());
+        connection.setAutoCommit(false);
+        assertTrue(TransactionHolder.isTransaction());
+    }
+    
+    @Test
     public void assertXATransactionOperation() throws SQLException {
         ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);