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 00dbf3a2462 Refactor DistSQLExecutorRequiredChecker (#29993)
00dbf3a2462 is described below
commit 00dbf3a246217e67a237b0b4e3596c0e4f5356f8
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Feb 4 23:05:13 2024 +0800
Refactor DistSQLExecutorRequiredChecker (#29993)
* Refactor DistSQLUpdateExecuteEngine
* Refactor DistSQLExecutorRequiredChecker
---
.../update/DropBroadcastTableRuleExecutor.java | 2 +-
.../handler/update/AlterEncryptRuleExecutor.java | 2 +-
.../handler/update/DropEncryptRuleExecutor.java | 2 +-
.../handler/update/AlterMaskRuleExecutor.java | 2 +-
.../distsql/handler/update/DropMaskRuleExecutor.java | 2 +-
.../update/AlterReadwriteSplittingRuleExecutor.java | 2 +-
.../update/DropReadwriteSplittingRuleExecutor.java | 2 +-
.../update/AlterDefaultShadowAlgorithmExecutor.java | 2 +-
.../handler/update/AlterShadowRuleExecutor.java | 2 +-
.../update/DropDefaultShadowAlgorithmExecutor.java | 2 +-
.../handler/update/DropShadowAlgorithmExecutor.java | 2 +-
.../handler/update/DropShadowRuleExecutor.java | 2 +-
.../update/AlterDefaultShardingStrategyExecutor.java | 2 +-
.../AlterShardingTableReferenceRuleExecutor.java | 2 +-
.../update/AlterShardingTableRuleExecutor.java | 2 +-
.../CreateShardingTableReferenceRuleExecutor.java | 2 +-
.../update/DropDefaultShardingStrategyExecutor.java | 2 +-
.../update/DropShardingAlgorithmExecutor.java | 2 +-
.../handler/update/DropShardingAuditorExecutor.java | 2 +-
.../update/DropShardingKeyGeneratorExecutor.java | 2 +-
.../update/DropShardingTableReferenceExecutor.java | 2 +-
.../update/DropShardingTableRuleExecutor.java | 2 +-
.../required/DistSQLExecutorCurrentRuleRequired.java | 8 +++++---
.../required/DistSQLExecutorRequiredChecker.java | 20 ++++++++++++++------
.../type/update/DistSQLUpdateExecuteEngine.java | 11 +++++------
.../DatabaseRuleDefinitionExecuteEngine.java | 6 +++---
.../LegacyDatabaseRuleDefinitionExecuteEngine.java | 6 +++---
.../handler/update/UnloadSingleTableExecutor.java | 2 +-
28 files changed, 53 insertions(+), 44 deletions(-)
diff --git
a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java
index 7053231e977..74a690d3e78 100644
---
a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java
+++
b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
/**
* Drop broadcast table rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Broadcast")
+@DistSQLExecutorCurrentRuleRequired(BroadcastRule.class)
@Setter
public final class DropBroadcastTableRuleExecutor implements
DatabaseRuleDropExecutor<DropBroadcastTableRuleStatement, BroadcastRule,
BroadcastRuleConfiguration> {
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
index 9cab21c32e2..8d1f2ca4f2f 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java
@@ -49,7 +49,7 @@ import java.util.stream.Collectors;
/**
* Alter encrypt rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Encrypt")
+@DistSQLExecutorCurrentRuleRequired(EncryptRule.class)
@Setter
public final class AlterEncryptRuleExecutor implements
DatabaseRuleAlterExecutor<AlterEncryptRuleStatement, EncryptRule,
EncryptRuleConfiguration> {
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java
index 9b850607f9c..dd92d227e75 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java
@@ -40,7 +40,7 @@ import java.util.stream.Collectors;
/**
* Drop encrypt rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Encrypt")
+@DistSQLExecutorCurrentRuleRequired(EncryptRule.class)
@Setter
public final class DropEncryptRuleExecutor implements
DatabaseRuleDropExecutor<DropEncryptRuleStatement, EncryptRule,
EncryptRuleConfiguration> {
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
index 2014908805e..d4ad38655c5 100644
---
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java
@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
/**
* Alter mask rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Mask")
+@DistSQLExecutorCurrentRuleRequired(MaskRule.class)
@Setter
public final class AlterMaskRuleExecutor implements
DatabaseRuleAlterExecutor<AlterMaskRuleStatement, MaskRule,
MaskRuleConfiguration> {
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java
index f3b13e15a29..e3fd674dad2 100644
---
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java
@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
/**
* Drop mask rule statement executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Mask")
+@DistSQLExecutorCurrentRuleRequired(MaskRule.class)
@Setter
public final class DropMaskRuleExecutor implements
DatabaseRuleDropExecutor<DropMaskRuleStatement, MaskRule,
MaskRuleConfiguration> {
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
index 4fa48aab0d8..7455ccf2d78 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java
@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
/**
* Alter readwrite-splitting rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Readwrite-splitting")
+@DistSQLExecutorCurrentRuleRequired(ReadwriteSplittingRule.class)
@Setter
public final class AlterReadwriteSplittingRuleExecutor implements
DatabaseRuleAlterExecutor<AlterReadwriteSplittingRuleStatement,
ReadwriteSplittingRule, ReadwriteSplittingRuleConfiguration> {
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java
index 24aedde0f74..660219b7712 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java
@@ -47,7 +47,7 @@ import java.util.stream.Collectors;
/**
* Drop readwrite-splitting rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Readwrite-splitting")
+@DistSQLExecutorCurrentRuleRequired(ReadwriteSplittingRule.class)
@Setter
public final class DropReadwriteSplittingRuleExecutor implements
DatabaseRuleDropExecutor<DropReadwriteSplittingRuleStatement,
ReadwriteSplittingRule, ReadwriteSplittingRuleConfiguration> {
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
index d110f796f95..e61be9a79d5 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java
@@ -40,7 +40,7 @@ import java.util.Map;
/**
* Alter default shadow algorithm executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Shadow")
+@DistSQLExecutorCurrentRuleRequired(ShadowRule.class)
@Setter
public final class AlterDefaultShadowAlgorithmExecutor implements
DatabaseRuleAlterExecutor<AlterDefaultShadowAlgorithmStatement, ShadowRule,
ShadowRuleConfiguration> {
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
index 5124bf82645..be88c9b79c5 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java
@@ -43,7 +43,7 @@ import java.util.Map;
/**
* Alter shadow rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Shadow")
+@DistSQLExecutorCurrentRuleRequired(ShadowRule.class)
@Setter
public final class AlterShadowRuleExecutor implements
DatabaseRuleAlterExecutor<AlterShadowRuleStatement, ShadowRule,
ShadowRuleConfiguration> {
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java
index fbeec4d54d5..6d6c58c193e 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java
@@ -32,7 +32,7 @@ import java.util.Collections;
/**
* Drop default shadow algorithm executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Shadow")
+@DistSQLExecutorCurrentRuleRequired(ShadowRule.class)
@Setter
public final class DropDefaultShadowAlgorithmExecutor implements
DatabaseRuleDropExecutor<DropDefaultShadowAlgorithmStatement, ShadowRule,
ShadowRuleConfiguration> {
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
index db9b644febd..5e6478207c4 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
/**
* Drop shadow algorithm executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Shadow")
+@DistSQLExecutorCurrentRuleRequired(ShadowRule.class)
@Setter
public final class DropShadowAlgorithmExecutor implements
DatabaseRuleDropExecutor<DropShadowAlgorithmStatement, ShadowRule,
ShadowRuleConfiguration> {
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java
index 355b3b199af..cbe562de7f3 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java
@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
/**
* Drop shadow rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Shadow")
+@DistSQLExecutorCurrentRuleRequired(ShadowRule.class)
@Setter
public final class DropShadowRuleExecutor implements
DatabaseRuleDropExecutor<DropShadowRuleStatement, ShadowRule,
ShadowRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
index 6451a5ec7ab..c9d1fa87101 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java
@@ -41,7 +41,7 @@ import java.util.Optional;
/**
* Alter default sharding strategy executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class AlterDefaultShardingStrategyExecutor implements
DatabaseRuleAlterExecutor<AlterDefaultShardingStrategyStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
index 59892135f45..123b836afb0 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java
@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
/**
* Alter sharding table reference rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class AlterShardingTableReferenceRuleExecutor implements
DatabaseRuleAlterExecutor<AlterShardingTableReferenceRuleStatement,
ShardingRule, ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
index 45059e1bd4c..c82de9f6c1c 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
/**
* Alter sharding table rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class AlterShardingTableRuleExecutor implements
DatabaseRuleAlterExecutor<AlterShardingTableRuleStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java
index 2759c4bdd75..3b661d01b42 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java
@@ -43,7 +43,7 @@ import java.util.stream.Collectors;
/**
* Create sharding table reference rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class CreateShardingTableReferenceRuleExecutor implements
DatabaseRuleCreateExecutor<CreateShardingTableReferenceRuleStatement,
ShardingRule, ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java
index dedaee5942c..85cebcd344e 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java
@@ -34,7 +34,7 @@ import java.util.Optional;
/**
* Drop default sharding strategy executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class DropDefaultShardingStrategyExecutor implements
DatabaseRuleDropExecutor<DropDefaultShardingStrategyStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java
index 6b73b782c22..d1b9c48c538 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java
@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
/**
* Drop sharding algorithm executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class DropShardingAlgorithmExecutor implements
DatabaseRuleDropExecutor<DropShardingAlgorithmStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java
index 4106a0956f0..71333cf406a 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java
@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
/**
* Drop sharding auditor statement executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding auditor")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class DropShardingAuditorExecutor implements
DatabaseRuleDropExecutor<DropShardingAuditorStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java
index 9b1a22fac10..c473c383071 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java
@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
/**
* Drop sharding key generator executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Key generator")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class DropShardingKeyGeneratorExecutor implements
DatabaseRuleDropExecutor<DropShardingKeyGeneratorStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java
index 40f016f0d33..5e038a4feca 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java
@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
/**
* Drop sharding table reference executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class DropShardingTableReferenceExecutor implements
DatabaseRuleDropExecutor<DropShardingTableReferenceRuleStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java
index b918d6d60dc..c9185aebc2d 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java
@@ -40,7 +40,7 @@ import java.util.stream.Collectors;
/**
* Drop sharding table rule executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Sharding")
+@DistSQLExecutorCurrentRuleRequired(ShardingRule.class)
@Setter
public final class DropShardingTableRuleExecutor implements
DatabaseRuleDropExecutor<DropShardingTableRuleStatement, ShardingRule,
ShardingRuleConfiguration> {
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java
index 240601308a2..34d739b348d 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.distsql.handler.required;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -30,9 +32,9 @@ import java.lang.annotation.Target;
public @interface DistSQLExecutorCurrentRuleRequired {
/**
- * Get rule type.
+ * Get rule class.
*
- * @return rule type
+ * @return rule class
*/
- String value();
+ Class<? extends ShardingSphereRule> value();
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
index 919bd912029..6a3eed8cc5d 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredR
import
org.apache.shardingsphere.distsql.statement.rdl.rule.type.DropRuleStatement;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -41,22 +42,29 @@ public final class DistSQLExecutorRequiredChecker {
*
* @param sqlStatement SQL statement
* @param contextManager context manager
- * @param databaseName database name
- * @param rule rule
+ * @param database database
*/
- public void check(final SQLStatement sqlStatement, final ContextManager
contextManager, final String databaseName, final ShardingSphereRule rule) {
+ public void check(final SQLStatement sqlStatement, final ContextManager
contextManager, final ShardingSphereDatabase database) {
Optional.ofNullable(executor.getClass().getAnnotation(DistSQLExecutorClusterModeRequired.class)).ifPresent(optional
-> checkClusterMode(contextManager));
-
Optional.ofNullable(executor.getClass().getAnnotation(DistSQLExecutorCurrentRuleRequired.class)).ifPresent(optional
-> checkCurrentRule(sqlStatement, databaseName, rule, optional));
+
Optional.ofNullable(executor.getClass().getAnnotation(DistSQLExecutorCurrentRuleRequired.class)).ifPresent(optional
-> checkCurrentRule(sqlStatement, contextManager, database, optional));
}
private void checkClusterMode(final ContextManager contextManager) {
ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(),
() -> new UnsupportedSQLOperationException("Mode must be `Cluster`."));
}
- private void checkCurrentRule(final SQLStatement sqlStatement, final
String databaseName, final ShardingSphereRule rule, final
DistSQLExecutorCurrentRuleRequired currentRuleRequired) {
+ private void checkCurrentRule(final SQLStatement sqlStatement, final
ContextManager contextManager, final ShardingSphereDatabase database,
+ final DistSQLExecutorCurrentRuleRequired
currentRuleRequired) {
if (sqlStatement instanceof DropRuleStatement && ((DropRuleStatement)
sqlStatement).isIfExists()) {
return;
}
- ShardingSpherePreconditions.checkNotNull(rule, () -> new
MissingRequiredRuleException(currentRuleRequired.value(), databaseName));
+ Optional<? extends ShardingSphereRule> rule = findRule(contextManager,
database, currentRuleRequired.value());
+ String ruleType =
currentRuleRequired.value().getSimpleName().substring(0,
currentRuleRequired.value().getSimpleName().indexOf("Rule"));
+ ShardingSpherePreconditions.checkState(rule.isPresent(), () -> null ==
database ? new MissingRequiredRuleException(ruleType) : new
MissingRequiredRuleException(ruleType, database.getName()));
+ }
+
+ private Optional<? extends ShardingSphereRule> findRule(final
ContextManager contextManager, final ShardingSphereDatabase database, final
Class<? extends ShardingSphereRule> ruleClass) {
+ Optional<? extends ShardingSphereRule> globalRule =
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().findSingleRule(ruleClass);
+ return null == database || globalRule.isPresent() ? globalRule :
database.getRuleMetaData().findSingleRule(ruleClass);
}
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java
index dfb88097579..e90517404fe 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java
@@ -78,12 +78,10 @@ public abstract class DistSQLUpdateExecuteEngine {
@SuppressWarnings("rawtypes")
private void executeDatabaseRuleDefinitionUpdate(final
DatabaseRuleDefinitionExecutor databaseExecutor) {
if (isNormalRuleUpdater()) {
- new DatabaseRuleDefinitionExecuteEngine(
- (RuleDefinitionStatement) sqlStatement, contextManager,
getDatabase(databaseName), databaseExecutor).executeUpdate();
+ new DatabaseRuleDefinitionExecuteEngine((RuleDefinitionStatement)
sqlStatement, contextManager, getDatabase(databaseName),
databaseExecutor).executeUpdate();
} else {
// TODO Remove when metadata structure adjustment completed. #25485
- new LegacyDatabaseRuleDefinitionExecuteEngine(
- (RuleDefinitionStatement) sqlStatement, contextManager,
getDatabase(databaseName), databaseExecutor).executeUpdate();
+ new
LegacyDatabaseRuleDefinitionExecuteEngine((RuleDefinitionStatement)
sqlStatement, contextManager, getDatabase(databaseName),
databaseExecutor).executeUpdate();
}
}
@@ -106,8 +104,9 @@ public abstract class DistSQLUpdateExecuteEngine {
@SuppressWarnings({"rawtypes", "unchecked"})
private void executeNormalUpdate() throws SQLException {
DistSQLUpdateExecutor executor =
TypedSPILoader.getService(DistSQLUpdateExecutor.class, sqlStatement.getClass());
- new DistSQLExecutorAwareSetter(executor).set(contextManager, null ==
databaseName ? null : getDatabase(databaseName), null);
- new DistSQLExecutorRequiredChecker(executor).check(sqlStatement,
contextManager, databaseName, null);
+ ShardingSphereDatabase database = null == databaseName ? null :
getDatabase(databaseName);
+ new DistSQLExecutorAwareSetter(executor).set(contextManager, database,
null);
+ new DistSQLExecutorRequiredChecker(executor).check(sqlStatement,
contextManager, database);
executor.executeUpdate(sqlStatement, contextManager);
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
index e6d497bda62..6d168fc1662 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java
@@ -52,7 +52,7 @@ public final class DatabaseRuleDefinitionExecuteEngine {
executor.setDatabase(database);
Optional<ShardingSphereRule> rule =
database.getRuleMetaData().findSingleRule(executor.getRuleClass());
executor.setRule(rule.orElse(null));
- checkBeforeUpdate(rule.orElse(null));
+ checkBeforeUpdate();
RuleConfiguration currentRuleConfig =
rule.map(ShardingSphereRule::getConfiguration).orElse(null);
if (getRefreshStatus()) {
contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService()
@@ -61,8 +61,8 @@ public final class DatabaseRuleDefinitionExecuteEngine {
}
@SuppressWarnings("unchecked")
- private void checkBeforeUpdate(final ShardingSphereRule rule) {
- new DistSQLExecutorRequiredChecker(executor).check(sqlStatement,
contextManager, database.getName(), rule);
+ private void checkBeforeUpdate() {
+ new DistSQLExecutorRequiredChecker(executor).check(sqlStatement,
contextManager, database);
executor.checkBeforeUpdate(sqlStatement);
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java
index 86a3303f27b..c90d5704f63 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java
@@ -64,7 +64,7 @@ public final class LegacyDatabaseRuleDefinitionExecuteEngine {
executor.setDatabase(database);
Optional<ShardingSphereRule> rule =
database.getRuleMetaData().findSingleRule(executor.getRuleClass());
executor.setRule(rule.orElse(null));
- checkBeforeUpdate(rule.orElse(null));
+ checkBeforeUpdate();
RuleConfiguration currentRuleConfig =
rule.map(ShardingSphereRule::getConfiguration).orElse(null);
if (getRefreshStatus(sqlStatement, executor)) {
contextManager.getInstanceContext().getModeContextManager().alterRuleConfiguration(database.getName(),
processSQLStatement(database, sqlStatement, executor, currentRuleConfig));
@@ -72,8 +72,8 @@ public final class LegacyDatabaseRuleDefinitionExecuteEngine {
}
@SuppressWarnings("unchecked")
- private void checkBeforeUpdate(final ShardingSphereRule rule) {
- new DistSQLExecutorRequiredChecker(executor).check(sqlStatement,
contextManager, database.getName(), rule);
+ private void checkBeforeUpdate() {
+ new DistSQLExecutorRequiredChecker(executor).check(sqlStatement,
contextManager, database);
executor.checkBeforeUpdate(sqlStatement);
}
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
index 0bea460ee16..4599d63380c 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
/**
* Unload single table statement executor.
*/
-@DistSQLExecutorCurrentRuleRequired("Single")
+@DistSQLExecutorCurrentRuleRequired(SingleRule.class)
@Setter
public final class UnloadSingleTableExecutor implements
DatabaseRuleAlterExecutor<UnloadSingleTableStatement, SingleRule,
SingleRuleConfiguration> {