This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 81c259a5256 Refactor GlobalRuleDefinitionExecutor.checkBeforeUpdate
(#29896)
81c259a5256 is described below
commit 81c259a52562a7170f21917c93700be633b464cd
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 29 12:24:27 2024 +0800
Refactor GlobalRuleDefinitionExecutor.checkBeforeUpdate (#29896)
* Code format for test cases
* Refactor GlobalRuleDefinitionExecutor.checkBeforeUpdate
---
.../rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java | 2 +-
.../rule/engine/legacy/LegacyGlobalRuleDefinitionExecuteEngine.java | 2 +-
.../type/rdl/rule/spi/global/GlobalRuleDefinitionExecutor.java | 4 ++--
.../distsql/handler/update/AlterGlobalClockRuleExecutor.java | 2 +-
.../distsql/handler/update/AlterSQLFederationRuleExecutor.java | 2 +-
.../parser/distsql/handler/update/AlterSQLParserRuleExecutor.java | 2 +-
.../distsql/handler/update/AlterSQLTranslatorRuleExecutor.java | 2 +-
.../traffic/distsql/handler/update/AlterTrafficRuleExecutor.java | 2 +-
.../traffic/distsql/handler/update/AlterTrafficRuleExecutorTest.java | 4 ++--
.../distsql/handler/update/AlterTransactionRuleExecutor.java | 2 +-
10 files changed, 12 insertions(+), 12 deletions(-)
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
index bf06a5a3b29..77f3c072159 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
@@ -46,7 +46,7 @@ public final class GlobalRuleDefinitionExecuteEngine {
public void executeUpdate() {
Collection<RuleConfiguration> ruleConfigs =
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getConfigurations();
RuleConfiguration currentRuleConfig =
findCurrentRuleConfiguration(ruleConfigs, executor.getRuleConfigurationClass());
- executor.checkBeforeUpdate(currentRuleConfig, sqlStatement);
+ executor.checkBeforeUpdate(sqlStatement, currentRuleConfig);
contextManager.getInstanceContext().getModeContextManager().alterGlobalRuleConfiguration(processUpdate(ruleConfigs,
sqlStatement, currentRuleConfig));
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/legacy/LegacyGlobalRuleDefinitionExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/legacy/LegacyGlobalRuleDefinitionExecuteEngine.java
index 5e690bdbafb..d1ede4f3bd1 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/legacy/LegacyGlobalRuleDefinitionExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/engine/legacy/LegacyGlobalRuleDefinitionExecuteEngine.java
@@ -48,7 +48,7 @@ public final class LegacyGlobalRuleDefinitionExecuteEngine {
public void executeUpdate() {
Collection<RuleConfiguration> ruleConfigs =
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getConfigurations();
RuleConfiguration currentRuleConfig =
findCurrentRuleConfiguration(ruleConfigs, executor.getRuleConfigurationClass());
- executor.checkBeforeUpdate(currentRuleConfig, sqlStatement);
+ executor.checkBeforeUpdate(sqlStatement, currentRuleConfig);
contextManager.getInstanceContext().getModeContextManager().alterGlobalRuleConfiguration(processUpdate(ruleConfigs,
sqlStatement, executor, currentRuleConfig));
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/global/GlobalRuleDefinitionExecutor.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/global/GlobalRuleDefinitionExecutor.java
index a277ef8fa2c..f388135759c 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/global/GlobalRuleDefinitionExecutor.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rdl/rule/spi/global/GlobalRuleDefinitionExecutor.java
@@ -34,10 +34,10 @@ public interface GlobalRuleDefinitionExecutor<T extends
RuleDefinitionStatement,
/**
* Check before update.
*
- * @param currentRuleConfig current rule configuration
* @param sqlStatement SQL statement
+ * @param currentRuleConfig current rule configuration
*/
- void checkBeforeUpdate(R currentRuleConfig, T sqlStatement);
+ void checkBeforeUpdate(T sqlStatement, R currentRuleConfig);
/**
* Build altered rule configuration.
diff --git
a/kernel/global-clock/distsql/handler/src/main/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutor.java
b/kernel/global-clock/distsql/handler/src/main/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutor.java
index e0e37c85793..1f3e62bd66f 100644
---
a/kernel/global-clock/distsql/handler/src/main/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutor.java
+++
b/kernel/global-clock/distsql/handler/src/main/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutor.java
@@ -27,7 +27,7 @@ import
org.apache.shardingsphere.globalclock.distsql.statement.updatable.AlterGl
public final class AlterGlobalClockRuleExecutor implements
GlobalRuleDefinitionExecutor<AlterGlobalClockRuleStatement,
GlobalClockRuleConfiguration> {
@Override
- public void checkBeforeUpdate(final GlobalClockRuleConfiguration
currentRuleConfig, final AlterGlobalClockRuleStatement sqlStatement) {
+ public void checkBeforeUpdate(final AlterGlobalClockRuleStatement
sqlStatement, final GlobalClockRuleConfiguration currentRuleConfig) {
}
@Override
diff --git
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutor.java
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutor.java
index 38051fa066b..050021829b3 100644
---
a/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutor.java
+++
b/kernel/sql-federation/distsql/handler/src/main/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutor.java
@@ -29,7 +29,7 @@ import
org.apache.shardingsphere.sqlfederation.distsql.statement.updatable.Alter
public final class AlterSQLFederationRuleExecutor implements
GlobalRuleDefinitionExecutor<AlterSQLFederationRuleStatement,
SQLFederationRuleConfiguration> {
@Override
- public void checkBeforeUpdate(final SQLFederationRuleConfiguration
currentRuleConfig, final AlterSQLFederationRuleStatement sqlStatement) {
+ public void checkBeforeUpdate(final AlterSQLFederationRuleStatement
sqlStatement, final SQLFederationRuleConfiguration currentRuleConfig) {
}
@Override
diff --git
a/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutor.java
b/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutor.java
index 9f076fcecb3..6c821490684 100644
---
a/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutor.java
+++
b/kernel/sql-parser/distsql/handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutor.java
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.sql.parser.api.CacheOption;
public final class AlterSQLParserRuleExecutor implements
GlobalRuleDefinitionExecutor<AlterSQLParserRuleStatement,
SQLParserRuleConfiguration> {
@Override
- public void checkBeforeUpdate(final SQLParserRuleConfiguration
currentRuleConfig, final AlterSQLParserRuleStatement sqlStatement) {
+ public void checkBeforeUpdate(final AlterSQLParserRuleStatement
sqlStatement, final SQLParserRuleConfiguration currentRuleConfig) {
}
@Override
diff --git
a/kernel/sql-translator/distsql/handler/src/main/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutor.java
b/kernel/sql-translator/distsql/handler/src/main/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutor.java
index 753fa4fc2bc..f63152ac009 100644
---
a/kernel/sql-translator/distsql/handler/src/main/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutor.java
+++
b/kernel/sql-translator/distsql/handler/src/main/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutor.java
@@ -29,7 +29,7 @@ import
org.apache.shardingsphere.sqltranslator.spi.SQLTranslator;
public final class AlterSQLTranslatorRuleExecutor implements
GlobalRuleDefinitionExecutor<AlterSQLTranslatorRuleStatement,
SQLTranslatorRuleConfiguration> {
@Override
- public void checkBeforeUpdate(final SQLTranslatorRuleConfiguration
currentRuleConfig, final AlterSQLTranslatorRuleStatement sqlStatement) {
+ public void checkBeforeUpdate(final AlterSQLTranslatorRuleStatement
sqlStatement, final SQLTranslatorRuleConfiguration currentRuleConfig) {
TypedSPILoader.checkService(SQLTranslator.class,
sqlStatement.getProvider().getName(), sqlStatement.getProvider().getProps());
}
diff --git
a/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutor.java
b/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutor.java
index f96bbb4bcb4..b6a850229d1 100644
---
a/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutor.java
+++
b/kernel/traffic/distsql/handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutor.java
@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
public final class AlterTrafficRuleExecutor implements
GlobalRuleDefinitionExecutor<AlterTrafficRuleStatement,
TrafficRuleConfiguration> {
@Override
- public void checkBeforeUpdate(final TrafficRuleConfiguration
currentRuleConfig, final AlterTrafficRuleStatement sqlStatement) {
+ public void checkBeforeUpdate(final AlterTrafficRuleStatement
sqlStatement, final TrafficRuleConfiguration currentRuleConfig) {
checkRuleNames(currentRuleConfig, sqlStatement);
checkAlgorithmNames(sqlStatement);
}
diff --git
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutorTest.java
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutorTest.java
index f01e9e74578..0dcdc528f2a 100644
---
a/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutorTest.java
+++
b/kernel/traffic/distsql/handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleExecutorTest.java
@@ -46,7 +46,7 @@ class AlterTrafficRuleExecutorTest {
"rule_name_3", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
AlterTrafficRuleExecutor executor = new AlterTrafficRuleExecutor();
assertThrows(MissingRequiredRuleException.class,
- () ->
executor.checkBeforeUpdate(createTrafficRuleConfiguration(), new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment))));
+ () -> executor.checkBeforeUpdate(new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)),
createTrafficRuleConfiguration()));
}
@Test
@@ -55,7 +55,7 @@ class AlterTrafficRuleExecutorTest {
"rule_name_1", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("invalid", new Properties()), new AlgorithmSegment("invalid",
new Properties()));
AlterTrafficRuleExecutor executor = new AlterTrafficRuleExecutor();
assertThrows(ServiceProviderNotFoundException.class,
- () ->
executor.checkBeforeUpdate(createTrafficRuleConfiguration(), new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment))));
+ () -> executor.checkBeforeUpdate(new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)),
createTrafficRuleConfiguration()));
}
@Test
diff --git
a/kernel/transaction/distsql/handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutor.java
b/kernel/transaction/distsql/handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutor.java
index c8decf6c86e..02a99ec88d7 100644
---
a/kernel/transaction/distsql/handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutor.java
+++
b/kernel/transaction/distsql/handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleExecutor.java
@@ -35,7 +35,7 @@ import java.util.Optional;
public final class AlterTransactionRuleExecutor implements
GlobalRuleDefinitionExecutor<AlterTransactionRuleStatement,
TransactionRuleConfiguration> {
@Override
- public void checkBeforeUpdate(final TransactionRuleConfiguration
currentRuleConfig, final AlterTransactionRuleStatement sqlStatement) {
+ public void checkBeforeUpdate(final AlterTransactionRuleStatement
sqlStatement, final TransactionRuleConfiguration currentRuleConfig) {
checkTransactionType(sqlStatement);
TransactionType transactionType =
TransactionType.valueOf(sqlStatement.getDefaultType().toUpperCase());
if (TransactionType.LOCAL == transactionType) {