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

jianglongtao 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 4b47c41d0d4 Optimize loader options config of YAML, change 
maxAliasesForCollections from by default 50 to 1000 (#34001)
4b47c41d0d4 is described below

commit 4b47c41d0d438a5e9a1ccb2de3bb9e954aeff41b
Author: jiangML <[email protected]>
AuthorDate: Wed Dec 11 15:28:04 2024 +0800

    Optimize loader options config of YAML, change maxAliasesForCollections 
from by default 50 to 1000 (#34001)
---
 .../YamlReadwriteSplittingRuleConfigurationSwapper.java      |  4 +++-
 .../apache/shardingsphere/infra/util/yaml/YamlEngine.java    | 12 ++++++++----
 .../util/yaml/constructor/ShardingSphereYamlConstructor.java |  7 ++++++-
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java
index 3a516399af0..78b83366f81 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingRuleConfigurationSwapper.java
@@ -56,7 +56,9 @@ public final class 
YamlReadwriteSplittingRuleConfigurationSwapper implements Yam
     private YamlReadwriteSplittingDataSourceGroupRuleConfiguration 
swapToYamlConfiguration(final 
ReadwriteSplittingDataSourceGroupRuleConfiguration dataSourceGroupRuleConfig) {
         YamlReadwriteSplittingDataSourceGroupRuleConfiguration result = new 
YamlReadwriteSplittingDataSourceGroupRuleConfiguration();
         
result.setWriteDataSourceName(dataSourceGroupRuleConfig.getWriteDataSourceName());
-        
result.setReadDataSourceNames(dataSourceGroupRuleConfig.getReadDataSourceNames());
+        if (null != dataSourceGroupRuleConfig.getReadDataSourceNames() && 
!dataSourceGroupRuleConfig.getReadDataSourceNames().isEmpty()) {
+            
result.setReadDataSourceNames(dataSourceGroupRuleConfig.getReadDataSourceNames());
+        }
         
result.setTransactionalReadQueryStrategy(dataSourceGroupRuleConfig.getTransactionalReadQueryStrategy().name());
         
result.setLoadBalancerName(dataSourceGroupRuleConfig.getLoadBalancerName());
         return result;
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/YamlEngine.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/YamlEngine.java
index 6e9dc650b30..658ccacf4aa 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/YamlEngine.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/YamlEngine.java
@@ -53,7 +53,8 @@ public final class YamlEngine {
     @SneakyThrows(ReflectiveOperationException.class)
     public static <T extends YamlConfiguration> T unmarshal(final File 
yamlFile, final Class<T> classType) throws IOException {
         try (BufferedReader inputStreamReader = 
Files.newBufferedReader(Paths.get(yamlFile.toURI()))) {
-            T result = new Yaml(new 
ShardingSphereYamlConstructor(classType)).loadAs(inputStreamReader, classType);
+            T result = new Yaml(new ShardingSphereYamlConstructor(classType), 
new Representer(new DumperOptions()), new DumperOptions(),
+                    
ShardingSphereYamlConstructor.createLoaderOptions()).loadAs(inputStreamReader, 
classType);
             return null == result ? classType.getConstructor().newInstance() : 
result;
         }
     }
@@ -70,7 +71,8 @@ public final class YamlEngine {
     @SneakyThrows(ReflectiveOperationException.class)
     public static <T extends YamlConfiguration> T unmarshal(final byte[] 
yamlBytes, final Class<T> classType) throws IOException {
         try (InputStream inputStream = new ByteArrayInputStream(yamlBytes)) {
-            T result = new Yaml(new 
ShardingSphereYamlConstructor(classType)).loadAs(inputStream, classType);
+            T result = new Yaml(new ShardingSphereYamlConstructor(classType), 
new Representer(new DumperOptions()), new DumperOptions(),
+                    
ShardingSphereYamlConstructor.createLoaderOptions()).loadAs(inputStream, 
classType);
             return null == result ? classType.getConstructor().newInstance() : 
result;
         }
     }
@@ -85,7 +87,8 @@ public final class YamlEngine {
      */
     @SneakyThrows(ReflectiveOperationException.class)
     public static <T> T unmarshal(final String yamlContent, final Class<T> 
classType) {
-        T result = new Yaml(new 
ShardingSphereYamlConstructor(classType)).loadAs(yamlContent, classType);
+        T result = new Yaml(new ShardingSphereYamlConstructor(classType), new 
Representer(new DumperOptions()), new DumperOptions(),
+                
ShardingSphereYamlConstructor.createLoaderOptions()).loadAs(yamlContent, 
classType);
         return null == result ? classType.getConstructor().newInstance() : 
result;
     }
     
@@ -102,7 +105,8 @@ public final class YamlEngine {
     public static <T> T unmarshal(final String yamlContent, final Class<T> 
classType, final boolean skipMissingProps) {
         Representer representer = new Representer(new DumperOptions());
         
representer.getPropertyUtils().setSkipMissingProperties(skipMissingProps);
-        T result = new Yaml(new ShardingSphereYamlConstructor(classType), 
representer).loadAs(yamlContent, classType);
+        T result = new Yaml(new ShardingSphereYamlConstructor(classType), 
representer, new DumperOptions(),
+                
ShardingSphereYamlConstructor.createLoaderOptions()).loadAs(yamlContent, 
classType);
         return null == result ? classType.getConstructor().newInstance() : 
result;
     }
     
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructor.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructor.java
index 09cfae8ec1d..fe992b692a6 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructor.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/constructor/ShardingSphereYamlConstructor.java
@@ -47,7 +47,12 @@ public class ShardingSphereYamlConstructor extends 
Constructor {
         this.rootClass = rootClass;
     }
     
-    private static LoaderOptions createLoaderOptions() {
+    /**
+     * Create loader options.
+     *
+     * @return loader options
+     */
+    public static LoaderOptions createLoaderOptions() {
         LoaderOptions result = new LoaderOptions();
         result.setMaxAliasesForCollections(1000);
         result.setCodePointLimit(Integer.MAX_VALUE);

Reply via email to