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 e53c6b3  Extraction method, optimized analysis of yml file (#11775)
e53c6b3 is described below

commit e53c6b3bd06ad966d315856a3864606c89fd2bf8
Author: zhaojinchao <[email protected]>
AuthorDate: Thu Aug 12 11:54:38 2021 +0800

    Extraction method, optimized analysis of yml file (#11775)
---
 .../api/yaml/YamlShardingSphereDataSourceFactory.java     | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
index 1b49bf4..775b3bf 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/api/yaml/YamlShardingSphereDataSourceFactory.java
@@ -82,8 +82,7 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final Map<String, DataSource> 
dataSourceMap, final File yamlFile) throws SQLException, IOException {
-        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlFile, 
YamlRootRuleConfigurations.class);
-        return 
ShardingSphereDataSourceFactory.createDataSource(configs.getSchemaName(), 
dataSourceMap, SWAPPER_ENGINE.swapToRuleConfigurations(configs.getRules()), 
configs.getProps());
+        return createDataSource(dataSourceMap, YamlEngine.unmarshal(yamlFile, 
YamlRootRuleConfigurations.class));
     }
     
     /**
@@ -99,7 +98,7 @@ public final class YamlShardingSphereDataSourceFactory {
         YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlFile, 
YamlRootRuleConfigurations.class);
         Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
         dataSourceMap.put(Strings.isNullOrEmpty(configs.getSchemaName()) ? 
DefaultSchema.LOGIC_NAME : configs.getSchemaName(), dataSource);
-        return createDataSource(dataSourceMap, yamlFile);
+        return createDataSource(dataSourceMap, configs);
     }
     
     /**
@@ -112,8 +111,7 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final Map<String, DataSource> 
dataSourceMap, final byte[] yamlBytes) throws SQLException, IOException {
-        YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlBytes, 
YamlRootRuleConfigurations.class);
-        return 
ShardingSphereDataSourceFactory.createDataSource(configs.getSchemaName(), 
dataSourceMap, SWAPPER_ENGINE.swapToRuleConfigurations(configs.getRules()), 
configs.getProps());
+        return createDataSource(dataSourceMap, YamlEngine.unmarshal(yamlBytes, 
YamlRootRuleConfigurations.class));
     }
     
     /**
@@ -126,10 +124,13 @@ public final class YamlShardingSphereDataSourceFactory {
      * @throws IOException IO exception
      */
     public static DataSource createDataSource(final DataSource dataSource, 
final byte[] yamlBytes) throws SQLException, IOException {
-        //TODO Analytical optimization yml
         YamlRootRuleConfigurations configs = YamlEngine.unmarshal(yamlBytes, 
YamlRootRuleConfigurations.class);
         Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
         dataSourceMap.put(Strings.isNullOrEmpty(configs.getSchemaName()) ? 
DefaultSchema.LOGIC_NAME : configs.getSchemaName(), dataSource);
-        return createDataSource(dataSourceMap, yamlBytes);
+        return createDataSource(dataSourceMap, configs);
+    }
+    
+    private static DataSource createDataSource(final Map<String, DataSource> 
dataSourceMap, final YamlRootRuleConfigurations configs) throws SQLException {
+        return 
ShardingSphereDataSourceFactory.createDataSource(configs.getSchemaName(), 
dataSourceMap, SWAPPER_ENGINE.swapToRuleConfigurations(configs.getRules()), 
configs.getProps());
     }
 }

Reply via email to