You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/02/18 03:44:51 UTC
[shardingsphere] branch master updated: [DistSQL] Refactor RAL's AlterStatementExecutor (#15466)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 b119565 [DistSQL] Refactor RAL's AlterStatementExecutor (#15466)
b119565 is described below
commit b11956560d632dc87d76326042ca843a435d2554
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Fri Feb 18 11:43:52 2022 +0800
[DistSQL] Refactor RAL's AlterStatementExecutor (#15466)
* Refactor RAL executor.
* Refactor RAL executor.
* Rename method.
---
.../text/distsql/ral/RALBackendHandler.java | 4 ++
.../text/distsql/ral/RALBackendHandlerFactory.java | 25 +++++++-
.../distsql/ral/UpdatableRALBackendHandler.java | 4 +-
.../common/CommonDistSQLBackendHandlerFactory.java | 13 -----
.../ral/common/SetDistSQLBackendHandler.java | 47 ---------------
.../ral/common/set/SetStatementExecutor.java | 35 ------------
.../common/set/SetStatementExecutorFactory.java | 66 ----------------------
.../updatable/AlterSQLParserRuleHandler.java | 2 +-
.../common/updatable/AlterTrafficRuleHandler.java | 4 +-
.../updatable/AlterTransactionRuleHandler.java | 2 +-
.../common/updatable/CreateTrafficRuleHandler.java | 4 +-
.../DropTrafficRuleHandler.java | 16 ++----
.../LabelInstanceHandler.java} | 19 ++-----
.../RefreshTableMetadataHandler.java | 43 ++++++++------
.../SetInstanceStatusHandler.java} | 19 ++-----
.../SetReadwriteSplittingStatusHandler.java} | 25 ++++----
.../SetVariableHandler.java} | 26 +++++----
.../UnlabelInstanceHandler.java} | 18 ++----
.../TextProtocolBackendHandlerFactoryTest.java | 4 +-
.../distsql/ral/SetVariableBackendHandlerTest.java | 38 +++++++------
.../common/drop/DropTrafficRuleHandlerTest.java | 27 ++++-----
.../set/SetStatementExecutorFactoryTest.java | 62 --------------------
.../set/executor/SetVariableExecutorTest.java | 23 +++++---
23 files changed, 163 insertions(+), 363 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandler.java
index ac8425c..dc8bc29 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandler.java
@@ -20,7 +20,9 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral;
import com.google.common.base.Preconditions;
import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
+import lombok.experimental.Accessors;
import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
@@ -73,7 +75,9 @@ public abstract class RALBackendHandler<E extends RALStatement, R extends RALBac
@Getter
@Setter
+ @Accessors(chain = true)
@AllArgsConstructor
+ @NoArgsConstructor
public static class HandlerParameter<E extends RALStatement> {
private E statement;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandlerFactory.java
index 8fc8e69..b40c821 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/RALBackendHandlerFactory.java
@@ -24,8 +24,14 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.CommonDistSQLState
import org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableRALStatement;
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.RefreshTableMetadataStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.alter.AlterSQLParserRuleStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.alter.AlterTransactionRuleStatement;
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.drop.DropTrafficRuleStatement;
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.LabelInstanceStatement;
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetInstanceStatusStatement;
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
+import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.UnlabelInstanceStatement;
import org.apache.shardingsphere.distsql.parser.statement.rdl.create.AlterTrafficRuleStatement;
import org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateTrafficRuleStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -38,8 +44,16 @@ import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.AlterTrafficRuleHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.AlterTransactionRuleHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.CreateTrafficRuleHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.DropTrafficRuleHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.LabelInstanceHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.RefreshTableMetadataHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.SetInstanceStatusHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.SetReadwriteSplittingStatusHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.SetVariableHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.UnlabelInstanceHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.query.QueryableScalingRALBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.update.UpdatableScalingRALBackendHandlerFactory;
+import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
import java.sql.SQLException;
import java.util.LinkedHashMap;
@@ -54,9 +68,16 @@ public final class RALBackendHandlerFactory {
private static Map<String, Class<? extends RALBackendHandler>> handlerMap = new LinkedHashMap<>();
static {
+ handlerMap.put(LabelInstanceStatement.class.getName(), LabelInstanceHandler.class);
+ handlerMap.put(UnlabelInstanceStatement.class.getName(), UnlabelInstanceHandler.class);
+ handlerMap.put(SetInstanceStatusStatement.class.getName(), SetInstanceStatusHandler.class);
+ handlerMap.put(SetVariableStatement.class.getName(), SetVariableHandler.class);
+ handlerMap.put(SetReadwriteSplittingStatusStatement.class.getName(), SetReadwriteSplittingStatusHandler.class);
+ handlerMap.put(RefreshTableMetadataStatement.class.getName(), RefreshTableMetadataHandler.class);
handlerMap.put(CreateTrafficRuleStatement.class.getName(), CreateTrafficRuleHandler.class);
- handlerMap.put(AlterSQLParserRuleStatement.class.getName(), AlterSQLParserRuleHandler.class);
handlerMap.put(AlterTrafficRuleStatement.class.getName(), AlterTrafficRuleHandler.class);
+ handlerMap.put(DropTrafficRuleStatement.class.getName(), DropTrafficRuleHandler.class);
+ handlerMap.put(AlterSQLParserRuleStatement.class.getName(), AlterSQLParserRuleHandler.class);
handlerMap.put(AlterTransactionRuleStatement.class.getName(), AlterTransactionRuleHandler.class);
}
@@ -101,7 +122,7 @@ public final class RALBackendHandlerFactory {
private static RALBackendHandler getHandler(final RALStatement sqlStatement, final HandlerParameter<RALStatement> parameter) {
Class<? extends RALBackendHandler> clazz = handlerMap.get(sqlStatement.getClass().getName());
if (null == clazz) {
- throw new UnsupportedOperationException(sqlStatement.getClass().getCanonicalName());
+ throw new UnsupportedOperationException(String.format("Unsupported statement : %s", sqlStatement.getClass().getCanonicalName()));
}
return newInstance(clazz).init(parameter);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/UpdatableRALBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/UpdatableRALBackendHandler.java
index e862f2b..a302748 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/UpdatableRALBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/UpdatableRALBackendHandler.java
@@ -30,9 +30,9 @@ public abstract class UpdatableRALBackendHandler<E extends RALStatement, R exten
@Override
protected final ResponseHeader handle(final ContextManager contextManager, final E sqlStatement) throws DistSQLException {
- doHandle(contextManager, sqlStatement);
+ update(contextManager, sqlStatement);
return new UpdateResponseHeader(sqlStatement);
}
- protected abstract void doHandle(ContextManager contextManager, E sqlStatement) throws DistSQLException;
+ protected abstract void update(ContextManager contextManager, E sqlStatement) throws DistSQLException;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/CommonDistSQLBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/CommonDistSQLBackendHandlerFactory.java
index 2e729b6..d8f5588 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/CommonDistSQLBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/CommonDistSQLBackendHandlerFactory.java
@@ -21,13 +21,9 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.CommonDistSQLStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.HintDistSQLStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.RefreshTableMetadataStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.ShowDistSQLStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.drop.DropTrafficRuleStatement;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.drop.DropTrafficRuleHandler;
import java.sql.SQLException;
@@ -46,21 +42,12 @@ public final class CommonDistSQLBackendHandlerFactory {
* @throws SQLException SQL exception
*/
public static TextProtocolBackendHandler newInstance(final CommonDistSQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
- if (sqlStatement instanceof SetDistSQLStatement) {
- return new SetDistSQLBackendHandler((SetDistSQLStatement) sqlStatement, connectionSession);
- }
if (sqlStatement instanceof ShowDistSQLStatement) {
return new ShowDistSQLBackendHandler((ShowDistSQLStatement) sqlStatement, connectionSession);
}
if (sqlStatement instanceof HintDistSQLStatement) {
return new HintDistSQLBackendHandler((HintDistSQLStatement) sqlStatement, connectionSession);
}
- if (sqlStatement instanceof RefreshTableMetadataStatement) {
- return new RefreshTableMetadataHandler((RefreshTableMetadataStatement) sqlStatement, connectionSession);
- }
- if (sqlStatement instanceof DropTrafficRuleStatement) {
- return new DropTrafficRuleHandler((DropTrafficRuleStatement) sqlStatement);
- }
return null;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/SetDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/SetDistSQLBackendHandler.java
deleted file mode 100644
index 02a9684..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/SetDistSQLBackendHandler.java
+++ /dev/null
@@ -1,47 +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.text.distsql.ral.common;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.SetStatementExecutor;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.SetStatementExecutorFactory;
-
-import java.sql.SQLException;
-
-/**
- * Set dist sql backend handler.
- */
-@RequiredArgsConstructor
-@Getter
-public final class SetDistSQLBackendHandler implements TextProtocolBackendHandler {
-
- private final SetDistSQLStatement sqlStatement;
-
- private final ConnectionSession connectionSession;
-
- @Override
- public ResponseHeader execute() throws SQLException {
- SetStatementExecutor setStatementExecutor = SetStatementExecutorFactory.newInstance(sqlStatement, connectionSession);
- return setStatementExecutor.execute();
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutor.java
deleted file mode 100644
index 7ddf996..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutor.java
+++ /dev/null
@@ -1,35 +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.text.distsql.ral.common.set;
-
-import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-
-/**
- * Set statement executor.
- */
-public interface SetStatementExecutor {
-
- /**
- * Execute set statement.
- *
- * @return backend response
- * @throws DistSQLException DistSQL exception
- */
- ResponseHeader execute() throws DistSQLException;
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactory.java
deleted file mode 100644
index f49a6a6..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactory.java
+++ /dev/null
@@ -1,66 +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.text.distsql.ral.common.set;
-
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.LabelInstanceStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetInstanceStatusStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.UnlabelInstanceStatement;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.LabelInstanceExecutor;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetInstanceStatusExecutor;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetReadwriteSplittingStatusExecutor;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetVariableExecutor;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.UnlabelInstanceExecutor;
-import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
-
-import java.sql.SQLException;
-
-/**
- * Set statement executor factory.
- */
-public final class SetStatementExecutorFactory {
-
- /**
- * Create set statement executor instance.
- *
- * @param sqlStatement set statement
- * @param connectionSession connection session
- * @return set command executor
- * @throws SQLException SQL exception
- */
- public static SetStatementExecutor newInstance(final SetDistSQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
- if (sqlStatement instanceof SetVariableStatement) {
- return new SetVariableExecutor((SetVariableStatement) sqlStatement, connectionSession);
- }
- if (sqlStatement instanceof SetReadwriteSplittingStatusStatement) {
- return new SetReadwriteSplittingStatusExecutor((SetReadwriteSplittingStatusStatement) sqlStatement, connectionSession);
- }
- if (sqlStatement instanceof SetInstanceStatusStatement) {
- return new SetInstanceStatusExecutor((SetInstanceStatusStatement) sqlStatement);
- }
- if (sqlStatement instanceof LabelInstanceStatement) {
- return new LabelInstanceExecutor((LabelInstanceStatement) sqlStatement);
- }
- if (sqlStatement instanceof UnlabelInstanceStatement) {
- return new UnlabelInstanceExecutor((UnlabelInstanceStatement) sqlStatement);
- }
- throw new UnsupportedOperationException(sqlStatement.getClass().getCanonicalName());
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java
index acf7aa0..b15a64e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterSQLParserRuleHandler.java
@@ -38,7 +38,7 @@ import java.util.Optional;
public final class AlterSQLParserRuleHandler extends UpdatableRALBackendHandler<AlterSQLParserRuleStatement, AlterSQLParserRuleHandler> {
@Override
- protected void doHandle(final ContextManager contextManager, final AlterSQLParserRuleStatement sqlStatement) {
+ protected void update(final ContextManager contextManager, final AlterSQLParserRuleStatement sqlStatement) {
updateSQLParserRule();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java
index c4ed985..f4d54df 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTrafficRuleHandler.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.parser.segment.TrafficRuleSegment;
import org.apache.shardingsphere.distsql.parser.statement.rdl.create.AlterTrafficRuleStatement;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
@@ -45,11 +44,10 @@ import java.util.stream.Collectors;
/**
* Alter traffic rule handler.
*/
-@RequiredArgsConstructor
public final class AlterTrafficRuleHandler extends UpdatableRALBackendHandler<AlterTrafficRuleStatement, AlterTrafficRuleHandler> {
@Override
- protected void doHandle(final ContextManager contextManager, final AlterTrafficRuleStatement sqlStatement) throws DistSQLException {
+ protected void update(final ContextManager contextManager, final AlterTrafficRuleStatement sqlStatement) throws DistSQLException {
Optional<TrafficRuleConfiguration> currentConfiguration = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData()
.findRuleConfiguration(TrafficRuleConfiguration.class).stream().findAny();
check(sqlStatement, currentConfiguration);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java
index 0397a71..d51ba8b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/AlterTransactionRuleHandler.java
@@ -36,7 +36,7 @@ import java.util.Optional;
public final class AlterTransactionRuleHandler extends UpdatableRALBackendHandler<AlterTransactionRuleStatement, AlterTrafficRuleHandler> {
@Override
- protected void doHandle(final ContextManager contextManager, final AlterTransactionRuleStatement sqlStatement) {
+ protected void update(final ContextManager contextManager, final AlterTransactionRuleStatement sqlStatement) {
updateTransactionRule();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java
index 0bdbae7..9ad8d00 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/CreateTrafficRuleHandler.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.parser.segment.TrafficRuleSegment;
import org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateTrafficRuleStatement;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -46,11 +45,10 @@ import java.util.stream.Collectors;
/**
* Create traffic rule handler.
*/
-@RequiredArgsConstructor
public final class CreateTrafficRuleHandler extends UpdatableRALBackendHandler<CreateTrafficRuleStatement, CreateTrafficRuleHandler> {
@Override
- protected void doHandle(final ContextManager contextManager, final CreateTrafficRuleStatement sqlStatement) throws DistSQLException {
+ protected void update(final ContextManager contextManager, final CreateTrafficRuleStatement sqlStatement) throws DistSQLException {
Optional<TrafficRuleConfiguration> trafficRuleConfiguration = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData()
.findRuleConfiguration(TrafficRuleConfiguration.class).stream().findAny();
check(sqlStatement, trafficRuleConfiguration);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/drop/DropTrafficRuleHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandler.java
similarity index 88%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/drop/DropTrafficRuleHandler.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandler.java
index b883ae7..50b4050 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/drop/DropTrafficRuleHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/DropTrafficRuleHandler.java
@@ -15,18 +15,16 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.drop;
+package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.drop.DropTrafficRuleStatement;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-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.text.TextProtocolBackendHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.UpdatableRALBackendHandler;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration;
@@ -38,13 +36,10 @@ import java.util.stream.Collectors;
/**
* Drop traffic rule statement handler.
*/
-@RequiredArgsConstructor
-public final class DropTrafficRuleHandler implements TextProtocolBackendHandler {
-
- private final DropTrafficRuleStatement sqlStatement;
+public final class DropTrafficRuleHandler extends UpdatableRALBackendHandler<DropTrafficRuleStatement, DropTrafficRuleHandler> {
@Override
- public ResponseHeader execute() throws DistSQLException {
+ protected void update(final ContextManager contextManager, final DropTrafficRuleStatement sqlStatement) throws DistSQLException {
Optional<TrafficRuleConfiguration> configuration = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getGlobalRuleMetaData()
.findRuleConfiguration(TrafficRuleConfiguration.class).stream().findAny();
check(sqlStatement, configuration);
@@ -54,7 +49,6 @@ public final class DropTrafficRuleHandler implements TextProtocolBackendHandler
getUnusedLoadBalancer(configuration.get()).forEach(each -> configuration.get().getLoadBalancers().remove(each));
updateToRepository(configuration.get());
}
- return new UpdateResponseHeader(sqlStatement);
}
private void check(final DropTrafficRuleStatement sqlStatement, final Optional<TrafficRuleConfiguration> configuration) throws DistSQLException {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/LabelInstanceExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java
similarity index 80%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/LabelInstanceExecutor.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java
index 6035c4b..aa96248 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/LabelInstanceExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java
@@ -15,35 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor;
+package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.AllArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.LabelInstanceStatement;
-import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceId;
import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-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.text.distsql.ral.common.set.SetStatementExecutor;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.UpdatableRALBackendHandler;
import java.util.Collection;
import java.util.LinkedHashSet;
/**
- * Label instance executor.
+ * Label instance handler.
*/
-@AllArgsConstructor
-public final class LabelInstanceExecutor implements SetStatementExecutor {
-
- private final LabelInstanceStatement sqlStatement;
+public final class LabelInstanceHandler extends UpdatableRALBackendHandler<LabelInstanceStatement, LabelInstanceHandler> {
@Override
- public ResponseHeader execute() throws DistSQLException {
+ public void update(final ContextManager contextManager, final LabelInstanceStatement sqlStatement) {
MetaDataPersistService persistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService().orElse(null);
if (null == persistService || null == persistService.getRepository() || persistService.getRepository() instanceof StandalonePersistRepository) {
throw new UnsupportedOperationException("Labels can only be added in cluster mode");
@@ -55,6 +49,5 @@ public final class LabelInstanceExecutor implements SetStatementExecutor {
labels.addAll(instances.getLabels());
}
persistService.getComputeNodePersistService().persistInstanceLabels(instanceId, labels, true);
- return new UpdateResponseHeader(sqlStatement);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/RefreshTableMetadataHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/RefreshTableMetadataHandler.java
similarity index 54%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/RefreshTableMetadataHandler.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/RefreshTableMetadataHandler.java
index a8e1f3e..2580bcd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/RefreshTableMetadataHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/RefreshTableMetadataHandler.java
@@ -15,41 +15,52 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common;
+package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.Getter;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.RefreshTableMetadataStatement;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-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.exception.NoDatabaseSelectedException;
+import org.apache.shardingsphere.proxy.backend.exception.UnknownDatabaseException;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
-
-import java.sql.SQLException;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.UpdatableRALBackendHandler;
/**
* Refresh table metadata handler.
*/
-@Getter
-public final class RefreshTableMetadataHandler extends SchemaRequiredBackendHandler<RefreshTableMetadataStatement> {
+public final class RefreshTableMetadataHandler extends UpdatableRALBackendHandler<RefreshTableMetadataStatement, RefreshTableMetadataHandler> {
+
+ private ConnectionSession connectionSession;
- public RefreshTableMetadataHandler(final RefreshTableMetadataStatement sqlStatement, final ConnectionSession connectionSession) {
- super(sqlStatement, connectionSession);
+ @Override
+ public RefreshTableMetadataHandler init(final HandlerParameter<RefreshTableMetadataStatement> parameter) {
+ sqlStatement = parameter.getStatement();
+ connectionSession = parameter.getConnectionSession();
+ return this;
}
@Override
- protected ResponseHeader execute(final String schemaName, final RefreshTableMetadataStatement sqlStatement) throws SQLException {
- ContextManager contextManager = ProxyContext.getInstance().getContextManager();
+ protected void update(final ContextManager contextManager, final RefreshTableMetadataStatement sqlStatement) throws DistSQLException {
+ String schemaName = connectionSession.getSchemaName();
+ checkSchema(schemaName);
if (sqlStatement.getResourceName().isPresent()) {
contextManager.reloadMetaData(schemaName, sqlStatement.getTableName().get(), sqlStatement.getResourceName().get());
- return new UpdateResponseHeader(sqlStatement);
+ return;
}
if (sqlStatement.getTableName().isPresent()) {
contextManager.reloadMetaData(schemaName, sqlStatement.getTableName().get());
- return new UpdateResponseHeader(sqlStatement);
+ return;
}
contextManager.reloadMetaData(schemaName);
- return new UpdateResponseHeader(sqlStatement);
+ }
+
+ private void checkSchema(final String schemaName) {
+ if (null == schemaName) {
+ throw new NoDatabaseSelectedException();
+ }
+ if (!ProxyContext.getInstance().schemaExists(schemaName)) {
+ throw new UnknownDatabaseException(schemaName);
+ }
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetInstanceStatusExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetInstanceStatusHandler.java
similarity index 88%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetInstanceStatusExecutor.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetInstanceStatusHandler.java
index a0107e4..a3a0588 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetInstanceStatusExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetInstanceStatusHandler.java
@@ -15,38 +15,32 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor;
+package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.AllArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetInstanceStatusStatement;
-import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceId;
import org.apache.shardingsphere.infra.state.StateType;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.ComputeNodeStatus;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.ComputeNodeStatusChangedEvent;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-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.text.distsql.ral.common.set.SetStatementExecutor;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.UpdatableRALBackendHandler;
import java.util.Collection;
import java.util.Optional;
/**
- * Set instance status executor.
+ * Set instance status handler.
*/
-@AllArgsConstructor
-public final class SetInstanceStatusExecutor implements SetStatementExecutor {
-
- private final SetInstanceStatusStatement sqlStatement;
+public final class SetInstanceStatusHandler extends UpdatableRALBackendHandler<SetInstanceStatusStatement, SetInstanceStatusHandler> {
@Override
- public ResponseHeader execute() throws DistSQLException {
+ protected void update(final ContextManager contextManager, final SetInstanceStatusStatement sqlStatement) {
InstanceId operationInstanceId = new InstanceId(sqlStatement.getIp(), Integer.valueOf(sqlStatement.getPort()));
boolean isDisable = "DISABLE".equals(sqlStatement.getStatus());
if (isDisable) {
@@ -56,7 +50,6 @@ public final class SetInstanceStatusExecutor implements SetStatementExecutor {
}
ShardingSphereEventBus.getInstance().post(new ComputeNodeStatusChangedEvent(isDisable ? ComputeNodeStatus.CIRCUIT_BREAK : ComputeNodeStatus.ONLINE,
sqlStatement.getIp(), sqlStatement.getPort()));
- return new UpdateResponseHeader(sqlStatement);
}
private void checkEnablingIsValid(final InstanceId operationInstanceId) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetReadwriteSplittingStatusExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetReadwriteSplittingStatusHandler.java
similarity index 92%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetReadwriteSplittingStatusExecutor.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetReadwriteSplittingStatusHandler.java
index e9cbc89..76b0bcf 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetReadwriteSplittingStatusExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetReadwriteSplittingStatusHandler.java
@@ -15,24 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor;
+package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.AllArgsConstructor;
import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException;
import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.StorageNodeStatus;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node.StorageStatusNode;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
-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;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.SetStatementExecutor;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.UpdatableRALBackendHandler;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
@@ -49,19 +47,23 @@ import java.util.Set;
import java.util.stream.Collectors;
/**
- * Set readwrite-splitting status executor.
+ * Set readwrite-splitting status handler.
*/
-@AllArgsConstructor
-public final class SetReadwriteSplittingStatusExecutor implements SetStatementExecutor {
+public final class SetReadwriteSplittingStatusHandler extends UpdatableRALBackendHandler<SetReadwriteSplittingStatusStatement, SetReadwriteSplittingStatusHandler> {
private static final String DISABLE = "DISABLE";
- private final SetReadwriteSplittingStatusStatement sqlStatement;
+ private ConnectionSession connectionSession;
- private final ConnectionSession connectionSession;
+ @Override
+ public SetReadwriteSplittingStatusHandler init(final HandlerParameter<SetReadwriteSplittingStatusStatement> parameter) {
+ initStatement(parameter.getStatement());
+ connectionSession = parameter.getConnectionSession();
+ return this;
+ }
@Override
- public ResponseHeader execute() throws DistSQLException {
+ protected void update(final ContextManager contextManager, final SetReadwriteSplittingStatusStatement sqlStatement) throws DistSQLException {
String schemaName = sqlStatement.getSchema().isPresent() ? sqlStatement.getSchema().get().getIdentifier().getValue() : connectionSession.getSchemaName();
String resourceName = sqlStatement.getResourceName();
checkSchema(schemaName);
@@ -72,7 +74,6 @@ public final class SetReadwriteSplittingStatusExecutor implements SetStatementEx
checkEnablingIsValid(schemaName, resourceName);
}
ShardingSphereEventBus.getInstance().post(new DataSourceDisabledEvent(schemaName, resourceName, isDisable));
- return new UpdateResponseHeader(sqlStatement);
}
private void checkSchema(final String schemaName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetVariableExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetVariableHandler.java
similarity index 86%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetVariableExecutor.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetVariableHandler.java
index 287eb9f..8903ca9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/SetVariableExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetVariableHandler.java
@@ -15,24 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor;
+package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.properties.TypedPropertyValue;
import org.apache.shardingsphere.infra.properties.TypedPropertyValueException;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-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;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.UpdatableRALBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.InvalidValueException;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.SetStatementExecutor;
import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -40,17 +39,21 @@ import java.util.Optional;
import java.util.Properties;
/**
- * Set variable statement executor.
+ * Set variable statement handler.
*/
-@RequiredArgsConstructor
-public final class SetVariableExecutor implements SetStatementExecutor {
+public final class SetVariableHandler extends UpdatableRALBackendHandler<SetVariableStatement, SetVariableHandler> {
- private final SetVariableStatement sqlStatement;
+ private ConnectionSession connectionSession;
- private final ConnectionSession connectionSession;
+ @Override
+ public SetVariableHandler init(final HandlerParameter<SetVariableStatement> parameter) {
+ initStatement(parameter.getStatement());
+ connectionSession = parameter.getConnectionSession();
+ return this;
+ }
@Override
- public ResponseHeader execute() {
+ protected void update(final ContextManager contextManager, final SetVariableStatement sqlStatement) throws DistSQLException {
Enum<?> enumType = getEnumType(sqlStatement.getName());
if (enumType instanceof ConfigurationPropertyKey) {
handleConfigurationProperty((ConfigurationPropertyKey) enumType, sqlStatement.getValue());
@@ -59,7 +62,6 @@ public final class SetVariableExecutor implements SetStatementExecutor {
} else {
throw new UnsupportedVariableException(sqlStatement.getName());
}
- return new UpdateResponseHeader(sqlStatement);
}
private Enum<?> getEnumType(final String name) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/UnlabelInstanceExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/UnlabelInstanceHandler.java
similarity index 83%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/UnlabelInstanceExecutor.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/UnlabelInstanceHandler.java
index 2ed0a96..6ec4201 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/excutor/UnlabelInstanceExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/UnlabelInstanceHandler.java
@@ -15,35 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor;
+package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
-import lombok.AllArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.UnlabelInstanceStatement;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceId;
import org.apache.shardingsphere.infra.instance.definition.InstanceType;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-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.text.distsql.ral.common.set.SetStatementExecutor;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.UpdatableRALBackendHandler;
import java.util.Collection;
import java.util.LinkedHashSet;
/**
- * Unlabel instance executor.
+ * Unlabel instance handler.
*/
-@AllArgsConstructor
-public final class UnlabelInstanceExecutor implements SetStatementExecutor {
-
- private final UnlabelInstanceStatement sqlStatement;
+public final class UnlabelInstanceHandler extends UpdatableRALBackendHandler<UnlabelInstanceStatement, UnlabelInstanceHandler> {
@Override
- public ResponseHeader execute() throws DistSQLException {
+ protected void update(final ContextManager contextManager, final UnlabelInstanceStatement sqlStatement) throws DistSQLException {
MetaDataPersistService persistService = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService().orElse(null);
if (null == persistService || null == persistService.getRepository() || persistService.getRepository() instanceof StandalonePersistRepository) {
throw new UnsupportedOperationException("Labels can only be removed in cluster mode");
@@ -57,6 +52,5 @@ public final class UnlabelInstanceExecutor implements SetStatementExecutor {
labels.removeAll(sqlStatement.getLabels());
persistService.getComputeNodePersistService().persistInstanceLabels(instanceId, labels, true);
}
- return new UpdateResponseHeader(sqlStatement);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
index 87d1079..eb2c5ab 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactoryTest.java
@@ -35,8 +35,8 @@ import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseB
import org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.UnicastDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.HintDistSQLBackendHandler;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.SetDistSQLBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.ShowDistSQLBackendHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.SetVariableHandler;
import org.apache.shardingsphere.proxy.backend.text.skip.SkipBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.transaction.TransactionAutoCommitHandler;
import org.apache.shardingsphere.proxy.backend.text.transaction.TransactionBackendHandler;
@@ -118,7 +118,7 @@ public final class TextProtocolBackendHandlerFactoryTest {
public void assertNewInstanceWithCommonDistSQL() throws SQLException {
String sql = "set variable transaction_type=LOCAL";
TextProtocolBackendHandler actual = TextProtocolBackendHandlerFactory.newInstance(databaseType, sql, Optional::empty, connectionSession);
- assertThat(actual, instanceOf(SetDistSQLBackendHandler.class));
+ assertThat(actual, instanceOf(SetVariableHandler.class));
sql = "show variable transaction_type";
actual = TextProtocolBackendHandlerFactory.newInstance(databaseType, sql, Optional::empty, connectionSession);
assertThat(actual, instanceOf(ShowDistSQLBackendHandler.class));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java
index eca5f83..0980f08 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/SetVariableBackendHandlerTest.java
@@ -35,9 +35,10 @@ import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
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;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.SetDistSQLBackendHandler;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.RALBackendHandler.HandlerParameter;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.SetVariableHandler;
import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.After;
@@ -94,8 +95,8 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeXA() throws SQLException {
connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "XA"), connectionSession);
- ResponseHeader actual = setDistSQLBackendHandler.execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "XA"), connectionSession));
+ ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(connectionSession.getTransactionStatus().getTransactionType(), is(TransactionType.XA));
}
@@ -103,8 +104,8 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeBASE() throws SQLException {
connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "BASE"), connectionSession);
- ResponseHeader actual = setDistSQLBackendHandler.execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "BASE"), connectionSession));
+ ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(connectionSession.getTransactionStatus().getTransactionType(), is(TransactionType.BASE));
}
@@ -112,8 +113,8 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSwitchTransactionTypeLOCAL() throws SQLException {
connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "LOCAL"), connectionSession);
- ResponseHeader actual = setDistSQLBackendHandler.execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "LOCAL"), connectionSession));
+ ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(connectionSession.getTransactionStatus().getTransactionType(), is(TransactionType.LOCAL));
}
@@ -121,20 +122,21 @@ public final class SetVariableBackendHandlerTest {
@Test(expected = UnsupportedVariableException.class)
public void assertSwitchTransactionTypeFailed() throws SQLException {
connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- new SetDistSQLBackendHandler(new SetVariableStatement("transaction_type", "XXX"), connectionSession).execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("transaction_type", "XXX"), connectionSession));
+ handler.execute();
}
@Test(expected = UnsupportedVariableException.class)
public void assertNotSupportedVariable() throws SQLException {
- new SetDistSQLBackendHandler(new SetVariableStatement("@@session", "XXX"), connectionSession).execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement("@@session", "XXX"), connectionSession));
+ handler.execute();
}
@Test
public void assertSetAgentPluginsEnabledTrue() throws SQLException {
connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.TRUE.toString()),
- connectionSession);
- ResponseHeader actual = setDistSQLBackendHandler.execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.TRUE.toString()), null));
+ ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.FALSE.toString()), is(Boolean.TRUE.toString()));
}
@@ -142,8 +144,8 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSetAgentPluginsEnabledFalse() throws SQLException {
connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "FALSE"), connectionSession);
- ResponseHeader actual = setDistSQLBackendHandler.execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "FALSE"), null));
+ ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.FALSE.toString()), is(Boolean.FALSE.toString()));
}
@@ -151,12 +153,16 @@ public final class SetVariableBackendHandlerTest {
@Test
public void assertSetAgentPluginsEnabledFalseWithUnknownValue() throws SQLException {
connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
- SetDistSQLBackendHandler setDistSQLBackendHandler = new SetDistSQLBackendHandler(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "xxx"), connectionSession);
- ResponseHeader actual = setDistSQLBackendHandler.execute();
+ SetVariableHandler handler = new SetVariableHandler().init(getParameter(new SetVariableStatement(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "xxx"), connectionSession));
+ ResponseHeader actual = handler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
assertThat(SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.FALSE.toString()), is(Boolean.FALSE.toString()));
}
+ private HandlerParameter<SetVariableStatement> getParameter(final SetVariableStatement statement, final ConnectionSession connectionSession) {
+ return new HandlerParameter<SetVariableStatement>().setStatement(statement).setConnectionSession(connectionSession);
+ }
+
@After
public void tearDown() {
ProxyContext.getInstance().init(contextManagerBefore);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/drop/DropTrafficRuleHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/drop/DropTrafficRuleHandlerTest.java
index 6f809b1..0da197f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/drop/DropTrafficRuleHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/drop/DropTrafficRuleHandlerTest.java
@@ -20,14 +20,15 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.drop;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.drop.DropTrafficRuleStatement;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.DropTrafficRuleHandler;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
import org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration;
import org.junit.Test;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -48,35 +49,35 @@ import static org.mockito.Mockito.when;
public class DropTrafficRuleHandlerTest {
@Test(expected = RequiredRuleMissedException.class)
- public void assertExecuteWithEmptyRuleConfigurationAndNotExistRule() throws DistSQLException {
+ public void assertExecuteWithEmptyRuleConfigurationAndNotExistRule() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(any())).thenReturn(new LinkedList<>());
ProxyContext.getInstance().init(contextManager);
- new DropTrafficRuleHandler(getSQLStatement(Collections.singletonList("rule_name"), false)).execute();
+ new DropTrafficRuleHandler().initStatement(getSQLStatement(Collections.singletonList("rule_name"), false)).execute();
}
@Test
- public void assertExecuteWithEmptyRuleConfigurationAndNotExistRuleAndIfExists() throws DistSQLException {
+ public void assertExecuteWithEmptyRuleConfigurationAndNotExistRuleAndIfExists() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(any())).thenReturn(new LinkedList<>());
ProxyContext.getInstance().init(contextManager);
- new DropTrafficRuleHandler(getSQLStatement(Collections.singletonList("rule_name"), true)).execute();
+ new DropTrafficRuleHandler().initStatement(getSQLStatement(Collections.singletonList("rule_name"), true)).execute();
}
@Test(expected = RequiredRuleMissedException.class)
- public void assertExecuteWithNotExistRule() throws DistSQLException {
+ public void assertExecuteWithNotExistRule() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(any())).thenReturn(createTrafficRule());
ProxyContext.getInstance().init(contextManager);
- new DropTrafficRuleHandler(getSQLStatement(Collections.singletonList("rule_name"), false)).execute();
+ new DropTrafficRuleHandler().initStatement(getSQLStatement(Collections.singletonList("rule_name"), false)).execute();
}
@Test
- public void assertExecute() throws DistSQLException {
+ public void assertExecute() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(any())).thenReturn(createTrafficRule());
ProxyContext.getInstance().init(contextManager);
- new DropTrafficRuleHandler(getSQLStatement(Collections.singletonList("rule_name_1"), false)).execute();
+ new DropTrafficRuleHandler().initStatement(getSQLStatement(Collections.singletonList("rule_name_1"), false)).execute();
Optional<TrafficRuleConfiguration> ruleConfiguration = contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(TrafficRuleConfiguration.class).stream().findAny();
assertTrue(ruleConfiguration.isPresent());
TrafficRuleConfiguration configuration = ruleConfiguration.get();
@@ -89,11 +90,11 @@ public class DropTrafficRuleHandlerTest {
}
@Test
- public void assertExecuteWithIfExists() throws DistSQLException {
+ public void assertExecuteWithIfExists() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(any())).thenReturn(createTrafficRule());
ProxyContext.getInstance().init(contextManager);
- new DropTrafficRuleHandler(getSQLStatement(Collections.singletonList("rule_name_1"), false)).execute();
+ new DropTrafficRuleHandler().initStatement(getSQLStatement(Collections.singletonList("rule_name_1"), false)).execute();
Optional<TrafficRuleConfiguration> ruleConfiguration = contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(TrafficRuleConfiguration.class).stream().findAny();
assertTrue(ruleConfiguration.isPresent());
TrafficRuleConfiguration configuration = ruleConfiguration.get();
@@ -106,11 +107,11 @@ public class DropTrafficRuleHandlerTest {
}
@Test
- public void assertExecuteWithNotExistRuleAndIfExists() throws DistSQLException {
+ public void assertExecuteWithNotExistRuleAndIfExists() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(any())).thenReturn(createTrafficRule());
ProxyContext.getInstance().init(contextManager);
- new DropTrafficRuleHandler(getSQLStatement(Collections.singletonList("rule_name_3"), true)).execute();
+ new DropTrafficRuleHandler().initStatement(getSQLStatement(Collections.singletonList("rule_name_3"), true)).execute();
Optional<TrafficRuleConfiguration> ruleConfiguration = contextManager.getMetaDataContexts().getGlobalRuleMetaData().findRuleConfiguration(TrafficRuleConfiguration.class).stream().findAny();
assertTrue(ruleConfiguration.isPresent());
TrafficRuleConfiguration configuration = ruleConfiguration.get();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactoryTest.java
deleted file mode 100644
index 0d10947..0000000
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/SetStatementExecutorFactoryTest.java
+++ /dev/null
@@ -1,62 +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.text.distsql.ral.common.set;
-
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetInstanceStatusStatement;
-import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetInstanceStatusExecutor;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetReadwriteSplittingStatusExecutor;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetVariableExecutor;
-import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.sql.SQLException;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class SetStatementExecutorFactoryTest {
-
- @Mock
- private ConnectionSession connectionSession;
-
- @Test
- public void assertSetVariableExecutor() throws SQLException {
- SetDistSQLStatement sqlStatement = mock(SetVariableStatement.class);
- assertThat(SetStatementExecutorFactory.newInstance(sqlStatement, connectionSession), instanceOf(SetVariableExecutor.class));
- }
-
- @Test
- public void assertSetReadwriteSplittingStatusExecutor() throws SQLException {
- SetDistSQLStatement sqlStatement = mock(SetReadwriteSplittingStatusStatement.class);
- assertThat(SetStatementExecutorFactory.newInstance(sqlStatement, connectionSession), instanceOf(SetReadwriteSplittingStatusExecutor.class));
- }
-
- @Test
- public void assertSetInstanceStatusExecutor() throws SQLException {
- SetDistSQLStatement sqlStatement = mock(SetInstanceStatusStatement.class);
- assertThat(SetStatementExecutorFactory.newInstance(sqlStatement, connectionSession), instanceOf(SetInstanceStatusExecutor.class));
- }
-}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/executor/SetVariableExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/executor/SetVariableExecutorTest.java
index 427ea5e..e335651 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/executor/SetVariableExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/set/executor/SetVariableExecutorTest.java
@@ -20,11 +20,12 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.exec
import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.RALBackendHandler.HandlerParameter;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
-import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.set.excutor.SetVariableExecutor;
+import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable.SetVariableHandler;
import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Test;
@@ -32,6 +33,8 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import java.sql.SQLException;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@@ -46,31 +49,35 @@ public final class SetVariableExecutorTest {
private ConnectionSession connectionSession;
@Test
- public void assertExecuteWithTransactionType() {
+ public void assertExecuteWithTransactionType() throws SQLException {
SetVariableStatement statement = new SetVariableStatement("transaction_type", "local");
when(connectionSession.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.XA));
- new SetVariableExecutor(statement, connectionSession).execute();
+ new SetVariableHandler().init(getParameter(statement, connectionSession)).execute();
assertThat(connectionSession.getTransactionStatus().getTransactionType().name(), is(TransactionType.LOCAL.name()));
}
@Test
- public void assertExecuteWithAgent() {
+ public void assertExecuteWithAgent() throws SQLException {
SetVariableStatement statement = new SetVariableStatement("AGENT_PLUGINS_ENABLED", "false");
- new SetVariableExecutor(statement, connectionSession).execute();
+ new SetVariableHandler().init(getParameter(statement, connectionSession)).execute();
String actualValue = SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "default");
assertThat(actualValue, is("false"));
}
@Test
- public void assertExecuteWithConfigurationKey() {
+ public void assertExecuteWithConfigurationKey() throws SQLException {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
MetaDataContexts metaDataContexts = new MetaDataContexts(null);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
SetVariableStatement statement = new SetVariableStatement("proxy_frontend_flush_threshold", "1024");
- new SetVariableExecutor(statement, connectionSession).execute();
+ new SetVariableHandler().init(getParameter(statement, connectionSession)).execute();
Object actualValue = contextManager.getMetaDataContexts().getProps().getProps().get("proxy-frontend-flush-threshold");
assertNotNull(actualValue);
assertThat(actualValue.toString(), is("1024"));
}
+
+ private HandlerParameter<SetVariableStatement> getParameter(final SetVariableStatement statement, final ConnectionSession connectionSession) {
+ return new HandlerParameter<SetVariableStatement>().setStatement(statement).setConnectionSession(connectionSession);
+ }
}