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

chengzhang 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 33b836aefc6 Remove ShardingSphereConnection.isHoldTransaction (#31718)
33b836aefc6 is described below

commit 33b836aefc6395190138ef5bc744b532470012c5
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jun 16 16:38:33 2024 +0800

    Remove ShardingSphereConnection.isHoldTransaction (#31718)
    
    * Support ShardingSphereConnection.createClob
    
    * Support ShardingSphereConnection.createClob
    
    * Remove ShardingSphereConnection.isHoldTransaction
---
 .../core/connection/ShardingSphereConnection.java  | 24 +++++++---------------
 .../connection/ShardingSphereConnectionTest.java   | 17 ---------------
 .../cases/nested/NestedTransactionTestCase.java    | 10 ++++-----
 3 files changed, 12 insertions(+), 39 deletions(-)

diff --git 
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
 
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index 0c0d29fe9c4..95aa0a4481f 100644
--- 
a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++ 
b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -91,15 +91,6 @@ public final class ShardingSphereConnection extends 
AbstractConnectionAdapter {
         processId = processEngine.connect(grantee, databaseName);
     }
     
-    /**
-     * Whether hold transaction or not.
-     *
-     * @return true or false
-     */
-    public boolean isHoldTransaction() {
-        return 
databaseConnectionManager.getConnectionTransaction().isHoldTransaction(autoCommit);
-    }
-    
     @Override
     public DatabaseMetaData getMetaData() throws SQLException {
         return new ShardingSphereDatabaseMetaData(this);
@@ -248,7 +239,7 @@ public final class ShardingSphereConnection extends 
AbstractConnectionAdapter {
         if (existedTrafficInstanceId.isPresent()) {
             return existedTrafficInstanceId;
         }
-        boolean isHoldTransaction = isHoldTransaction();
+        boolean isHoldTransaction = 
databaseConnectionManager.getConnectionTransaction().isHoldTransaction(autoCommit);
         Optional<String> result = new TrafficEngine(trafficRule, 
contextManager.getComputeNodeInstanceContext()).dispatch(queryContext, 
isHoldTransaction);
         if (isHoldTransaction && result.isPresent()) {
             
databaseConnectionManager.getConnectionContext().setTrafficInstanceId(result.get());
@@ -285,26 +276,25 @@ public final class ShardingSphereConnection extends 
AbstractConnectionAdapter {
     @Override
     public Savepoint setSavepoint(final String name) throws SQLException {
         checkClose();
-        if (!isHoldTransaction()) {
-            throw new SQLFeatureNotSupportedException("Savepoint can only be 
used in transaction blocks.");
-        }
+        
ShardingSpherePreconditions.checkState(databaseConnectionManager.getConnectionTransaction().isHoldTransaction(autoCommit),
+                () -> new SQLFeatureNotSupportedException("Savepoint can only 
be used in transaction blocks."));
         return databaseConnectionManager.setSavepoint(name);
     }
     
     @Override
     public Savepoint setSavepoint() throws SQLException {
         checkClose();
-        ShardingSpherePreconditions.checkState(isHoldTransaction(), () -> new 
SQLFeatureNotSupportedException("Savepoint can only be used in transaction 
blocks."));
+        
ShardingSpherePreconditions.checkState(databaseConnectionManager.getConnectionTransaction().isHoldTransaction(autoCommit),
+                () -> new SQLFeatureNotSupportedException("Savepoint can only 
be used in transaction blocks."));
         return databaseConnectionManager.setSavepoint();
     }
     
     @Override
     public void releaseSavepoint(final Savepoint savepoint) throws 
SQLException {
         checkClose();
-        if (!isHoldTransaction()) {
-            return;
+        if 
(databaseConnectionManager.getConnectionTransaction().isHoldTransaction(autoCommit))
 {
+            databaseConnectionManager.releaseSavepoint(savepoint);
         }
-        databaseConnectionManager.releaseSavepoint(savepoint);
     }
     
     private void checkClose() throws SQLException {
diff --git 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
index 69eabb34c99..0a25edb3b37 100644
--- 
a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
+++ 
b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
@@ -55,23 +55,6 @@ import static org.mockito.Mockito.when;
 
 class ShardingSphereConnectionTest {
     
-    @Test
-    void assertIsHoldTransaction() throws SQLException {
-        try (ShardingSphereConnection connection = new 
ShardingSphereConnection(DefaultDatabase.LOGIC_NAME, mockContextManager())) {
-            connection.setAutoCommit(false);
-            assertTrue(connection.isHoldTransaction());
-        }
-    }
-    
-    @Test
-    void assertIsNotHoldTransaction() throws SQLException {
-        try (ShardingSphereConnection connection = new 
ShardingSphereConnection(DefaultDatabase.LOGIC_NAME, mockContextManager())) {
-            connection.setAutoCommit(true);
-            assertFalse(connection.isHoldTransaction());
-        }
-        
-    }
-    
     @Test
     void assertSetAutoCommitWithLocalTransaction() throws SQLException {
         Connection physicalConnection = mock(Connection.class);
diff --git 
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java
 
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java
index 9bc44a01e4d..da3d0f16d70 100644
--- 
a/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java
+++ 
b/test/e2e/operation/transaction/src/test/java/org/apache/shardingsphere/test/e2e/transaction/cases/nested/NestedTransactionTestCase.java
@@ -42,20 +42,20 @@ public final class NestedTransactionTestCase extends 
BaseTransactionTestCase {
     @Override
     protected void executeTest(final TransactionContainerComposer 
containerComposer) throws SQLException {
         try (ShardingSphereConnection connection = (ShardingSphereConnection) 
getDataSource().getConnection()) {
-            assertFalse(connection.isHoldTransaction());
+            
assertFalse(connection.getDatabaseConnectionManager().getConnectionTransaction().isHoldTransaction(connection.getAutoCommit()));
             connection.setAutoCommit(false);
-            assertTrue(connection.isHoldTransaction());
+            
assertTrue(connection.getDatabaseConnectionManager().getConnectionTransaction().isHoldTransaction(connection.getAutoCommit()));
             requiresNewTransaction();
-            assertTrue(connection.isHoldTransaction());
+            
assertTrue(connection.getDatabaseConnectionManager().getConnectionTransaction().isHoldTransaction(connection.getAutoCommit()));
             connection.commit();
         }
     }
     
     private void requiresNewTransaction() throws SQLException {
         try (ShardingSphereConnection connection = (ShardingSphereConnection) 
getDataSource().getConnection()) {
-            assertFalse(connection.isHoldTransaction());
+            
assertFalse(connection.getDatabaseConnectionManager().getConnectionTransaction().isHoldTransaction(connection.getAutoCommit()));
             connection.setAutoCommit(false);
-            assertTrue(connection.isHoldTransaction());
+            
assertTrue(connection.getDatabaseConnectionManager().getConnectionTransaction().isHoldTransaction(connection.getAutoCommit()));
             connection.commit();
         }
     }

Reply via email to