This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 f9ab44b3b3a Simplify ConvertYamlConfigurationExecutor via SPI (#27281)
f9ab44b3b3a is described below
commit f9ab44b3b3af5f3d3a40b626fb32f68f66f22c10
Author: Raigor <[email protected]>
AuthorDate: Wed Jul 19 08:28:19 2023 +0800
Simplify ConvertYamlConfigurationExecutor via SPI (#27281)
---
...dler.ral.query.ConvertRuleConfigurationProvider | 2 --
...dler.ral.query.ConvertRuleConfigurationProvider | 2 --
...dler.ral.query.ConvertRuleConfigurationProvider | 2 --
.../ConvertYamlConfigurationExecutor.java | 37 ++++------------------
4 files changed, 6 insertions(+), 37 deletions(-)
diff --git
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
b/features/encrypt/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
similarity index 79%
copy from
proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
copy to
features/encrypt/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
index 7df32713fd6..42003f17cdc 100644
---
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
+++
b/features/encrypt/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
@@ -15,6 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.sharding.distsql.handler.provider.ShardingConvertRuleConfigurationProvider
-org.apache.shardingsphere.readwritesplitting.distsql.handler.provider.ReadwriteSplittingConvertRuleConfigurationProvider
org.apache.shardingsphere.encrypt.distsql.handler.provider.EncryptConvertRuleConfigurationProvider
diff --git
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
similarity index 81%
copy from
proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
copy to
features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
index 7df32713fd6..fb5b48f2843 100644
---
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
+++
b/features/readwrite-splitting/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
@@ -15,6 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.sharding.distsql.handler.provider.ShardingConvertRuleConfigurationProvider
org.apache.shardingsphere.readwritesplitting.distsql.handler.provider.ReadwriteSplittingConvertRuleConfigurationProvider
-org.apache.shardingsphere.encrypt.distsql.handler.provider.EncryptConvertRuleConfigurationProvider
diff --git
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
similarity index 80%
rename from
proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
rename to
features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
index 7df32713fd6..87db103ca0a 100644
---
a/proxy/backend/core/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
+++
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurationProvider
@@ -16,5 +16,3 @@
#
org.apache.shardingsphere.sharding.distsql.handler.provider.ShardingConvertRuleConfigurationProvider
-org.apache.shardingsphere.readwritesplitting.distsql.handler.provider.ReadwriteSplittingConvertRuleConfigurationProvider
-org.apache.shardingsphere.encrypt.distsql.handler.provider.EncryptConvertRuleConfigurationProvider
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
index 5d4ad39418b..8cdbb625b2f 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
@@ -25,10 +25,6 @@ import
org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurat
import
org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
import
org.apache.shardingsphere.encrypt.api.config.CompatibleEncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.YamlCompatibleEncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.config.YamlEncryptRuleConfiguration;
-import
org.apache.shardingsphere.encrypt.yaml.swapper.YamlCompatibleEncryptRuleConfigurationSwapper;
-import
org.apache.shardingsphere.encrypt.yaml.swapper.YamlEncryptRuleConfigurationSwapper;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
@@ -36,27 +32,21 @@ import
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCrea
import
org.apache.shardingsphere.infra.datasource.props.custom.CustomDataSourceProperties;
import
org.apache.shardingsphere.infra.datasource.props.synonym.PoolPropertySynonyms;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.util.spi.type.ordered.OrderedSPILoader;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
+import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import
org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
import
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
-import org.apache.shardingsphere.mask.yaml.config.YamlMaskRuleConfiguration;
-import
org.apache.shardingsphere.mask.yaml.swapper.YamlMaskRuleConfigurationSwapper;
import
org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDataSourceConfiguration;
import
org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDatabaseConfiguration;
import
org.apache.shardingsphere.proxy.backend.config.yaml.swapper.YamlProxyDataSourceConfigurationSwapper;
import org.apache.shardingsphere.proxy.backend.exception.FileIOException;
-import
org.apache.shardingsphere.readwritesplitting.yaml.config.YamlReadwriteSplittingRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.yaml.swapper.YamlReadwriteSplittingRuleConfigurationSwapper;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
-import
org.apache.shardingsphere.shadow.yaml.config.YamlShadowRuleConfiguration;
-import
org.apache.shardingsphere.shadow.yaml.swapper.YamlShadowRuleConfigurationSwapper;
-import
org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
-import
org.apache.shardingsphere.sharding.yaml.swapper.YamlShardingRuleConfigurationSwapper;
import java.io.File;
import java.io.IOException;
@@ -115,28 +105,13 @@ public final class ConvertYamlConfigurationExecutor
implements QueryableRALExecu
return result.toString();
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
private Map<Integer, RuleConfiguration> swapToRuleConfigs(final
YamlProxyDatabaseConfiguration yamlConfig) {
Map<Integer, RuleConfiguration> result = new
TreeMap<>(Comparator.reverseOrder());
for (YamlRuleConfiguration each : yamlConfig.getRules()) {
- if (each instanceof YamlShardingRuleConfiguration) {
- YamlShardingRuleConfigurationSwapper swapper = new
YamlShardingRuleConfigurationSwapper();
- result.put(swapper.getOrder(),
swapper.swapToObject((YamlShardingRuleConfiguration) each));
- } else if (each instanceof
YamlReadwriteSplittingRuleConfiguration) {
- YamlReadwriteSplittingRuleConfigurationSwapper swapper = new
YamlReadwriteSplittingRuleConfigurationSwapper();
- result.put(swapper.getOrder(),
swapper.swapToObject((YamlReadwriteSplittingRuleConfiguration) each));
- } else if (each instanceof YamlEncryptRuleConfiguration) {
- YamlEncryptRuleConfigurationSwapper swapper = new
YamlEncryptRuleConfigurationSwapper();
- result.put(swapper.getOrder(),
swapper.swapToObject((YamlEncryptRuleConfiguration) each));
- } else if (each instanceof YamlCompatibleEncryptRuleConfiguration)
{
- YamlCompatibleEncryptRuleConfigurationSwapper swapper = new
YamlCompatibleEncryptRuleConfigurationSwapper();
- result.put(swapper.getOrder(),
swapper.swapToObject((YamlCompatibleEncryptRuleConfiguration) each));
- } else if (each instanceof YamlShadowRuleConfiguration) {
- YamlShadowRuleConfigurationSwapper swapper = new
YamlShadowRuleConfigurationSwapper();
- result.put(swapper.getOrder(),
swapper.swapToObject((YamlShadowRuleConfiguration) each));
- } else if (each instanceof YamlMaskRuleConfiguration) {
- YamlMaskRuleConfigurationSwapper swapper = new
YamlMaskRuleConfigurationSwapper();
- result.put(swapper.getOrder(),
swapper.swapToObject((YamlMaskRuleConfiguration) each));
- }
+ YamlRuleConfigurationSwapper swapper =
OrderedSPILoader.getServicesByClass(YamlRuleConfigurationSwapper.class,
Collections.singleton(each.getRuleConfigurationType()))
+ .get(each.getRuleConfigurationType());
+ result.put(swapper.getOrder(), (RuleConfiguration)
swapper.swapToObject(each));
}
return result;
}