This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 2d140e208c6 Optimize sneakyaml export DatabaseConfiguration (#18612)
2d140e208c6 is described below
commit 2d140e208c6edcb4757037bd6695c6b3f122a96b
Author: 小马哥 <[email protected]>
AuthorDate: Sun Jun 26 21:36:41 2022 +0800
Optimize sneakyaml export DatabaseConfiguration (#18612)
---
.../shardingsphere/infra/yaml/engine/YamlEngine.java | 18 +-----------------
.../queryable/ExportDatabaseConfigurationHandler.java | 8 +-------
2 files changed, 2 insertions(+), 24 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java
index 44b346d58ed..b592c1cb7f8 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/engine/YamlEngine.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.infra.yaml.engine.constructor.ShardingSphereYam
import
org.apache.shardingsphere.infra.yaml.engine.representer.ShardingSphereYamlRepresenter;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
import java.io.ByteArrayInputStream;
@@ -107,25 +106,10 @@ public final class YamlEngine {
* @return YAML content
*/
public static String marshal(final Object value) {
- return marshal(value, null);
- }
-
- /**
- * Marshal YAML.
- *
- * @param value object to be marshaled
- * @param classTag class tag
- * @return YAML content
- */
- public static String marshal(final Object value, final Tag classTag) {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setLineBreak(DumperOptions.LineBreak.getPlatformLineBreak());
- ShardingSphereYamlRepresenter shardingSphereYamlRepresenter = new
ShardingSphereYamlRepresenter();
- if (classTag != null) {
- shardingSphereYamlRepresenter.addClassTag(value.getClass(),
classTag);
- }
if (value instanceof Collection) {
- return new Yaml(shardingSphereYamlRepresenter,
dumperOptions).dumpAs(value, null, DumperOptions.FlowStyle.BLOCK);
+ return new Yaml(new ShardingSphereYamlRepresenter(),
dumperOptions).dumpAs(value, null, DumperOptions.FlowStyle.BLOCK);
}
return new Yaml(new ShardingSphereYamlRepresenter(),
dumperOptions).dumpAsMap(value);
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java
index 41a7430fdba..577f009cd2a 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/queryable/ExportDatabaseConfigurationHandler.java
@@ -33,7 +33,6 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import
org.apache.shardingsphere.proxy.backend.text.distsql.ral.QueryableRALBackendHandler;
-import org.yaml.snakeyaml.nodes.Tag;
import javax.sql.DataSource;
import java.io.File;
@@ -112,15 +111,10 @@ public final class ExportDatabaseConfigurationHandler
extends QueryableRALBacken
}
stringBuilder.append("rules").append(":\n");
for (Entry<RuleConfiguration, YamlRuleConfigurationSwapper> entry :
YamlRuleConfigurationSwapperFactory.getInstanceMapByRuleConfigurations(ruleConfigs).entrySet())
{
- String content =
YamlEngine.marshal(Collections.singleton(entry.getValue().swapToYamlConfiguration(entry.getKey())),
Tag.MAP);
- stringBuilder.append(replaceKeywordsOfRulesConfiguration(content));
+
stringBuilder.append(YamlEngine.marshal(Collections.singletonList(entry.getValue().swapToYamlConfiguration(entry.getKey()))));
}
}
- private String replaceKeywordsOfRulesConfiguration(final String
ruleConfigsContent) {
- return ruleConfigsContent.replace("? ", "- ").replace(": null\n", "");
- }
-
@SuppressWarnings("ResultOfMethodCallIgnored")
private void exportToFile(final String filePath, final String
exportedData) {
File file = new File(filePath);