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

panjuan 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 5a04865f03c Refactor : use try with resource (#20252)
5a04865f03c is described below

commit 5a04865f03cfb49913b5f9e4c20bb15b29ee39b7
Author: 孙念君 Nianjun Sun <[email protected]>
AuthorDate: Thu Aug 18 14:51:50 2022 +0800

    Refactor : use try with resource (#20252)
---
 .../classictransfer/ClassicTransferTestCase.java    | 21 ++++++++-------------
 .../container/compose/DockerComposedContainer.java  |  4 ++--
 ... ProxyClusterContainerConfigurationFactory.java} |  2 +-
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/classictransfer/ClassicTransferTestCase.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/classictransfer/ClassicTransferTestCase.java
index 51f7998e8da..4850cf181b7 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/classictransfer/ClassicTransferTestCase.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/classictransfer/ClassicTransferTestCase.java
@@ -73,16 +73,14 @@ public final class ClassicTransferTestCase extends 
BaseTransactionTestCase {
     
     private int getBalanceSum() throws Exception {
         int result = 0;
-        Connection connection = getDataSource().getConnection();
-        connection.setAutoCommit(false);
-        Statement statement = connection.createStatement();
-        ResultSet resultSet = statement.executeQuery("select sum(balance) as a 
from account where transaction_id in (1, 2)");
-        if (resultSet.next()) {
-            result = resultSet.getInt(1);
+        try (Connection connection = getDataSource().getConnection(); 
Statement statement = connection.createStatement()) {
+            connection.setAutoCommit(false);
+            ResultSet resultSet = statement.executeQuery("select sum(balance) 
as a from account where transaction_id in (1, 2)");
+            if (resultSet.next()) {
+                result = resultSet.getInt(1);
+            } 
+            connection.commit();
         }
-        connection.commit();
-        statement.close();
-        connection.close();
         return result;
     }
     
@@ -93,11 +91,9 @@ public final class ClassicTransferTestCase extends 
BaseTransactionTestCase {
         private DataSource dataSource;
         
         public void run() {
-            Connection connection = null;
             Statement statement1 = null;
             Statement statement2 = null;
-            try {
-                connection = dataSource.getConnection();
+            try (Connection connection = dataSource.getConnection();){
                 connection.setAutoCommit(false);
                 statement1 = connection.createStatement();
                 statement1.execute("update account set balance=balance-1 where 
transaction_id=2;");
@@ -110,7 +106,6 @@ public final class ClassicTransferTestCase extends 
BaseTransactionTestCase {
                 try {
                     statement1.close();
                     statement2.close();
-                    connection.close();
                 } catch (SQLException ignored) {
                 }
             }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java
index 45ae77c1df0..a8a2386a606 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java
@@ -23,7 +23,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
 import 
org.apache.shardingsphere.integration.transaction.framework.container.config.StorageContainerConfigurationFactory;
-import 
org.apache.shardingsphere.integration.transaction.framework.container.config.proxy.TransactionProxyClusterContainerConfigurationFactory;
+import 
org.apache.shardingsphere.integration.transaction.framework.container.config.proxy.ProxyClusterContainerConfigurationFactory;
 import 
org.apache.shardingsphere.integration.transaction.framework.container.jdbc.ShardingSphereJDBCContainer;
 import 
org.apache.shardingsphere.integration.transaction.framework.param.TransactionParameterized;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.adapter.AdapterContainerFactory;
@@ -61,7 +61,7 @@ public final class DockerComposedContainer extends 
BaseComposedContainer {
         if 
(TransactionTestConstants.PROXY.equalsIgnoreCase(parameterized.getAdapter())) {
             jdbcContainer = null;
             proxyContainer = (ShardingSphereProxyClusterContainer) 
AdapterContainerFactory.newInstance("Cluster", "proxy", databaseType, 
storageContainer, "",
-                    
TransactionProxyClusterContainerConfigurationFactory.newInstance(databaseType));
+                    
ProxyClusterContainerConfigurationFactory.newInstance(databaseType));
             proxyContainer.dependsOn(governanceContainer, storageContainer);
             getContainers().registerContainer(proxyContainer);
         } else {
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/config/proxy/TransactionProxyClusterContainerConfigurationFactory.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/config/proxy/ProxyClusterContainerConfiguration
 [...]
similarity index 97%
rename from 
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/config/proxy/TransactionProxyClusterContainerConfigurationFactory.java
rename to 
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/config/proxy/ProxyClusterContainerConfigurationFactory.java
index 6a752ef8cef..92981381b9a 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/config/proxy/TransactionProxyClusterContainerConfigurationFactory.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/config/proxy/ProxyClusterContainerConfigurationFactory.java
@@ -30,7 +30,7 @@ import java.util.Map;
  * Transaction proxy cluster container configuration factory.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class TransactionProxyClusterContainerConfigurationFactory {
+public final class ProxyClusterContainerConfigurationFactory {
     
     /**
      * Create instance of adaptor container configuration.

Reply via email to