You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/08/05 06:51:19 UTC
[shardingsphere] branch master updated: refactor SingleTableRule
from FeatureRule to KernelRule (#11656)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 1c084f3 refactor SingleTableRule from FeatureRule to KernelRule (#11656)
1c084f3 is described below
commit 1c084f324dff6175594dd93738bb4dd377908823
Author: Zhengqiang Duan <st...@gmail.com>
AuthorDate: Thu Aug 5 14:50:51 2021 +0800
refactor SingleTableRule from FeatureRule to KernelRule (#11656)
---
.../constant/DatabaseDiscoveryOrder.java | 2 +-
.../encrypt/constant/EncryptOrder.java | 2 +-
.../constant/ReadwriteSplittingOrder.java | 2 +-
.../shadow/constant/ShadowOrder.java | 2 +-
.../ShadowSQLRewriteContextDecoratorTest.java | 2 +-
.../sharding/constant/ShardingOrder.java | 2 +-
.../infra/constant/SingleTableOrder.java | 2 +-
.../rule/builder/ShardingSphereRulesBuilder.java | 9 +------
...efaultSingleTableRuleConfigurationBuilder.java} | 28 ++++++++++++----------
.../builder/single/SingleTableRuleBuilder.java | 4 ++--
.../infra/rule/single/SingleTableRule.java | 15 ++++++------
...der.level.DefaultKernelRuleConfigurationBuilder | 18 ++++++++++++++
.../fixture/TestShardingSphereRuleBuilder.java | 2 +-
.../checker/RuleConfigurationCheckerFixture.java | 2 +-
.../infra/context/fixture/FixtureRuleBuilder.java | 2 +-
.../route/fixture/router/SQLRouterFixture.java | 2 +-
16 files changed, 55 insertions(+), 41 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/constant/DatabaseDiscoveryOrder.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/constant/DatabaseDiscoveryOrder.java
index 5ae5fe2..b97c9fb 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/constant/DatabaseDiscoveryOrder.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/constant/DatabaseDiscoveryOrder.java
@@ -29,7 +29,7 @@ public final class DatabaseDiscoveryOrder {
/**
* Database discovery order.
*/
- public static final int ORDER = 40;
+ public static final int ORDER = 30;
/**
* Algorithm provider database discovery order.
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/constant/EncryptOrder.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/constant/EncryptOrder.java
index c0567b5..ce8f2f1 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/constant/EncryptOrder.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/constant/EncryptOrder.java
@@ -29,7 +29,7 @@ public final class EncryptOrder {
/**
* Encrypt order.
*/
- public static final int ORDER = 20;
+ public static final int ORDER = 10;
/**
* Algorithm provider encrypt order.
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/constant/ReadwriteSplittingOrder.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/constant/ReadwriteSplittingOrder.java
index dc0916b..0a7ff12 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/constant/ReadwriteSplittingOrder.java
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/constant/ReadwriteSplittingOrder.java
@@ -29,7 +29,7 @@ public final class ReadwriteSplittingOrder {
/**
* Readwrite-splitting order.
*/
- public static final int ORDER = 30;
+ public static final int ORDER = 20;
/**
* Algorithm provider readwrite-splitting order.
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/constant/ShadowOrder.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/constant/ShadowOrder.java
index 3541d47..1f65107 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/constant/ShadowOrder.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/constant/ShadowOrder.java
@@ -29,5 +29,5 @@ public final class ShadowOrder {
/**
* Shadow order.
*/
- public static final int ORDER = 50;
+ public static final int ORDER = 40;
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecoratorTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecoratorTest.java
index e9f6085..ba94d74 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecoratorTest.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rewrite/context/ShadowSQLRewriteContextDecoratorTest.java
@@ -35,7 +35,7 @@ public final class ShadowSQLRewriteContextDecoratorTest {
@Test
public void assertGetOrder() {
- assertThat(shadowSQLRewriteContextDecorator.getOrder(), is(50));
+ assertThat(shadowSQLRewriteContextDecorator.getOrder(), is(40));
}
@Test
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/constant/ShardingOrder.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/constant/ShardingOrder.java
index aa9f2f8..22acab0 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/constant/ShardingOrder.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/constant/ShardingOrder.java
@@ -29,7 +29,7 @@ public final class ShardingOrder {
/**
* Sharding order.
*/
- public static final int ORDER = 0;
+ public static final int ORDER = -10;
/**
* Algorithm provider sharding order.
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/SingleTableOrder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/SingleTableOrder.java
index cf91c6f..a4ec5f0 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/SingleTableOrder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/constant/SingleTableOrder.java
@@ -29,5 +29,5 @@ public final class SingleTableOrder {
/**
* Single table order.
*/
- public static final int ORDER = 10;
+ public static final int ORDER = 0;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java
index 79f4249..fefec69 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/ShardingSphereRulesBuilder.java
@@ -22,7 +22,6 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.function.DistributedRuleConfiguration;
import org.apache.shardingsphere.infra.config.function.EnhancedRuleConfiguration;
-import org.apache.shardingsphere.infra.config.single.SingleTableRuleConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -67,7 +66,7 @@ public final class ShardingSphereRulesBuilder {
@SuppressWarnings({"unchecked", "rawtypes"})
public static Collection<ShardingSphereRule> buildSchemaRules(final String schemaName, final Collection<RuleConfiguration> schemaRuleConfigs,
final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap) {
- Map<RuleConfiguration, SchemaRuleBuilder> builders = getSchemaRuleBuilders(getAllSchemaRuleConfigurations(schemaRuleConfigs));
+ Map<RuleConfiguration, SchemaRuleBuilder> builders = getSchemaRuleBuilders(schemaRuleConfigs);
appendDefaultKernelSchemaRuleConfigurationBuilder(builders);
Collection<ShardingSphereRule> result = new LinkedList<>();
for (Entry<RuleConfiguration, SchemaRuleBuilder> entry : builders.entrySet()) {
@@ -96,12 +95,6 @@ public final class ShardingSphereRulesBuilder {
return result;
}
- private static Collection<RuleConfiguration> getAllSchemaRuleConfigurations(final Collection<RuleConfiguration> schemaRuleConfigs) {
- Collection<RuleConfiguration> result = new LinkedList<>(schemaRuleConfigs);
- result.add(new SingleTableRuleConfiguration());
- return result;
- }
-
@SuppressWarnings("rawtypes")
private static void appendDefaultKernelSchemaRuleConfigurationBuilder(final Map<RuleConfiguration, SchemaRuleBuilder> builders) {
Map<SchemaRuleBuilder, DefaultKernelRuleConfigurationBuilder> defaultBuilders =
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFixture.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/DefaultSingleTableRuleConfigurationBuilder.java
similarity index 53%
copy from shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFixture.java
copy to shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/DefaultSingleTableRuleConfigurationBuilder.java
index d609438..dbae0d5 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFixture.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/DefaultSingleTableRuleConfigurationBuilder.java
@@ -15,25 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.rule.fixture.checker;
+package org.apache.shardingsphere.infra.rule.builder.single;
-import org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker;
-import org.apache.shardingsphere.infra.rule.fixture.TestRuleConfiguration;
-
-public final class RuleConfigurationCheckerFixture implements RuleConfigurationChecker<TestRuleConfiguration> {
+import org.apache.shardingsphere.infra.config.single.SingleTableRuleConfiguration;
+import org.apache.shardingsphere.infra.constant.SingleTableOrder;
+import org.apache.shardingsphere.infra.rule.builder.level.DefaultKernelRuleConfigurationBuilder;
+/**
+ * Default single table rule configuration builder.
+ */
+public final class DefaultSingleTableRuleConfigurationBuilder implements DefaultKernelRuleConfigurationBuilder<SingleTableRuleConfiguration, SingleTableRuleBuilder> {
+
@Override
- public void check(final String schemaName, final TestRuleConfiguration config) {
-
+ public SingleTableRuleConfiguration build() {
+ return new SingleTableRuleConfiguration();
}
-
+
@Override
public int getOrder() {
- return 0;
+ return SingleTableOrder.ORDER;
}
-
+
@Override
- public Class<TestRuleConfiguration> getTypeClass() {
- return TestRuleConfiguration.class;
+ public Class<SingleTableRuleBuilder> getTypeClass() {
+ return SingleTableRuleBuilder.class;
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java
index 63ce567..0a717bf 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/builder/single/SingleTableRuleBuilder.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.config.single.SingleTableRuleConfiguratio
import org.apache.shardingsphere.infra.constant.SingleTableOrder;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.builder.level.FeatureRuleBuilder;
+import org.apache.shardingsphere.infra.rule.builder.level.KernelRuleBuilder;
import org.apache.shardingsphere.infra.rule.builder.scope.SchemaRuleBuilder;
import org.apache.shardingsphere.infra.rule.single.SingleTableRule;
@@ -32,7 +32,7 @@ import java.util.Map;
/**
* Single table rule builder.
*/
-public final class SingleTableRuleBuilder implements FeatureRuleBuilder, SchemaRuleBuilder<SingleTableRuleConfiguration> {
+public final class SingleTableRuleBuilder implements KernelRuleBuilder, SchemaRuleBuilder<SingleTableRuleConfiguration> {
@Override
public SingleTableRule build(final String schemaName, final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType,
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java
index 6265d7a..00592d5 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/single/SingleTableRule.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.infra.rule.single;
import lombok.Getter;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.identifier.level.FeatureRule;
+import org.apache.shardingsphere.infra.rule.identifier.level.KernelRule;
import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
@@ -39,7 +39,7 @@ import java.util.stream.Collectors;
* Single table rule.
*/
@Getter
-public final class SingleTableRule implements FeatureRule, SchemaRule {
+public final class SingleTableRule implements KernelRule, SchemaRule {
private final Collection<String> dataSourceNames;
@@ -61,13 +61,12 @@ public final class SingleTableRule implements FeatureRule, SchemaRule {
return result;
}
- private Map<String, DataSource> getAggregateDataSourceMap(final Map<String, DataSource> dataSourceMap, final DataSourceContainedRule each) {
+ private Map<String, DataSource> getAggregateDataSourceMap(final Map<String, DataSource> dataSourceMap, final DataSourceContainedRule rule) {
Map<String, DataSource> result = new HashMap<>();
- for (Entry<String, Collection<String>> entry : each.getDataSourceMapper().entrySet()) {
- Collection<String> actualDataSources = entry.getValue();
- for (String actualDataSource : actualDataSources) {
- if (dataSourceMap.containsKey(actualDataSource)) {
- result.put(entry.getKey(), dataSourceMap.remove(actualDataSource));
+ for (Entry<String, Collection<String>> entry : rule.getDataSourceMapper().entrySet()) {
+ for (String each : entry.getValue()) {
+ if (dataSourceMap.containsKey(each)) {
+ result.put(entry.getKey(), dataSourceMap.remove(each));
}
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.level.DefaultKernelRuleConfigurationBuilder b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.level.DefaultKernelRuleConfigurationBuilder
new file mode 100644
index 0000000..80045ed
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.builder.level.DefaultKernelRuleConfigurationBuilder
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.infra.rule.builder.single.DefaultSingleTableRuleConfigurationBuilder
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java
index 694447b..a155413 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestShardingSphereRuleBuilder.java
@@ -40,7 +40,7 @@ public final class TestShardingSphereRuleBuilder implements SchemaRuleBuilder<Te
@Override
public int getOrder() {
- return 0;
+ return -10;
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFixture.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFixture.java
index d609438..c9cbccf 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFixture.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFixture.java
@@ -29,7 +29,7 @@ public final class RuleConfigurationCheckerFixture implements RuleConfigurationC
@Override
public int getOrder() {
- return 0;
+ return -10;
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java
index db535f2..4f0dbf0 100644
--- a/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java
+++ b/shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/fixture/FixtureRuleBuilder.java
@@ -35,7 +35,7 @@ public final class FixtureRuleBuilder implements SchemaRuleBuilder<FixtureRuleCo
@Override
public int getOrder() {
- return 0;
+ return -10;
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java
index 31a78e0..7adc77a 100644
--- a/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java
+++ b/shardingsphere-infra/shardingsphere-infra-route/src/test/java/org/apache/shardingsphere/infra/route/fixture/router/SQLRouterFixture.java
@@ -45,7 +45,7 @@ public final class SQLRouterFixture implements SQLRouter<RouteRuleFixture> {
@Override
public int getOrder() {
- return 0;
+ return -10;
}
@Override