This is an automated email from the ASF dual-hosted git repository.
zhangyonglun 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 a3c5e7b Add SchemaRule and GlobalRule interface (#9982)
a3c5e7b is described below
commit a3c5e7b5c36a222a3e18b12b81a68c1bac8d524c
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 7 22:10:08 2021 +0800
Add SchemaRule and GlobalRule interface (#9982)
---
.../authority/rule/AuthorityRule.java | 3 ++-
.../common/rule/DatabaseDiscoveryRule.java | 11 +++++-----
.../shardingsphere/encrypt/rule/EncryptRule.java | 3 ++-
.../common/rule/ReadWriteSplittingRule.java | 9 ++++----
.../shardingsphere/shadow/rule/ShadowRule.java | 4 ++--
.../shardingsphere/sharding/rule/ShardingRule.java | 3 ++-
.../infra/rule/scope/GlobalRule.java | 24 +++-------------------
.../infra/rule/scope/SchemaRule.java | 24 +++-------------------
8 files changed, 25 insertions(+), 56 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
index 6335477..da646c4 100644
---
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
+++
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.authority.engine.AuthorityContext;
import org.apache.shardingsphere.authority.engine.impl.DefaultAuthority;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.scope.GlobalRule;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import javax.sql.DataSource;
@@ -34,7 +35,7 @@ import java.util.Collection;
/**
* Authority rule.
*/
-public final class AuthorityRule implements ShardingSphereRule {
+public final class AuthorityRule implements GlobalRule {
static {
ShardingSphereServiceLoader.register(PrivilegeLoadAlgorithm.class);
diff --git
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRule.java
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRule.java
index 6965c34..8e6ea48 100644
---
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRule.java
+++
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-common/src/main/java/org/apache/shardingsphere/db/discovery/common/rule/DatabaseDiscoveryRule.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.db.discovery.common.rule;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.Getter;
+import
org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import
org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import
org.apache.shardingsphere.db.discovery.common.algorithm.config.AlgorithmProvidedDatabaseDiscoveryRuleConfiguration;
import org.apache.shardingsphere.db.discovery.spi.DatabaseDiscoveryType;
import org.apache.shardingsphere.infra.aware.DataSourceNameAware;
@@ -27,15 +29,14 @@ import
org.apache.shardingsphere.infra.aware.DataSourceNameAwareFactory;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
+import
org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceEvent;
+import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.type.StatusContainedRule;
-import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
-import
org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import
org.apache.shardingsphere.db.discovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import
org.apache.shardingsphere.db.discovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -49,7 +50,7 @@ import java.util.Optional;
/**
* Database discovery rule.
*/
-public final class DatabaseDiscoveryRule implements DataSourceContainedRule,
StatusContainedRule {
+public final class DatabaseDiscoveryRule implements SchemaRule,
DataSourceContainedRule, StatusContainedRule {
static {
ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
diff --git
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
index bab30ab..ba75f9f 100644
---
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
+++
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfigu
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.QueryAssistedEncryptAlgorithm;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
+import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -40,7 +41,7 @@ import java.util.stream.Collectors;
/**
* Encrypt rule.
*/
-public final class EncryptRule implements TableContainedRule {
+public final class EncryptRule implements SchemaRule, TableContainedRule {
static {
ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
diff --git
a/shardingsphere-features/shardingsphere-read-write-splitting/shardingsphere-read-write-splitting-common/src/main/java/org/apache/shardingsphere/readwrite/splitting/common/rule/ReadWriteSplittingRule.java
b/shardingsphere-features/shardingsphere-read-write-splitting/shardingsphere-read-write-splitting-common/src/main/java/org/apache/shardingsphere/readwrite/splitting/common/rule/ReadWriteSplittingRule.java
index 3fc02e2..92369f7 100644
---
a/shardingsphere-features/shardingsphere-read-write-splitting/shardingsphere-read-write-splitting-common/src/main/java/org/apache/shardingsphere/readwrite/splitting/common/rule/ReadWriteSplittingRule.java
+++
b/shardingsphere-features/shardingsphere-read-write-splitting/shardingsphere-read-write-splitting-common/src/main/java/org/apache/shardingsphere/readwrite/splitting/common/rule/ReadWriteSplittingRule.java
@@ -20,15 +20,16 @@ package
org.apache.shardingsphere.readwrite.splitting.common.rule;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
-import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
-import org.apache.shardingsphere.infra.rule.type.StatusContainedRule;
import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
import
org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEvent;
+import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
+import org.apache.shardingsphere.infra.rule.type.DataSourceContainedRule;
+import org.apache.shardingsphere.infra.rule.type.StatusContainedRule;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
-import
org.apache.shardingsphere.readwrite.splitting.common.algorithm.config.AlgorithmProvidedReadWriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwrite.splitting.api.ReadWriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwrite.splitting.api.rule.ReadWriteSplittingDataSourceRuleConfiguration;
+import
org.apache.shardingsphere.readwrite.splitting.common.algorithm.config.AlgorithmProvidedReadWriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwrite.splitting.spi.ReplicaLoadBalanceAlgorithm;
import java.util.Collection;
@@ -41,7 +42,7 @@ import java.util.Optional;
/**
* Read write splitting rule.
*/
-public final class ReadWriteSplittingRule implements DataSourceContainedRule,
StatusContainedRule {
+public final class ReadWriteSplittingRule implements SchemaRule,
DataSourceContainedRule, StatusContainedRule {
static {
ShardingSphereServiceLoader.register(ReplicaLoadBalanceAlgorithm.class);
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index ccaee24..8a1dcbe 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.shadow.rule;
import lombok.Getter;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import java.util.HashMap;
@@ -28,7 +28,7 @@ import java.util.Map;
* Databases shadow rule.
*/
@Getter
-public final class ShadowRule implements ShardingSphereRule {
+public final class ShadowRule implements SchemaRule {
private final Map<String, String> shadowMappings;
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 97d1a93..ee50e2b 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.CreateTableEvent;
import
org.apache.shardingsphere.infra.metadata.schema.refresher.event.DropTableEvent;
+import org.apache.shardingsphere.infra.rule.scope.SchemaRule;
import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.type.TableContainedRule;
import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
@@ -67,7 +68,7 @@ import java.util.stream.Collectors;
* Sharding rule.
*/
@Getter
-public final class ShardingRule implements DataNodeContainedRule,
TableContainedRule {
+public final class ShardingRule implements SchemaRule, DataNodeContainedRule,
TableContainedRule {
static {
ShardingSphereServiceLoader.register(ShardingAlgorithm.class);
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java
similarity index 51%
copy from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
copy to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java
index ccaee24..fbe266c 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java
@@ -15,30 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.rule;
+package org.apache.shardingsphere.infra.rule.scope;
-import lombok.Getter;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-
-import java.util.HashMap;
-import java.util.Map;
/**
- * Databases shadow rule.
+ * Global rule.
*/
-@Getter
-public final class ShadowRule implements ShardingSphereRule {
-
- private final Map<String, String> shadowMappings;
-
- private final String column;
-
- public ShadowRule(final ShadowRuleConfiguration shadowRuleConfig) {
- column = shadowRuleConfig.getColumn();
- shadowMappings = new
HashMap<>(shadowRuleConfig.getShadowDataSourceNames().size());
- for (int i = 0; i <
shadowRuleConfig.getSourceDataSourceNames().size(); i++) {
-
shadowMappings.put(shadowRuleConfig.getSourceDataSourceNames().get(i),
shadowRuleConfig.getShadowDataSourceNames().get(i));
- }
- }
+public interface GlobalRule extends ShardingSphereRule {
}
diff --git
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/scope/SchemaRule.java
similarity index 51%
copy from
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
copy to
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/scope/SchemaRule.java
index ccaee24..55f99a0 100644
---
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/scope/SchemaRule.java
@@ -15,30 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.shadow.rule;
+package org.apache.shardingsphere.infra.rule.scope;
-import lombok.Getter;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-
-import java.util.HashMap;
-import java.util.Map;
/**
- * Databases shadow rule.
+ * Schema rule.
*/
-@Getter
-public final class ShadowRule implements ShardingSphereRule {
-
- private final Map<String, String> shadowMappings;
-
- private final String column;
-
- public ShadowRule(final ShadowRuleConfiguration shadowRuleConfig) {
- column = shadowRuleConfig.getColumn();
- shadowMappings = new
HashMap<>(shadowRuleConfig.getShadowDataSourceNames().size());
- for (int i = 0; i <
shadowRuleConfig.getSourceDataSourceNames().size(); i++) {
-
shadowMappings.put(shadowRuleConfig.getSourceDataSourceNames().get(i),
shadowRuleConfig.getShadowDataSourceNames().get(i));
- }
- }
+public interface SchemaRule extends ShardingSphereRule {
}