From 1a88337955bc26df7ce5c4cd648e715cdcd0713d Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Tue, 23 Jan 2024 22:30:38 +0800 Subject: [PATCH] Remove useless RALBackendHandler (#29821) * Remove useless generic type on RuleDefinitionBackendHandler * Refactor CreateDatabaseRuleRDLExecuteEngine * Refactor DropDatabaseRuleRDLExecuteEngine * Remove useless RALBackendHandler * Refactor QueryableRALBackendHandler * Refactor QueryableRALBackendHandler * Refactor CreateDatabaseRuleRDLExecuteEngine --- .../ral/QueryableRALBackendHandler.java | 11 +++----- .../distsql/ral/RALBackendHandler.java | 26 ------------------- .../ral/UpdatableRALBackendHandler.java | 3 ++- .../CreateDatabaseRuleRDLExecuteEngine.java | 15 +++-------- 4 files changed, 10 insertions(+), 45 deletions(-) delete mode 100644 proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandler.java diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java index cb8d485824e52..3427c3c5958a6 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral; +import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.distsql.handler.type.ral.query.ConnectionSizeAwareQueryableRALExecutor; import org.apache.shardingsphere.distsql.handler.type.ral.query.DatabaseAwareQueryableRALExecutor; import org.apache.shardingsphere.distsql.handler.type.ral.query.InstanceContextAwareQueryableRALExecutor; @@ -27,6 +28,7 @@ import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; +import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLBackendHandler; import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell; import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; @@ -47,7 +49,8 @@ * * @param type of queryable RAL statement */ -public final class QueryableRALBackendHandler implements RALBackendHandler { +@RequiredArgsConstructor +public final class QueryableRALBackendHandler implements DistSQLBackendHandler { private final T sqlStatement; @@ -57,12 +60,6 @@ public final class QueryableRALBackendHandler i private MergedResult mergedResult; - @SuppressWarnings("unchecked") - public QueryableRALBackendHandler(final QueryableRALStatement sqlStatement, final ConnectionSession connectionSession) { - this.sqlStatement = (T) sqlStatement; - this.connectionSession = connectionSession; - } - @SuppressWarnings("unchecked") @Override public ResponseHeader execute() { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandler.java deleted file mode 100644 index 1d622db1270e7..0000000000000 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.proxy.backend.handler.distsql.ral; - -import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLBackendHandler; - -/** - * RAL backend handler. - */ -public interface RALBackendHandler extends DistSQLBackendHandler { -} diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java index aae7434e2b25d..a4dabf7709d29 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableRALBackendHandler.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.distsql.statement.ral.UpdatableRALStatement; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; +import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLBackendHandler; import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader; import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader; import org.apache.shardingsphere.proxy.backend.session.ConnectionSession; @@ -36,7 +37,7 @@ * @param type of SQL statement */ @RequiredArgsConstructor -public final class UpdatableRALBackendHandler implements RALBackendHandler { +public final class UpdatableRALBackendHandler implements DistSQLBackendHandler { private final UpdatableRALStatement sqlStatement; diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java index 01a545505389a..ada833f2da536 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/rule/database/execute/type/CreateDatabaseRuleRDLExecuteEngine.java @@ -28,8 +28,6 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.distsql.rdl.rule.database.execute.DatabaseRuleRDLExecuteEngine; -import org.apache.shardingsphere.single.distsql.statement.rdl.LoadSingleTableStatement; -import org.apache.shardingsphere.single.distsql.statement.rdl.SetDefaultSingleTableStorageUnitStatement; import java.util.Collection; import java.util.LinkedHashMap; @@ -49,17 +47,12 @@ public final class CreateDatabaseRuleRDLExecuteEngine implements DatabaseRuleRDL @SuppressWarnings("unchecked") public Collection execute(final RuleDefinitionStatement sqlStatement, final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig) { RuleConfiguration toBeCreatedRuleConfig = executor.buildToBeCreatedRuleConfiguration(currentRuleConfig, sqlStatement); - executor.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig); ModeContextManager modeContextManager = ProxyContext.getInstance().getContextManager().getInstanceContext().getModeContextManager(); - return modeContextManager.alterRuleConfiguration(database.getName(), getToBeCreatedRuleConfiguration(sqlStatement, database, currentRuleConfig, toBeCreatedRuleConfig)); - } - - private RuleConfiguration getToBeCreatedRuleConfiguration(final RuleDefinitionStatement sqlStatement, - final ShardingSphereDatabase database, final RuleConfiguration currentRuleConfig, final RuleConfiguration toBeCreatedRuleConfig) { - if (sqlStatement instanceof LoadSingleTableStatement || sqlStatement instanceof SetDefaultSingleTableStorageUnitStatement) { - return null == currentRuleConfig ? decorateRuleConfiguration(database, toBeCreatedRuleConfig) : decorateRuleConfiguration(database, currentRuleConfig); + if (null == currentRuleConfig) { + return modeContextManager.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, toBeCreatedRuleConfig)); } - return toBeCreatedRuleConfig; + executor.updateCurrentRuleConfiguration(currentRuleConfig, toBeCreatedRuleConfig); + return modeContextManager.alterRuleConfiguration(database.getName(), decorateRuleConfiguration(database, currentRuleConfig)); } @SuppressWarnings("unchecked")