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

zhonghongsheng 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 da625d35ab9 Refactor DataSourcePoolProperties.poolClassName (#28047)
da625d35ab9 is described below

commit da625d35ab92d59735705d02b6886f537120ef98
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 12 11:46:40 2023 +0800

    Refactor DataSourcePoolProperties.poolClassName (#28047)
    
    * Refactor DataSourcePoolProperties.poolClassName
    
    * Refactor DataSourcePoolProperties.poolClassName
---
 .../pool/props/DataSourcePoolProperties.java        | 21 +++++----------------
 .../pool/props/DataSourcePoolPropertiesTest.java    | 10 +++++-----
 2 files changed, 10 insertions(+), 21 deletions(-)

diff --git 
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolProperties.java
 
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolProperties.java
index 09b59b5816c..65d372bcb78 100644
--- 
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolProperties.java
+++ 
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolProperties.java
@@ -39,8 +39,6 @@ import java.util.Optional;
 @Getter
 public final class DataSourcePoolProperties {
     
-    private static final String DEFAULT_DATA_SOURCE_CLASS = 
"com.zaxxer.hikari.HikariDataSource";
-    
     private final String poolClassName;
     
     private final ConnectionPropertySynonyms connectionPropertySynonyms;
@@ -50,13 +48,13 @@ public final class DataSourcePoolProperties {
     private final CustomDataSourcePoolProperties 
customDataSourcePoolProperties;
     
     public DataSourcePoolProperties(final String poolClassName, final 
Map<String, Object> props) {
-        this.poolClassName = poolClassName;
-        Optional<DataSourcePoolMetaData> poolMetaData = 
TypedSPILoader.findService(DataSourcePoolMetaData.class, poolClassName);
-        Map<String, String> propertySynonyms = poolMetaData.isPresent() ? 
poolMetaData.get().getPropertySynonyms() : Collections.emptyMap();
+        Optional<DataSourcePoolMetaData> metaData = 
TypedSPILoader.findService(DataSourcePoolMetaData.class, poolClassName);
+        this.poolClassName = metaData.map(optional -> 
optional.getType().toString()).orElse(poolClassName);
+        Map<String, String> propertySynonyms = 
metaData.map(DataSourcePoolMetaData::getPropertySynonyms).orElse(Collections.emptyMap());
         connectionPropertySynonyms = new ConnectionPropertySynonyms(props, 
propertySynonyms);
         poolPropertySynonyms = new PoolPropertySynonyms(props, 
propertySynonyms);
-        customDataSourcePoolProperties = new CustomDataSourcePoolProperties(
-                props, getStandardPropertyKeys(), poolMetaData.isPresent() ? 
poolMetaData.get().getTransientFieldNames() : Collections.emptyList(), 
propertySynonyms);
+        Collection<String> transientFieldNames = 
metaData.map(DataSourcePoolMetaData::getTransientFieldNames).orElse(Collections.emptyList());
+        customDataSourcePoolProperties = new 
CustomDataSourcePoolProperties(props, getStandardPropertyKeys(), 
transientFieldNames, propertySynonyms);
     }
     
     private Collection<String> getStandardPropertyKeys() {
@@ -65,15 +63,6 @@ public final class DataSourcePoolProperties {
         return result;
     }
     
-    /**
-     * Get data source pool class name.
-     *
-     * @return data source pool class name
-     */
-    public String getPoolClassName() {
-        return null == poolClassName ? DEFAULT_DATA_SOURCE_CLASS : 
poolClassName;
-    }
-    
     /**
      * Get all standard properties.
      * 
diff --git 
a/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesTest.java
 
b/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesTest.java
index 5aa5ba21f57..06f19c5f6b5 100644
--- 
a/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesTest.java
+++ 
b/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/DataSourcePoolPropertiesTest.java
@@ -135,15 +135,15 @@ class DataSourcePoolPropertiesTest {
     private Map<String, Object> createUserProperties(final String username) {
         Map<String, Object> result = new LinkedHashMap<>(2, 1F);
         result.put("username", username);
-        result.put("dataSourceProperties", getDataSourcePoolProperties());
+        result.put("dataSourceProperties", createDataSourcePoolProperties());
         return result;
     }
     
-    private Map<String, String> getDataSourcePoolProperties() {
+    private Map<String, String> createDataSourcePoolProperties() {
         Map<String, String> result = new LinkedHashMap<>(3, 1F);
-        result.put("maintainTimeStats", "false");
-        result.put("rewriteBatchedStatements", "true");
-        result.put("useLocalSessionState", "true");
+        result.put("maintainTimeStats", Boolean.FALSE.toString());
+        result.put("rewriteBatchedStatements", Boolean.TRUE.toString());
+        result.put("useLocalSessionState", Boolean.TRUE.toString());
         return result;
     }
 }

Reply via email to