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

duanzhengqiang 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 c1af007  Refactor DataSourcePoolDestroyerFactory (#14331)
c1af007 is described below

commit c1af007b447fc373a07115c00347c9efc9163e15
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Dec 26 12:25:50 2021 +0800

    Refactor DataSourcePoolDestroyerFactory (#14331)
---
 .../datasource/DataSourceConfigurationValidator.java     |  2 +-
 .../pool/destroyer/DataSourcePoolDestroyer.java          |  2 +-
 .../pool/destroyer/DataSourcePoolDestroyerFactory.java   | 16 +++++++++++-----
 .../infra/metadata/resource/ShardingSphereResource.java  |  2 +-
 4 files changed, 14 insertions(+), 8 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 b5d46e6..c453fcb 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
@@ -63,7 +63,7 @@ public final class DataSourceConfigurationValidator {
         } finally {
             if (null != dataSource) {
                 try {
-                    
DataSourcePoolDestroyerFactory.getInstance(dataSource.getClass().getCanonicalName()).destroy(dataSource);
+                    DataSourcePoolDestroyerFactory.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/DataSourcePoolDestroyer.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyer.java
index e910ae4..60a2f9a 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyer.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyer.java
@@ -30,7 +30,7 @@ public interface DataSourcePoolDestroyer extends TypedSPI, 
RequiredSPI {
     /**
      * destroy data source pool gracefully.
      * 
-     * @param dataSource data source
+     * @param dataSource data source pool to be destroyed
      * @throws SQLException SQL exception
      */
     void destroy(DataSource dataSource) throws SQLException;
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactory.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactory.java
index 78fa0ee..5c9c218 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactory.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/pool/destroyer/DataSourcePoolDestroyerFactory.java
@@ -21,6 +21,8 @@ import 
org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.spi.required.RequiredSPIRegistry;
 import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
 
+import javax.sql.DataSource;
+import java.sql.SQLException;
 import java.util.Properties;
 
 /**
@@ -33,12 +35,16 @@ public final class DataSourcePoolDestroyerFactory {
     }
     
     /**
-     * Get data source pool destroyer instance.
-     * 
-     * @param dataSourceClassName data source class name
-     * @return instance of data source pool destroyer
+     * Destroy data source pool.
+     *
+     * @param dataSource data source pool to be destroyed
+     * @throws SQLException SQL exception
      */
-    public static DataSourcePoolDestroyer getInstance(final String 
dataSourceClassName) {
+    public static void destroy(final DataSource dataSource) throws 
SQLException {
+        
newInstance(dataSource.getClass().getCanonicalName()).destroy(dataSource);
+    }
+    
+    private static DataSourcePoolDestroyer newInstance(final String 
dataSourceClassName) {
         return 
TypedSPIRegistry.findRegisteredService(DataSourcePoolDestroyer.class, 
dataSourceClassName, new Properties())
                 
.orElse(RequiredSPIRegistry.getRegisteredService(DataSourcePoolDestroyer.class));
     }
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 49229aa..b10582f 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().getCanonicalName()).destroy(dataSource);
+        DataSourcePoolDestroyerFactory.destroy(dataSource);
     }
 }

Reply via email to