This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 749da400706 Add GlobalRuleDefinitionExecutorFactory (#36136)
749da400706 is described below
commit 749da400706f32ca9a17e7b77f082756ddcde23b
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jul 31 21:31:34 2025 +0800
Add GlobalRuleDefinitionExecutorFactory (#36136)
* Add GlobalRuleDefinitionExecutorFactory
* Add GlobalRuleDefinitionExecutorFactory
---
.../engine/update/DistSQLUpdateExecuteEngine.java | 5 ++-
.../global/GlobalRuleDefinitionExecuteEngine.java | 3 --
.../GlobalRuleDefinitionExecutorFactory.java | 50 ++++++++++++++++++++++
3 files changed, 53 insertions(+), 5 deletions(-)
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java
index 0da78106f84..cf5308e60d7 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/DistSQLUpdateExecuteEngine.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.engine.g
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleDefinitionExecutor;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleDefinitionExecutorFactory;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.global.GlobalRuleDefinitionExecutor;
+import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.global.GlobalRuleDefinitionExecutorFactory;
import
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorRequiredChecker;
import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
@@ -73,8 +74,8 @@ public final class DistSQLUpdateExecuteEngine {
if (databaseExecutor.isPresent()) {
new
DatabaseRuleDefinitionExecuteEngine((DatabaseRuleDefinitionStatement)
sqlStatement, contextManager, database, databaseExecutor.get()).executeUpdate();
} else {
- new
GlobalRuleDefinitionExecuteEngine((GlobalRuleDefinitionStatement) sqlStatement,
- contextManager,
TypedSPILoader.getService(GlobalRuleDefinitionExecutor.class,
sqlStatement.getClass())).executeUpdate();
+ GlobalRuleDefinitionExecutor globalExecutor =
GlobalRuleDefinitionExecutorFactory.newInstance(sqlStatement,
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData());
+ new
GlobalRuleDefinitionExecuteEngine((GlobalRuleDefinitionStatement) sqlStatement,
contextManager, globalExecutor).executeUpdate();
}
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
index 734337d0ac6..b115613b0a5 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/global/GlobalRuleDefinitionExecuteEngine.java
@@ -20,7 +20,6 @@ package
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.engine.
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.global.GlobalRuleDefinitionExecutor;
import
org.apache.shardingsphere.distsql.statement.type.rdl.rule.global.GlobalRuleDefinitionStatement;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import java.sql.SQLException;
@@ -45,8 +44,6 @@ public final class GlobalRuleDefinitionExecuteEngine {
*/
@SuppressWarnings("unchecked")
public void executeUpdate() throws SQLException {
- ShardingSphereRule rule =
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(executor.getRuleClass());
- executor.setRule(rule);
executor.checkBeforeUpdate(sqlStatement);
contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService().alterGlobalRuleConfiguration(executor.buildToBeAlteredRuleConfiguration(sqlStatement));
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/spi/global/GlobalRuleDefinitionExecutorFactory.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/spi/global/GlobalRuleDefinitionExecutorFactory.java
new file mode 100644
index 00000000000..0a9ba2c617f
--- /dev/null
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/spi/global/GlobalRuleDefinitionExecutorFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.global;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+
+/**
+ * Global rule definition executor factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class GlobalRuleDefinitionExecutorFactory {
+
+ /**
+ * Create new instance.
+ *
+ * @param sqlStatement SQL statement
+ * @param globalRuleMetaData global rule meta data
+ * @return created instance
+ */
+ @SuppressWarnings("rawtypes")
+ public static GlobalRuleDefinitionExecutor newInstance(final
DistSQLStatement sqlStatement, final RuleMetaData globalRuleMetaData) {
+ GlobalRuleDefinitionExecutor result =
TypedSPILoader.getService(GlobalRuleDefinitionExecutor.class,
sqlStatement.getClass());
+ setAttributes(result, globalRuleMetaData);
+ return result;
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private static void setAttributes(final GlobalRuleDefinitionExecutor
executor, final RuleMetaData globalRuleMetaData) {
+
executor.setRule(globalRuleMetaData.getSingleRule(executor.getRuleClass()));
+ }
+}