Skip to content

Commit

Permalink
Optimize loader options config of YAML, change maxAliasesForCollectio…
Browse files Browse the repository at this point in the history
…ns from by default 50 to 1000 (#34001)
  • Loading branch information
jiangML authored Dec 11, 2024
1 parent 52f021a commit 4b47c41
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public YamlReadwriteSplittingRuleConfiguration swapToYamlConfiguration(final Rea
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -70,7 +71,8 @@ public static <T extends YamlConfiguration> T unmarshal(final File yamlFile, fin
@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;
}
}
Expand All @@ -85,7 +87,8 @@ public static <T extends YamlConfiguration> T unmarshal(final byte[] yamlBytes,
*/
@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;
}

Expand All @@ -102,7 +105,8 @@ public static <T> T unmarshal(final String yamlContent, final Class<T> classType
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public ShardingSphereYamlConstructor(final Class<?> rootClass) {
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);
Expand Down

0 comments on commit 4b47c41

Please sign in to comment.