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 7d7a63f  Reuse DataSourcePoolDestroyer on 
DataSourceConfigurationValidator (#14328)
7d7a63f is described below

commit 7d7a63f0f2a7065aa54883a7c1d56e0814286346
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Dec 26 02:11:51 2021 +0800

    Reuse DataSourcePoolDestroyer on DataSourceConfigurationValidator (#14328)
    
    * Reuse DataSourcePoolDestroyer on DataSourceConfigurationValidator
    
    * Reuse DataSourcePoolDestroyer on DataSourceConfigurationValidator
---
 .../datasource/DataSourceConfigurationValidator.java   | 18 ++++++------------
 .../destroyer/impl/HikariDataSourcePoolDestroyer.java  |  4 ++--
 .../metadata/resource/ShardingSphereResource.java      |  2 +-
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfigurationValidator.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfigurationValidator.java
index dfc663e..b5d46e6 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfigurationValidator.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourceConfigurationValidator.java
@@ -17,9 +17,11 @@
 
 package org.apache.shardingsphere.infra.config.datasource;
 
+import 
org.apache.shardingsphere.infra.config.datasource.pool.destroyer.DataSourcePoolDestroyerFactory;
 import 
org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourcesException;
 
 import javax.sql.DataSource;
+import java.sql.SQLException;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.Map;
@@ -60,18 +62,10 @@ public final class DataSourceConfigurationValidator {
             throw new 
InvalidDataSourceConfigurationException(dataSourceConfigName, ex.getMessage());
         } finally {
             if (null != dataSource) {
-                close(dataSource);
-            }
-        }
-    }
-    
-    private void close(final DataSource dataSource) {
-        if (dataSource instanceof AutoCloseable) {
-            try {
-                ((AutoCloseable) dataSource).close();
-                // CHECKSTYLE:OFF
-            } catch (final Exception ex) {
-                // CHECKSTYLE:ON
+                try {
+                    
DataSourcePoolDestroyerFactory.getInstance(dataSource.getClass().getCanonicalName()).destroy(dataSource);
+                } catch (final SQLException ignored) {
+                }
             }
         }
     }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/HikariDataSourcePoolDestroyer.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/HikariDataSourcePoolDestroyer.java
index 1c14880..4701365 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/HikariDataSourcePoolDestroyer.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/impl/HikariDataSourcePoolDestroyer.java
@@ -35,12 +35,12 @@ public final class HikariDataSourcePoolDestroyer implements 
DataSourcePoolDestro
         ExecutorService executor = Executors.newSingleThreadExecutor();
         executor.execute(() -> {
             while (true) {
-                if 
(hikariDataSource.getHikariPoolMXBean().getActiveConnections() == 0) {
+                if (0 == 
hikariDataSource.getHikariPoolMXBean().getActiveConnections()) {
                     hikariDataSource.close();
                     break;
                 }
                 try {
-                    Thread.sleep(10);
+                    Thread.sleep(10L);
                 } catch (final InterruptedException ignore) {
                 }
             }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java
index 982893d..49229aa 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/resource/ShardingSphereResource.java
@@ -82,6 +82,6 @@ public final class ShardingSphereResource {
      * @throws SQLException SQL exception
      */
     public void close(final DataSource dataSource) throws SQLException {
-        
DataSourcePoolDestroyerFactory.getInstance(dataSource.getClass().getName()).destroy(dataSource);
+        
DataSourcePoolDestroyerFactory.getInstance(dataSource.getClass().getCanonicalName()).destroy(dataSource);
     }
 }

Reply via email to