You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/12/07 12:04:13 UTC
[shardingsphere] branch master updated: Decoupling JDBCBackendConnection from ConnectionSession (#13975)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 baa9eda Decoupling JDBCBackendConnection from ConnectionSession (#13975)
baa9eda is described below
commit baa9edafeaee8b8862af653121be0ca58f232b39
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Tue Dec 7 20:03:17 2021 +0800
Decoupling JDBCBackendConnection from ConnectionSession (#13975)
---
.../jaeger/advice/CommandExecutorTaskAdvice.java | 5 +-
.../advice/CommandExecutorTaskAdviceTest.java | 3 +-
.../AbstractCommandExecutorTaskAdviceTest.java | 8 +-
.../zipkin/advice/CommandExecutorTaskAdvice.java | 5 +-
.../backend/communication/BackendConnection.java | 55 ++++++++
.../communication/DatabaseCommunicationEngine.java | 8 +-
.../DatabaseCommunicationEngineFactory.java | 22 +--
.../backend/communication/ProxySQLExecutor.java | 44 +++---
...tionSession.java => JDBCBackendConnection.java} | 70 ++++++++--
.../transaction/BackendTransactionManager.java | 32 ++---
.../jdbc/transaction/LocalTransactionManager.java | 14 +-
.../exception/BackendConnectionException.java} | 26 ++--
.../proxy/backend/session/ConnectionSession.java | 8 +-
.../transaction/TransactionStatus.java | 2 +-
.../text/TextProtocolBackendHandlerFactory.java | 7 +-
.../admin/DatabaseAdminBackendHandlerFactory.java | 8 +-
.../text/data/DatabaseBackendHandlerFactory.java | 4 +-
.../data/impl/BroadcastDatabaseBackendHandler.java | 7 +-
.../impl/SchemaAssignedDatabaseBackendHandler.java | 7 +-
.../data/impl/UnicastDatabaseBackendHandler.java | 7 +-
.../DatabaseOperateBackendHandlerFactory.java | 6 +-
.../text/distsql/DistSQLBackendHandlerFactory.java | 4 +-
.../text/distsql/ral/RALBackendHandlerFactory.java | 4 +-
.../AdvancedDistSQLBackendHandlerFactory.java | 4 +-
.../common/CommonDistSQLBackendHandlerFactory.java | 4 +-
.../ral/common/HintDistSQLBackendHandler.java | 4 +-
.../ral/common/RefreshTableMetadataHandler.java | 4 +-
.../ral/common/SetDistSQLBackendHandler.java | 4 +-
.../ral/common/ShowDistSQLBackendHandler.java | 4 +-
.../common/hint/HintStatementExecutorFactory.java | 4 +-
.../common/set/SetStatementExecutorFactory.java | 4 +-
.../common/show/ShowStatementExecutorFactory.java | 4 +-
.../show/executor/ShowAllVariablesExecutor.java | 9 +-
.../common/show/executor/ShowVariableExecutor.java | 17 ++-
.../ral/query/QueryableRALBackendHandler.java | 4 +-
.../query/QueryableRALBackendHandlerFactory.java | 4 +-
.../text/distsql/rdl/RDLBackendHandlerFactory.java | 6 +-
.../rdl/resource/AddResourceBackendHandler.java | 4 +-
.../rdl/resource/AlterResourceBackendHandler.java | 4 +-
.../rdl/resource/DropResourceBackendHandler.java | 4 +-
.../rdl/rule/RuleDefinitionBackendHandler.java | 4 +-
.../text/distsql/rql/RQLBackendHandler.java | 4 +-
.../text/distsql/rql/RQLBackendHandlerFactory.java | 4 +-
.../transaction/TransactionBackendHandler.java | 6 +-
.../TransactionBackendHandlerFactory.java | 4 +-
.../DatabaseCommunicationEngineFactoryTest.java | 17 +--
.../DatabaseCommunicationEngineTest.java | 19 +--
.../communication/ProxySQLExecutorTest.java | 26 ++--
...ionTest.java => JDBCBackendConnectionTest.java} | 154 ++++++++++++---------
.../jdbc/connection/MockConnectionUtil.java | 8 +-
.../transaction/BackendTransactionManagerTest.java | 18 ++-
.../transaction/LocalTransactionManagerTest.java | 16 ++-
.../jdbc/transaction/TransactionStatusTest.java | 1 +
.../backend/session/ConnectionSessionTest.java | 85 ++++++++++++
.../TextProtocolBackendHandlerFactoryTest.java | 10 +-
.../DatabaseOperateBackendHandlerFactoryTest.java | 29 ++--
.../executor/ShowProcessListExecutorTest.java | 4 +-
.../mysql/executor/ShowVersionExecutorTest.java | 4 +-
.../information/SelectInformationExecutorTest.java | 12 +-
.../executor/SelectDatabaseExecutorTest.java | 10 +-
.../executor/SelectTableExecutorTest.java | 6 +-
.../data/DatabaseBackendHandlerFactoryTest.java | 12 +-
.../impl/BroadcastDatabaseBackendHandlerTest.java | 16 +--
.../SchemaAssignedDatabaseBackendHandlerTest.java | 6 +-
.../impl/UnicastDatabaseBackendHandlerTest.java | 6 +-
.../database/DropDatabaseBackendHandlerTest.java | 4 +-
.../distsql/DistSQLBackendHandlerFactoryTest.java | 92 ++++--------
.../distsql/ral/SetVariableBackendHandlerTest.java | 6 +-
.../ral/ShowAllVariablesBackendHandlerTest.java | 4 +-
.../ral/ShowVariableBackendHandlerTest.java | 6 +-
.../advance/ParseDistSQLBackendHandlerTest.java | 6 +-
.../hint/HintStatementExecutorFactoryTest.java | 4 +-
.../set/SetStatementExecutorFactoryTest.java | 4 +-
.../set/executor/SetVariableExecutorTest.java | 24 ++--
.../resource/AddResourceBackendHandlerTest.java | 4 +-
.../resource/AlterResourceBackendHandlerTest.java | 4 +-
.../resource/DropResourceBackendHandlerTest.java | 4 +-
.../text/distsql/rql/RQLBackendHandlerTest.java | 10 +-
.../rql/RuleDefinitionBackendHandlerTest.java | 4 +-
.../TransactionBackendHandlerFactoryTest.java | 19 ++-
.../transaction/TransactionBackendHandlerTest.java | 10 +-
.../frontend/command/CommandExecutorTask.java | 43 ++----
.../netty/FrontendChannelInboundHandler.java | 14 +-
.../proxy/frontend/state/ProxyState.java | 7 +-
.../proxy/frontend/state/ProxyStateContext.java | 7 +-
.../state/impl/CircuitBreakProxyState.java | 4 +-
.../proxy/frontend/state/impl/LockProxyState.java | 4 +-
.../proxy/frontend/state/impl/OKProxyState.java | 3 +-
.../frontend/command/CommandExecutorTaskTest.java | 47 +++----
.../frontend/state/impl/OKProxyStateTest.java | 20 +--
.../mysql/command/MySQLCommandExecuteEngine.java | 9 +-
.../mysql/command/MySQLCommandExecutorFactory.java | 4 +-
.../execute/MySQLComStmtExecuteExecutor.java | 8 +-
.../fieldlist/MySQLComFieldListPacketExecutor.java | 8 +-
.../text/query/MySQLComQueryPacketExecutor.java | 4 +-
.../command/MySQLCommandExecutorFactoryTest.java | 12 +-
.../execute/MySQLComStmtExecuteExecutorTest.java | 12 +-
.../query/MySQLComQueryPacketExecutorTest.java | 4 +-
.../command/OpenGaussCommandExecuteEngine.java | 8 +-
.../command/OpenGaussCommandExecutorFactory.java | 4 +-
.../bind/OpenGaussComBatchBindExecutor.java | 10 +-
.../command/PostgreSQLCommandExecuteEngine.java | 23 +--
.../command/PostgreSQLCommandExecutorFactory.java | 4 +-
.../command/PostgreSQLConnectionContext.java | 8 +-
.../command/query/extended/PostgreSQLPortal.java | 18 +--
.../extended/bind/PostgreSQLComBindExecutor.java | 8 +-
.../query/simple/PostgreSQLComQueryExecutor.java | 4 +-
.../PostgreSQLCommandExecuteEngineTest.java | 23 +--
.../PostgreSQLCommandExecutorFactoryTest.java | 4 +-
.../command/PostgreSQLConnectionContextTest.java | 4 +-
.../query/extended/PostgreSQLPortalTest.java | 10 +-
.../bind/PostgreSQLComBindExecutorTest.java | 10 +-
.../close/PostgreSQLComCloseExecutorTest.java | 4 +-
.../sync/PostgreSQLComSyncExecutorTest.java | 6 +-
.../simple/PostgreSQLComQueryExecutorTest.java | 6 +-
.../frontend/command/CommandExecuteEngine.java | 8 +-
116 files changed, 871 insertions(+), 631 deletions(-)
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/advice/CommandExecutorTaskAdvice.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/advice/CommandExecutorTaskAdvice.java
index 29fecf1..02e24ce 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/advice/CommandExecutorTaskAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/advice/CommandExecutorTaskAdvice.java
@@ -27,7 +27,8 @@ import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
import org.apache.shardingsphere.agent.plugin.tracing.jaeger.constant.JaegerConstants;
import org.apache.shardingsphere.agent.plugin.tracing.jaeger.span.JaegerErrorSpan;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutorDataMap;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
import java.lang.reflect.Field;
@@ -54,7 +55,7 @@ public final class CommandExecutorTaskAdvice implements InstanceMethodAroundAdvi
ExecutorDataMap.getValue().remove(JaegerConstants.ROOT_SPAN);
Field field = CommandExecutorTask.class.getDeclaredField("connectionSession");
field.setAccessible(true);
- JDBCConnectionSession connection = (JDBCConnectionSession) field.get(target);
+ JDBCBackendConnection connection = (JDBCBackendConnection) ((ConnectionSession) field.get(target)).getBackendConnection();
Scope scope = GlobalTracer.get().scopeManager().active();
scope.span().setTag(JaegerConstants.ShardingSphereTags.CONNECTION_COUNT.getKey(), connection.getConnectionSize());
scope.close();
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/advice/CommandExecutorTaskAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/advice/CommandExecutorTaskAdviceTest.java
index 6639bfe..677275f 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/advice/CommandExecutorTaskAdviceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-opentracing/src/test/java/org/apache/shardingsphere/agent/plugin/tracing/opentracing/advice/CommandExecutorTaskAdviceTest.java
@@ -25,7 +25,6 @@ import io.opentracing.util.GlobalTracer;
import lombok.SneakyThrows;
import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -58,7 +57,7 @@ public final class CommandExecutorTaskAdviceTest {
}
FieldReader fieldReader = new FieldReader(GlobalTracer.get(), GlobalTracer.class.getDeclaredField("tracer"));
tracer = (MockTracer) fieldReader.read();
- executeCommandMethod = CommandExecutorTask.class.getDeclaredMethod("executeCommand", ChannelHandlerContext.class, PacketPayload.class, JDBCConnectionSession.class);
+ executeCommandMethod = CommandExecutorTask.class.getDeclaredMethod("executeCommand", ChannelHandlerContext.class, PacketPayload.class);
}
@Before
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
index 44b03cc..d696522 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
@@ -21,7 +21,8 @@ import io.netty.util.DefaultAttributeMap;
import lombok.Getter;
import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject;
import org.apache.shardingsphere.agent.plugin.tracing.AgentRunner;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.runner.RunWith;
@@ -35,7 +36,10 @@ public abstract class AbstractCommandExecutorTaskAdviceTest implements AdviceTes
@SuppressWarnings("ConstantConditions")
@Override
public final void prepare() {
- Object executorTask = new CommandExecutorTask(null, new JDBCConnectionSession(TransactionType.BASE, new DefaultAttributeMap()), null, null);
+ ConnectionSession connectionSession = new ConnectionSession(TransactionType.BASE, new DefaultAttributeMap());
+ JDBCBackendConnection backendConnection = new JDBCBackendConnection(connectionSession);
+ connectionSession.setBackendConnection(backendConnection);
+ Object executorTask = new CommandExecutorTask(null, connectionSession, null, null);
targetObject = (AdviceTargetObject) executorTask;
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/advice/CommandExecutorTaskAdvice.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/advice/CommandExecutorTaskAdvice.java
index 084640a..ecdf45b 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/advice/CommandExecutorTaskAdvice.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/advice/CommandExecutorTaskAdvice.java
@@ -25,7 +25,8 @@ import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject;
import org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
import org.apache.shardingsphere.agent.plugin.tracing.zipkin.constant.ZipkinConstants;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutorDataMap;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
import java.lang.reflect.Field;
@@ -51,7 +52,7 @@ public final class CommandExecutorTaskAdvice implements InstanceMethodAroundAdvi
public void afterMethod(final AdviceTargetObject target, final Method method, final Object[] args, final MethodInvocationResult result) {
Field field = CommandExecutorTask.class.getDeclaredField("connectionSession");
field.setAccessible(true);
- JDBCConnectionSession connection = (JDBCConnectionSession) field.get(target);
+ JDBCBackendConnection connection = (JDBCBackendConnection) ((ConnectionSession) field.get(target)).getBackendConnection();
Span span = (Span) ExecutorDataMap.getValue().remove(ZipkinConstants.ROOT_SPAN);
span.tag(ZipkinConstants.Tags.CONNECTION_COUNT, String.valueOf(connection.getConnectionSize()));
span.finish();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/BackendConnection.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/BackendConnection.java
new file mode 100644
index 0000000..c71a505
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/BackendConnection.java
@@ -0,0 +1,55 @@
+/*
+ * 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.communication;
+
+import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+
+/**
+ * Backend connection for Proxy.
+ */
+public interface BackendConnection {
+
+ /**
+ * Get connection session of backend connection.
+ *
+ * @return connection session
+ */
+ ConnectionSession getConnectionSession();
+
+ /**
+ * Prepare for task execution.
+ *
+ * @throws BackendConnectionException backend connection exception
+ */
+ void prepareForTaskExecution() throws BackendConnectionException;
+
+ /**
+ * Close resources used in execution.
+ *
+ * @throws BackendConnectionException backend connection exception
+ */
+ void closeExecutionResources() throws BackendConnectionException;
+
+ /**
+ * Close all resources.
+ *
+ * @throws BackendConnectionException backend connection exception
+ */
+ void closeAllResources() throws BackendConnectionException;
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 2c98643..9139964 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.merge.MergeEngine;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
@@ -83,14 +83,14 @@ public final class DatabaseCommunicationEngine {
private final Collection<ResultSet> cachedResultSets = new CopyOnWriteArrayList<>();
- public DatabaseCommunicationEngine(final String driverType, final ShardingSphereMetaData metaData, final LogicSQL logicSQL, final JDBCConnectionSession connectionSession) {
+ public DatabaseCommunicationEngine(final String driverType, final ShardingSphereMetaData metaData, final LogicSQL logicSQL, final JDBCBackendConnection backendConnection) {
this.driverType = driverType;
this.metaData = metaData;
this.logicSQL = logicSQL;
- proxySQLExecutor = new ProxySQLExecutor(driverType, connectionSession, this);
+ proxySQLExecutor = new ProxySQLExecutor(driverType, backendConnection, this);
kernelProcessor = new KernelProcessor();
metadataRefreshEngine = new MetaDataRefreshEngine(metaData,
- ProxyContext.getInstance().getContextManager().getMetaDataContexts().getOptimizerContext().getMetaData().getSchemas().get(connectionSession.getSchemaName()),
+ ProxyContext.getInstance().getContextManager().getMetaDataContexts().getOptimizerContext().getMetaData().getSchemas().get(backendConnection.getConnectionSession().getSchemaName()),
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
index c992a70..0822d02 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import java.util.Collections;
@@ -51,14 +51,14 @@ public final class DatabaseCommunicationEngineFactory {
*
* @param sqlStatementContext SQL statement context
* @param sql SQL to be executed
- * @param connectionSession connection session
+ * @param backendConnection backend connection
* @return text protocol backend handler
*/
- public DatabaseCommunicationEngine newTextProtocolInstance(final SQLStatementContext<?> sqlStatementContext, final String sql, final JDBCConnectionSession connectionSession) {
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName());
+ public DatabaseCommunicationEngine newTextProtocolInstance(final SQLStatementContext<?> sqlStatementContext, final String sql, final JDBCBackendConnection backendConnection) {
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getSchemaName());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, Collections.emptyList());
- DatabaseCommunicationEngine result = new DatabaseCommunicationEngine(JDBCDriverType.STATEMENT, metaData, logicSQL, connectionSession);
- connectionSession.add(result);
+ DatabaseCommunicationEngine result = new DatabaseCommunicationEngine(JDBCDriverType.STATEMENT, metaData, logicSQL, backendConnection);
+ backendConnection.add(result);
return result;
}
@@ -68,15 +68,15 @@ public final class DatabaseCommunicationEngineFactory {
* @param sqlStatementContext SQL statement context
* @param sql SQL to be executed
* @param parameters SQL parameters
- * @param connectionSession connection session
+ * @param backendConnection backend connection
* @return binary protocol backend handler
*/
public DatabaseCommunicationEngine newBinaryProtocolInstance(final SQLStatementContext<?> sqlStatementContext, final String sql,
- final List<Object> parameters, final JDBCConnectionSession connectionSession) {
- ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName());
+ final List<Object> parameters, final JDBCBackendConnection backendConnection) {
+ ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getSchemaName());
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, parameters);
- DatabaseCommunicationEngine result = new DatabaseCommunicationEngine(JDBCDriverType.PREPARED_STATEMENT, metaData, logicSQL, connectionSession);
- connectionSession.add(result);
+ DatabaseCommunicationEngine result = new DatabaseCommunicationEngine(JDBCDriverType.PREPARED_STATEMENT, metaData, logicSQL, backendConnection);
+ backendConnection.add(result);
return result;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
index 9f2554b..e6bb8b0 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutor.java
@@ -38,11 +38,11 @@ import org.apache.shardingsphere.infra.federation.executor.FederationExecutorFac
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.type.RawExecutionRule;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.executor.ProxyJDBCExecutor;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.executor.callback.ProxyJDBCExecutorCallback;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.executor.callback.ProxyJDBCExecutorCallbackFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.apache.shardingsphere.proxy.backend.context.BackendExecutorContext;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.TableModifyInTransactionException;
@@ -67,7 +67,7 @@ public final class ProxySQLExecutor {
private final String type;
- private final JDBCConnectionSession connectionSession;
+ private final JDBCBackendConnection backendConnection;
private final DatabaseCommunicationEngine databaseCommunicationEngine;
@@ -77,17 +77,17 @@ public final class ProxySQLExecutor {
private final FederationExecutor federationExecutor;
- public ProxySQLExecutor(final String type, final JDBCConnectionSession connectionSession, final DatabaseCommunicationEngine databaseCommunicationEngine) {
+ public ProxySQLExecutor(final String type, final JDBCBackendConnection backendConnection, final DatabaseCommunicationEngine databaseCommunicationEngine) {
this.type = type;
- this.connectionSession = connectionSession;
+ this.backendConnection = backendConnection;
this.databaseCommunicationEngine = databaseCommunicationEngine;
ExecutorEngine executorEngine = BackendExecutorContext.getInstance().getExecutorEngine();
- boolean isSerialExecute = connectionSession.isSerialExecute();
+ boolean isSerialExecute = backendConnection.isSerialExecute();
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- jdbcExecutor = new ProxyJDBCExecutor(type, connectionSession, databaseCommunicationEngine, new JDBCExecutor(executorEngine, isSerialExecute));
+ jdbcExecutor = new ProxyJDBCExecutor(type, backendConnection.getConnectionSession(), databaseCommunicationEngine, new JDBCExecutor(executorEngine, isSerialExecute));
rawExecutor = new RawExecutor(executorEngine, isSerialExecute, metaDataContexts.getProps());
federationExecutor = FederationExecutorFactory.newInstance(
- connectionSession.getSchemaName(), metaDataContexts.getOptimizerContext(), metaDataContexts.getProps(), new JDBCExecutor(executorEngine, isSerialExecute));
+ backendConnection.getConnectionSession().getSchemaName(), metaDataContexts.getOptimizerContext(), metaDataContexts.getProps(), new JDBCExecutor(executorEngine, isSerialExecute));
}
/**
@@ -103,14 +103,14 @@ public final class ProxySQLExecutor {
}
private boolean isExecuteDDLInXATransaction(final SQLStatement sqlStatement) {
- TransactionStatus transactionStatus = connectionSession.getTransactionStatus();
+ TransactionStatus transactionStatus = backendConnection.getConnectionSession().getTransactionStatus();
return TransactionType.XA == transactionStatus.getTransactionType() && sqlStatement instanceof DDLStatement && transactionStatus.isInTransaction();
}
private boolean isExecuteDDLInPostgreSQLOpenGaussTransaction(final SQLStatement sqlStatement) {
// TODO implement DDL statement commit/rollback in PostgreSQL/openGauss transaction
boolean isPostgreSQLOpenGaussStatement = sqlStatement instanceof PostgreSQLStatement || sqlStatement instanceof OpenGaussStatement;
- return sqlStatement instanceof DDLStatement && isPostgreSQLOpenGaussStatement && connectionSession.getTransactionStatus().isInTransaction();
+ return sqlStatement instanceof DDLStatement && isPostgreSQLOpenGaussStatement && backendConnection.getConnectionSession().getTransactionStatus().isInTransaction();
}
/**
@@ -121,7 +121,8 @@ public final class ProxySQLExecutor {
* @throws SQLException SQL exception
*/
public Collection<ExecuteResult> execute(final ExecutionContext executionContext) throws SQLException {
- Collection<ShardingSphereRule> rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(connectionSession.getSchemaName()).getRuleMetaData().getRules();
+ String schemaName = backendConnection.getConnectionSession().getSchemaName();
+ Collection<ShardingSphereRule> rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getRuleMetaData().getRules();
int maxConnectionsSizePerQuery = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
boolean isReturnGeneratedKeys = executionContext.getSqlStatementContext().getSqlStatement() instanceof MySQLInsertStatement;
return execute(executionContext, rules, maxConnectionsSizePerQuery, isReturnGeneratedKeys);
@@ -146,8 +147,8 @@ public final class ProxySQLExecutor {
} catch (final SQLException ex) {
return getSaneExecuteResults(executionContext, ex);
}
- executionGroupContext.setSchemaName(connectionSession.getSchemaName());
- executionGroupContext.setGrantee(connectionSession.getGrantee());
+ executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getSchemaName());
+ executionGroupContext.setGrantee(backendConnection.getConnectionSession().getGrantee());
// TODO handle query header
return rawExecutor.execute(executionGroupContext, executionContext.getLogicSQL(), new RawSQLExecutorCallback());
}
@@ -157,36 +158,37 @@ public final class ProxySQLExecutor {
return Collections.emptyList();
}
MetaDataContexts metaData = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- ProxyJDBCExecutorCallback callback = ProxyJDBCExecutorCallbackFactory.newInstance(type, metaData.getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType(),
+ String schemaName = backendConnection.getConnectionSession().getSchemaName();
+ ProxyJDBCExecutorCallback callback = ProxyJDBCExecutorCallbackFactory.newInstance(type, metaData.getMetaData(schemaName).getResource().getDatabaseType(),
executionContext.getSqlStatementContext().getSqlStatement(), databaseCommunicationEngine, isReturnGeneratedKeys, isExceptionThrown, true);
- connectionSession.setFederationExecutor(federationExecutor);
+ backendConnection.setFederationExecutor(federationExecutor);
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = createDriverExecutionPrepareEngine(isReturnGeneratedKeys, metaData);
return federationExecutor.executeQuery(prepareEngine, callback, executionContext).stream().map(each -> (ExecuteResult) each).collect(Collectors.toList());
}
private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriverExecutionPrepareEngine(final boolean isReturnGeneratedKeys, final MetaDataContexts metaData) {
int maxConnectionsSizePerQuery = metaData.getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
- return new DriverExecutionPrepareEngine<>(type, maxConnectionsSizePerQuery, connectionSession, new StatementOption(isReturnGeneratedKeys),
- metaData.getMetaData(connectionSession.getSchemaName()).getRuleMetaData().getRules());
+ return new DriverExecutionPrepareEngine<>(type, maxConnectionsSizePerQuery, backendConnection, new StatementOption(isReturnGeneratedKeys),
+ metaData.getMetaData(backendConnection.getConnectionSession().getSchemaName()).getRuleMetaData().getRules());
}
private Collection<ExecuteResult> useDriverToExecute(final ExecutionContext executionContext, final Collection<ShardingSphereRule> rules,
final int maxConnectionsSizePerQuery, final boolean isReturnGeneratedKeys, final boolean isExceptionThrown) throws SQLException {
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = new DriverExecutionPrepareEngine<>(
- type, maxConnectionsSizePerQuery, connectionSession, new StatementOption(isReturnGeneratedKeys), rules);
+ type, maxConnectionsSizePerQuery, backendConnection, new StatementOption(isReturnGeneratedKeys), rules);
ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext;
try {
executionGroupContext = prepareEngine.prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits());
} catch (final SQLException ex) {
return getSaneExecuteResults(executionContext, ex);
}
- executionGroupContext.setSchemaName(connectionSession.getSchemaName());
- executionGroupContext.setGrantee(connectionSession.getGrantee());
+ executionGroupContext.setSchemaName(backendConnection.getConnectionSession().getSchemaName());
+ executionGroupContext.setGrantee(backendConnection.getConnectionSession().getGrantee());
return jdbcExecutor.execute(executionContext.getLogicSQL(), executionGroupContext, isReturnGeneratedKeys, isExceptionThrown);
}
private Collection<ExecuteResult> getSaneExecuteResults(final ExecutionContext executionContext, final SQLException originalException) throws SQLException {
- DatabaseType databaseType = ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = ProxyContext.getInstance().getMetaData(backendConnection.getConnectionSession().getSchemaName()).getResource().getDatabaseType();
Optional<ExecuteResult> executeResult = JDBCSaneQueryResultEngineFactory.newInstance(databaseType).getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement());
if (executeResult.isPresent()) {
return Collections.singleton(executeResult.get());
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCConnectionSession.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
similarity index 78%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCConnectionSession.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
index f7a6620..1491574 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCConnectionSession.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.proxy.backend.communication.jdbc.connection;
import com.google.common.base.Preconditions;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
-import io.netty.util.AttributeMap;
import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.db.protocol.parameter.TypeUnspecifiedSQLParameter;
@@ -29,9 +28,12 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMod
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.ExecutorJDBCManager;
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption;
import org.apache.shardingsphere.infra.federation.executor.FederationExecutor;
+import org.apache.shardingsphere.proxy.backend.communication.BackendConnection;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.statement.StatementMemoryStrictlyFetchSizeSetter;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.typed.TypedSPI;
@@ -53,16 +55,18 @@ import java.util.function.Function;
import java.util.stream.Collectors;
/**
- * JDBC connection session.
+ * JDBC backend connection.
*/
@Getter
@Setter
-public final class JDBCConnectionSession extends ConnectionSession implements ExecutorJDBCManager {
+public final class JDBCBackendConnection implements BackendConnection, ExecutorJDBCManager {
static {
ShardingSphereServiceLoader.register(StatementMemoryStrictlyFetchSizeSetter.class);
}
+ private final ConnectionSession connectionSession;
+
private volatile FederationExecutor federationExecutor;
private final Multimap<String, Connection> cachedConnections = LinkedHashMultimap.create();
@@ -79,15 +83,15 @@ public final class JDBCConnectionSession extends ConnectionSession implements Ex
private final Map<String, StatementMemoryStrictlyFetchSizeSetter> fetchSizeSetters;
- public JDBCConnectionSession(final TransactionType initialTransactionType, final AttributeMap attributeMap) {
- super(initialTransactionType, attributeMap);
+ public JDBCBackendConnection(final ConnectionSession connectionSession) {
+ this.connectionSession = connectionSession;
fetchSizeSetters = ShardingSphereServiceLoader.getSingletonServiceInstances(StatementMemoryStrictlyFetchSizeSetter.class).stream()
.collect(Collectors.toMap(TypedSPI::getType, Function.identity()));
}
@Override
public List<Connection> getConnections(final String dataSourceName, final int connectionSize, final ConnectionMode connectionMode) throws SQLException {
- return getTransactionStatus().isInTransaction()
+ return connectionSession.getTransactionStatus().isInTransaction()
? getConnectionsWithTransaction(dataSourceName, connectionSize, connectionMode) : getConnectionsWithoutTransaction(dataSourceName, connectionSize, connectionMode);
}
@@ -117,8 +121,8 @@ public final class JDBCConnectionSession extends ConnectionSession implements Ex
}
private List<Connection> createNewConnections(final String dataSourceName, final int connectionSize, final ConnectionMode connectionMode) throws SQLException {
- Preconditions.checkNotNull(getSchemaName(), "Current schema is null.");
- List<Connection> result = ProxyContext.getInstance().getBackendDataSource().getConnections(getSchemaName(), dataSourceName, connectionSize, connectionMode);
+ Preconditions.checkNotNull(connectionSession.getSchemaName(), "Current schema is null.");
+ List<Connection> result = ProxyContext.getInstance().getBackendDataSource().getConnections(connectionSession.getSchemaName(), dataSourceName, connectionSize, connectionMode);
for (Connection each : result) {
replayMethodsInvocation(each);
}
@@ -126,8 +130,8 @@ public final class JDBCConnectionSession extends ConnectionSession implements Ex
}
private List<Connection> getConnectionsWithoutTransaction(final String dataSourceName, final int connectionSize, final ConnectionMode connectionMode) throws SQLException {
- Preconditions.checkNotNull(getSchemaName(), "Current schema is null.");
- List<Connection> result = ProxyContext.getInstance().getBackendDataSource().getConnections(getSchemaName(), dataSourceName, connectionSize, connectionMode);
+ Preconditions.checkNotNull(connectionSession.getSchemaName(), "Current schema is null.");
+ List<Connection> result = ProxyContext.getInstance().getBackendDataSource().getConnections(connectionSession.getSchemaName(), dataSourceName, connectionSize, connectionMode);
synchronized (cachedConnections) {
cachedConnections.putAll(dataSourceName, result);
}
@@ -169,7 +173,7 @@ public final class JDBCConnectionSession extends ConnectionSession implements Ex
}
private void setFetchSize(final Statement statement) throws SQLException {
- DatabaseType databaseType = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(getSchemaName()).getResource().getDatabaseType();
+ DatabaseType databaseType = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(connectionSession.getSchemaName()).getResource().getDatabaseType();
if (fetchSizeSetters.containsKey(databaseType.getName())) {
fetchSizeSetters.get(databaseType.getName()).setFetchSize(statement);
}
@@ -181,7 +185,8 @@ public final class JDBCConnectionSession extends ConnectionSession implements Ex
* @return true or false
*/
public boolean isSerialExecute() {
- return getTransactionStatus().isInTransaction() && (TransactionType.LOCAL == getTransactionStatus().getTransactionType() || TransactionType.XA == getTransactionStatus().getTransactionType());
+ return connectionSession.getTransactionStatus().isInTransaction()
+ && (TransactionType.LOCAL == connectionSession.getTransactionStatus().getTransactionType() || TransactionType.XA == connectionSession.getTransactionStatus().getTransactionType());
}
/**
@@ -220,6 +225,45 @@ public final class JDBCConnectionSession extends ConnectionSession implements Ex
inUseDatabaseCommunicationEngines.remove(databaseCommunicationEngine);
}
+ @Override
+ public void prepareForTaskExecution() throws BackendConnectionException {
+ if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
+ connectionStatus.waitUntilConnectionRelease();
+ connectionStatus.switchToUsing();
+ }
+ if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
+ BackendTransactionManager transactionManager = new BackendTransactionManager(this);
+ try {
+ transactionManager.begin();
+ } catch (SQLException ex) {
+ throw new BackendConnectionException(ex);
+ }
+ }
+ }
+
+ @Override
+ public void closeExecutionResources() throws BackendConnectionException {
+ Collection<Exception> result = new LinkedList<>();
+ result.addAll(closeDatabaseCommunicationEngines(false));
+ result.addAll(closeFederationExecutor());
+ if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
+ result.addAll(closeDatabaseCommunicationEngines(true));
+ result.addAll(closeConnections(false));
+ connectionStatus.switchToReleased();
+ }
+ if (result.isEmpty()) {
+ return;
+ }
+ throw new BackendConnectionException(result);
+ }
+
+ @Override
+ public void closeAllResources() {
+ closeDatabaseCommunicationEngines(true);
+ closeConnections(true);
+ closeFederationExecutor();
+ }
+
/**
* Close database communication engines.
*
@@ -255,7 +299,7 @@ public final class JDBCConnectionSession extends ConnectionSession implements Ex
Collection<SQLException> result = new LinkedList<>();
for (Connection each : cachedConnections.values()) {
try {
- if (forceRollback && getTransactionStatus().isInTransaction()) {
+ if (forceRollback && connectionSession.getTransactionStatus().isInTransaction()) {
each.rollback();
}
each.close();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManager.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManager.java
index 12fd4c5..deaede8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManager.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManager.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction;
import org.apache.shardingsphere.transaction.TransactionHolder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine;
import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -31,7 +31,7 @@ import java.sql.SQLException;
*/
public final class BackendTransactionManager implements TransactionManager {
- private final JDBCConnectionSession connection;
+ private final JDBCBackendConnection connection;
private final TransactionType transactionType;
@@ -39,18 +39,18 @@ public final class BackendTransactionManager implements TransactionManager {
private final ShardingSphereTransactionManager shardingSphereTransactionManager;
- public BackendTransactionManager(final JDBCConnectionSession connectionSession) {
- connection = connectionSession;
- transactionType = connection.getTransactionStatus().getTransactionType();
- localTransactionManager = new LocalTransactionManager(connectionSession);
- ShardingSphereTransactionManagerEngine engine = ProxyContext.getInstance().getContextManager().getTransactionContexts().getEngines().get(connection.getSchemaName());
+ public BackendTransactionManager(final JDBCBackendConnection backendConnection) {
+ connection = backendConnection;
+ transactionType = connection.getConnectionSession().getTransactionStatus().getTransactionType();
+ localTransactionManager = new LocalTransactionManager(backendConnection);
+ ShardingSphereTransactionManagerEngine engine = ProxyContext.getInstance().getContextManager().getTransactionContexts().getEngines().get(connection.getConnectionSession().getSchemaName());
shardingSphereTransactionManager = null == engine ? null : engine.getTransactionManager(transactionType);
}
@Override
public void begin() throws SQLException {
- if (!connection.getTransactionStatus().isInTransaction()) {
- connection.getTransactionStatus().setInTransaction(true);
+ if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
+ connection.getConnectionSession().getTransactionStatus().setInTransaction(true);
TransactionHolder.setInTransaction();
connection.closeDatabaseCommunicationEngines(true);
connection.closeConnections(false);
@@ -64,7 +64,7 @@ public final class BackendTransactionManager implements TransactionManager {
@Override
public void commit() throws SQLException {
- if (connection.getTransactionStatus().isInTransaction()) {
+ if (connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
try {
if (TransactionType.LOCAL == transactionType || null == shardingSphereTransactionManager) {
localTransactionManager.commit();
@@ -72,7 +72,7 @@ public final class BackendTransactionManager implements TransactionManager {
shardingSphereTransactionManager.commit();
}
} finally {
- connection.getTransactionStatus().setInTransaction(false);
+ connection.getConnectionSession().getTransactionStatus().setInTransaction(false);
TransactionHolder.clear();
}
}
@@ -80,7 +80,7 @@ public final class BackendTransactionManager implements TransactionManager {
@Override
public void rollback() throws SQLException {
- if (connection.getTransactionStatus().isInTransaction()) {
+ if (connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
try {
if (TransactionType.LOCAL == transactionType || null == shardingSphereTransactionManager) {
localTransactionManager.rollback();
@@ -88,7 +88,7 @@ public final class BackendTransactionManager implements TransactionManager {
shardingSphereTransactionManager.rollback();
}
} finally {
- connection.getTransactionStatus().setInTransaction(false);
+ connection.getConnectionSession().getTransactionStatus().setInTransaction(false);
TransactionHolder.clear();
}
}
@@ -96,7 +96,7 @@ public final class BackendTransactionManager implements TransactionManager {
@Override
public void setSavepoint(final String savepointName) throws SQLException {
- if (!connection.getTransactionStatus().isInTransaction()) {
+ if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
return;
}
if (TransactionType.LOCAL == transactionType || null == shardingSphereTransactionManager) {
@@ -107,7 +107,7 @@ public final class BackendTransactionManager implements TransactionManager {
@Override
public void rollbackTo(final String savepointName) throws SQLException {
- if (!connection.getTransactionStatus().isInTransaction()) {
+ if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
return;
}
if (TransactionType.LOCAL == transactionType || null == shardingSphereTransactionManager) {
@@ -118,7 +118,7 @@ public final class BackendTransactionManager implements TransactionManager {
@Override
public void releaseSavepoint(final String savepointName) throws SQLException {
- if (!connection.getTransactionStatus().isInTransaction()) {
+ if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
return;
}
if (TransactionType.LOCAL == transactionType || null == shardingSphereTransactionManager) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java
index 4b74ce0..bc3ba8b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManager.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import java.sql.Connection;
import java.sql.SQLException;
@@ -31,7 +31,7 @@ import java.util.LinkedList;
@RequiredArgsConstructor
public final class LocalTransactionManager implements TransactionManager {
- private final JDBCConnectionSession connection;
+ private final JDBCBackendConnection connection;
@Override
public void begin() {
@@ -46,7 +46,7 @@ public final class LocalTransactionManager implements TransactionManager {
@Override
public void commit() throws SQLException {
- if (connection.getTransactionStatus().isInTransaction()) {
+ if (connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
Collection<SQLException> exceptions = new LinkedList<>(commitConnections());
throwSQLExceptionIfNecessary(exceptions);
}
@@ -68,7 +68,7 @@ public final class LocalTransactionManager implements TransactionManager {
@Override
public void rollback() throws SQLException {
- if (connection.getTransactionStatus().isInTransaction()) {
+ if (connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
Collection<SQLException> exceptions = new LinkedList<>(rollbackConnections());
throwSQLExceptionIfNecessary(exceptions);
}
@@ -90,7 +90,7 @@ public final class LocalTransactionManager implements TransactionManager {
@Override
public void setSavepoint(final String savepointName) throws SQLException {
- if (!connection.getTransactionStatus().isInTransaction()) {
+ if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
return;
}
for (Connection each : connection.getCachedConnections().values()) {
@@ -107,7 +107,7 @@ public final class LocalTransactionManager implements TransactionManager {
@Override
public void rollbackTo(final String savepointName) throws SQLException {
- if (!connection.getTransactionStatus().isInTransaction()) {
+ if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
return;
}
Collection<SQLException> result = new LinkedList<>();
@@ -123,7 +123,7 @@ public final class LocalTransactionManager implements TransactionManager {
@Override
public void releaseSavepoint(final String savepointName) throws SQLException {
- if (!connection.getTransactionStatus().isInTransaction()) {
+ if (!connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
return;
}
Collection<SQLException> result = new LinkedList<>();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/BackendConnectionException.java
similarity index 53%
copy from shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/BackendConnectionException.java
index f7c1c2e..a8231d9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/BackendConnectionException.java
@@ -15,20 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.frontend.state.impl;
+package org.apache.shardingsphere.proxy.backend.exception;
-import io.netty.channel.ChannelHandlerContext;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
-import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
-import org.apache.shardingsphere.proxy.frontend.state.ProxyState;
+import lombok.Getter;
+
+import java.util.Collection;
+import java.util.LinkedList;
/**
- * Lock proxy state.
+ * Exception causes by backend connection.
*/
-public final class LockProxyState implements ProxyState {
+@Getter
+public final class BackendConnectionException extends Exception {
+
+ private final Collection<Exception> exceptions = new LinkedList<>();
+
+ public BackendConnectionException(final Exception ex) {
+ exceptions.add(ex);
+ }
- @Override
- public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final JDBCConnectionSession connectionSession) {
- throw new UnsupportedOperationException("LockProxyState");
+ public BackendConnectionException(final Collection<Exception> exceptions) {
+ this.exceptions.addAll(exceptions);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
index db31a88..480227f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
@@ -23,8 +23,9 @@ import lombok.Getter;
import lombok.Setter;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import org.apache.shardingsphere.proxy.backend.communication.BackendConnection;
import org.apache.shardingsphere.proxy.backend.communication.SQLStatementSchemaHolder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.apache.shardingsphere.transaction.core.TransactionType;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -34,7 +35,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
*/
@Getter
@Setter
-public abstract class ConnectionSession {
+public final class ConnectionSession {
@Setter(AccessLevel.NONE)
private volatile String schemaName;
@@ -47,8 +48,11 @@ public abstract class ConnectionSession {
private final AttributeMap attributeMap;
+ @Getter(AccessLevel.NONE)
private final AtomicBoolean autoCommit = new AtomicBoolean(true);
+ private volatile BackendConnection backendConnection;
+
public ConnectionSession(final TransactionType initialTransactionType, final AttributeMap attributeMap) {
transactionStatus = new TransactionStatus(initialTransactionType);
this.attributeMap = attributeMap;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/TransactionStatus.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/transaction/TransactionStatus.java
similarity index 96%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/TransactionStatus.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/transaction/TransactionStatus.java
index 270d6ef..73d36b4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/TransactionStatus.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/session/transaction/TransactionStatus.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction;
+package org.apache.shardingsphere.proxy.backend.session.transaction;
import lombok.Getter;
import lombok.Setter;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
index 228646c..3d46306 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
@@ -31,7 +31,6 @@ import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.communication.SQLStatementSchemaHolder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminBackendHandlerFactory;
@@ -78,7 +77,7 @@ public final class TextProtocolBackendHandlerFactory {
* @throws SQLException SQL exception
*/
@SuppressWarnings("unchecked")
- public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final String sql, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final String sql, final ConnectionSession connectionSession) throws SQLException {
String trimSQL = SQLUtil.trimComment(sql);
if (Strings.isNullOrEmpty(trimSQL)) {
return new SkipBackendHandler(new EmptyStatement());
@@ -93,8 +92,8 @@ public final class TextProtocolBackendHandlerFactory {
if (backendHandler.isPresent()) {
return backendHandler.get();
}
- SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(
- ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), Collections.emptyList(), sqlStatement, connectionSession.getDefaultSchemaName());
+ SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(),
+ Collections.emptyList(), sqlStatement, connectionSession.getDefaultSchemaName());
// TODO optimize SQLStatementSchemaHolder
if (sqlStatementContext instanceof TableAvailable) {
((TableAvailable) sqlStatementContext).getTablesContext().getSchemaName().ifPresent(SQLStatementSchemaHolder::set);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java
index 19bd777..641368d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseAdminBackendHandlerFactory.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.admin;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutor;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutorFactory;
@@ -51,7 +51,7 @@ public final class DatabaseAdminBackendHandlerFactory {
* @param connectionSession connection session
* @return new instance of database admin backend handler
*/
- public static Optional<TextProtocolBackendHandler> newInstance(final DatabaseType databaseType, final SQLStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ public static Optional<TextProtocolBackendHandler> newInstance(final DatabaseType databaseType, final SQLStatement sqlStatement, final ConnectionSession connectionSession) {
Optional<DatabaseAdminExecutorFactory> executorFactory = TypedSPIRegistry.findRegisteredService(DatabaseAdminExecutorFactory.class, databaseType.getName(), new Properties());
if (!executorFactory.isPresent()) {
return Optional.empty();
@@ -70,7 +70,7 @@ public final class DatabaseAdminBackendHandlerFactory {
* @return new instance of database admin backend handler
*/
public static Optional<TextProtocolBackendHandler> newInstance(final DatabaseType databaseType, final SQLStatement sqlStatement,
- final JDBCConnectionSession connectionSession, final String sql) {
+ final ConnectionSession connectionSession, final String sql) {
Optional<DatabaseAdminExecutorFactory> executorFactory = TypedSPIRegistry.findRegisteredService(DatabaseAdminExecutorFactory.class, databaseType.getName(), new Properties());
if (!executorFactory.isPresent()) {
return Optional.empty();
@@ -79,7 +79,7 @@ public final class DatabaseAdminBackendHandlerFactory {
return executor.map(optional -> createTextProtocolBackendHandler(sqlStatement, connectionSession, optional));
}
- private static TextProtocolBackendHandler createTextProtocolBackendHandler(final SQLStatement sqlStatement, final JDBCConnectionSession connectionSession, final DatabaseAdminExecutor executor) {
+ private static TextProtocolBackendHandler createTextProtocolBackendHandler(final SQLStatement sqlStatement, final ConnectionSession connectionSession, final DatabaseAdminExecutor executor) {
return executor instanceof DatabaseAdminQueryExecutor
? new DatabaseAdminQueryBackendHandler(connectionSession, (DatabaseAdminQueryExecutor) executor) : new DatabaseAdminUpdateBackendHandler(connectionSession, sqlStatement, executor);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactory.java
index 9331555..625f770 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactory.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.data;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.UnicastDatabaseBackendHandler;
@@ -44,7 +44,7 @@ public final class DatabaseBackendHandlerFactory {
* @param connectionSession connection session
* @return database backend handler
*/
- public static DatabaseBackendHandler newInstance(final SQLStatementContext<?> sqlStatementContext, final String sql, final JDBCConnectionSession connectionSession) {
+ public static DatabaseBackendHandler newInstance(final SQLStatementContext<?> sqlStatementContext, final String sql, final ConnectionSession connectionSession) {
SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
if (sqlStatement instanceof SetStatement || sqlStatement instanceof DCLStatement) {
return new BroadcastDatabaseBackendHandler(sqlStatementContext, sql, connectionSession);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java
index 05ee7a3..e0b67dd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandler.java
@@ -20,11 +20,12 @@ package org.apache.shardingsphere.proxy.backend.text.data.impl;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DatabaseNotExistedException;
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.data.DatabaseBackendHandler;
import java.sql.SQLException;
@@ -44,7 +45,7 @@ public final class BroadcastDatabaseBackendHandler implements DatabaseBackendHan
private final String sql;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
@Override
public ResponseHeader execute() throws SQLException {
@@ -53,7 +54,7 @@ public final class BroadcastDatabaseBackendHandler implements DatabaseBackendHan
try {
for (String each : schemaNames) {
connectionSession.setCurrentSchema(each);
- databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession).execute();
+ databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, (JDBCBackendConnection) connectionSession.getBackendConnection()).execute();
}
} finally {
connectionSession.setCurrentSchema(originalSchema);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
index 20fd12d..c465acf 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
@@ -21,10 +21,11 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.RuleNotExistedException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.data.DatabaseBackendHandler;
import java.sql.SQLException;
@@ -42,7 +43,7 @@ public final class SchemaAssignedDatabaseBackendHandler implements DatabaseBacke
private final String sql;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
private DatabaseCommunicationEngine databaseCommunicationEngine;
@@ -51,7 +52,7 @@ public final class SchemaAssignedDatabaseBackendHandler implements DatabaseBacke
if (!ProxyContext.getInstance().getMetaData(connectionSession.getSchemaName()).isComplete()) {
throw new RuleNotExistedException();
}
- databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession);
+ databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, (JDBCBackendConnection) connectionSession.getBackendConnection());
return databaseCommunicationEngine.execute();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
index c579e50..79af130 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
@@ -21,11 +21,12 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import org.apache.shardingsphere.proxy.backend.exception.RuleNotExistedException;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.data.DatabaseBackendHandler;
import java.sql.SQLException;
@@ -44,7 +45,7 @@ public final class UnicastDatabaseBackendHandler implements DatabaseBackendHandl
private final String sql;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
private DatabaseCommunicationEngine databaseCommunicationEngine;
@@ -57,7 +58,7 @@ public final class UnicastDatabaseBackendHandler implements DatabaseBackendHandl
}
try {
connectionSession.setCurrentSchema(schemaName);
- databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, connectionSession);
+ databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, (JDBCBackendConnection) connectionSession.getBackendConnection());
return databaseCommunicationEngine.execute();
} finally {
connectionSession.setCurrentSchema(originSchema);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DatabaseOperateBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DatabaseOperateBackendHandlerFactory.java
index 85c36e4..8e05d36 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DatabaseOperateBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/DatabaseOperateBackendHandlerFactory.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.text.database;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement;
@@ -41,11 +41,11 @@ public final class DatabaseOperateBackendHandlerFactory {
* @return database operate backend handler
* @throws SQLException SQL exception
*/
- public static TextProtocolBackendHandler newInstance(final SQLStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static TextProtocolBackendHandler newInstance(final SQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
return createBackendHandler(sqlStatement, connectionSession);
}
- private static TextProtocolBackendHandler createBackendHandler(final SQLStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ private static TextProtocolBackendHandler createBackendHandler(final SQLStatement sqlStatement, final ConnectionSession connectionSession) {
if (sqlStatement instanceof CreateDatabaseStatement) {
return new CreateDatabaseBackendHandler((CreateDatabaseStatement) sqlStatement);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
index 7b1eec2..5860965 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactory.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.distsql.parser.statement.rdl.RDLStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.RQLStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+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.RALBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.RDLBackendHandlerFactory;
@@ -48,7 +48,7 @@ public final class DistSQLBackendHandlerFactory {
* @return text protocol backend handler
* @throws SQLException SQL exception
*/
- public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final DistSQLStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final DistSQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
if (sqlStatement instanceof RQLStatement) {
return RQLBackendHandlerFactory.newInstance((RQLStatement) sqlStatement, connectionSession);
}
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 bea581f..bd8ad32 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
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatem
import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableRALStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+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.advanced.AdvancedDistSQLBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.query.QueryableRALBackendHandlerFactory;
@@ -49,7 +49,7 @@ public final class RALBackendHandlerFactory {
* @return RAL backend handler
* @throws SQLException SQL exception
*/
- public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final RALStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final RALStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
if (sqlStatement instanceof QueryableRALStatement) {
return QueryableRALBackendHandlerFactory.newInstance((QueryableRALStatement) sqlStatement, connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/AdvancedDistSQLBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/AdvancedDistSQLBackendHandlerFactory.java
index b3ebe1f..508fc1f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/AdvancedDistSQLBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advanced/AdvancedDistSQLBackendHandlerFactory.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.AdvancedDistSQLSta
import org.apache.shardingsphere.distsql.parser.statement.ral.advanced.parse.ParseStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.advanced.preview.PreviewStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import java.sql.SQLException;
@@ -45,7 +45,7 @@ public final class AdvancedDistSQLBackendHandlerFactory {
* @throws SQLException SQL exception
*/
public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final AdvancedDistSQLStatement sqlStatement,
- final JDBCConnectionSession connectionSession) throws SQLException {
+ final ConnectionSession connectionSession) throws SQLException {
if (sqlStatement instanceof PreviewStatement) {
return new PreviewDistSQLBackendHandler((PreviewStatement) sqlStatement, connectionSession);
} else if (sqlStatement instanceof ParseStatement) {
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 c61e1c0..6e6cfac 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
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.common.HintDistSQL
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.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import java.sql.SQLException;
@@ -44,7 +44,7 @@ public final class CommonDistSQLBackendHandlerFactory {
* @return common dist sql backend handler
* @throws SQLException SQL exception
*/
- public static TextProtocolBackendHandler newInstance(final CommonDistSQLStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static TextProtocolBackendHandler newInstance(final CommonDistSQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
if (sqlStatement instanceof SetDistSQLStatement) {
return new SetDistSQLBackendHandler((SetDistSQLStatement) sqlStatement, connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/HintDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/HintDistSQLBackendHandler.java
index 1a4f748..b407f88 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/HintDistSQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/HintDistSQLBackendHandler.java
@@ -21,9 +21,9 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.HintDistSQLStatement;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
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.hint.HintStatementExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.HintStatementExecutorFactory;
@@ -40,7 +40,7 @@ public final class HintDistSQLBackendHandler implements TextProtocolBackendHandl
private final HintDistSQLStatement sqlStatement;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
private HintStatementExecutor hintStatementExecutor;
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/RefreshTableMetadataHandler.java
index e809bf9..a8e1f3e 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/RefreshTableMetadataHandler.java
@@ -20,10 +20,10 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common;
import lombok.Getter;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.RefreshTableMetadataStatement;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.SchemaRequiredBackendHandler;
import java.sql.SQLException;
@@ -34,7 +34,7 @@ import java.sql.SQLException;
@Getter
public final class RefreshTableMetadataHandler extends SchemaRequiredBackendHandler<RefreshTableMetadataStatement> {
- public RefreshTableMetadataHandler(final RefreshTableMetadataStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ public RefreshTableMetadataHandler(final RefreshTableMetadataStatement sqlStatement, final ConnectionSession connectionSession) {
super(sqlStatement, connectionSession);
}
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
index 51a207d..02a9684 100644
--- 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
@@ -20,8 +20,8 @@ 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.communication.jdbc.connection.JDBCConnectionSession;
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;
@@ -37,7 +37,7 @@ public final class SetDistSQLBackendHandler implements TextProtocolBackendHandle
private final SetDistSQLStatement sqlStatement;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
@Override
public ResponseHeader execute() throws SQLException {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java
index 536df4f..6b307bc 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/ShowDistSQLBackendHandler.java
@@ -20,8 +20,8 @@ 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.ShowDistSQLStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.show.ShowStatementExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.ShowStatementExecutorFactory;
@@ -38,7 +38,7 @@ public final class ShowDistSQLBackendHandler implements TextProtocolBackendHandl
private final ShowDistSQLStatement sqlStatement;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
private ShowStatementExecutor showStatementExecutor;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactory.java
index e8943e3..ac1111b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactory.java
@@ -22,7 +22,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.HintDistSQLStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.hint.ClearHintStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.executor.AddShardingHintDatabaseValueExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.executor.AddShardingHintTableValueExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.executor.ClearHintExecutor;
@@ -57,7 +57,7 @@ public final class HintStatementExecutorFactory {
* @return hint command executor
* @throws SQLException SQL exception
*/
- public static HintStatementExecutor newInstance(final HintDistSQLStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static HintStatementExecutor newInstance(final HintDistSQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
if (sqlStatement instanceof SetReadwriteSplittingHintStatement) {
return new SetReadwriteSplittingHintExecutor((SetReadwriteSplittingHintStatement) sqlStatement);
}
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
index 71dd10e..84e9fda 100644
--- 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
@@ -21,7 +21,7 @@ import com.mchange.v1.db.sql.UnsupportedTypeException;
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.communication.jdbc.connection.JDBCConnectionSession;
+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;
@@ -42,7 +42,7 @@ public final class SetStatementExecutorFactory {
* @return set command executor
* @throws SQLException SQL exception
*/
- public static SetStatementExecutor newInstance(final SetDistSQLStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static SetStatementExecutor newInstance(final SetDistSQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
if (sqlStatement instanceof SetVariableStatement) {
return new SetVariableExecutor((SetVariableStatement) sqlStatement, connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java
index 8658bda..0d40af5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.common.ShowDistSQL
import org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowAllVariablesStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowInstanceStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowVariableStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor.ShowAllVariablesExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor.ShowInstanceExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor.ShowReadwriteSplittingReadResourcesExecutor;
@@ -44,7 +44,7 @@ public final class ShowStatementExecutorFactory {
* @return show command executor
* @throws SQLException SQL exception
*/
- public static ShowStatementExecutor newInstance(final ShowDistSQLStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static ShowStatementExecutor newInstance(final ShowDistSQLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
if (sqlStatement instanceof ShowInstanceStatement) {
return new ShowInstanceExecutor();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowAllVariablesExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowAllVariablesExecutor.java
index 2b94278..0388900 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowAllVariablesExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowAllVariablesExecutor.java
@@ -21,9 +21,10 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.util.SystemPropertyUtil;
import org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
@@ -39,7 +40,7 @@ import java.util.List;
@RequiredArgsConstructor
public final class ShowAllVariablesExecutor extends AbstractShowExecutor {
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
@Override
protected List<QueryHeader> createQueryHeaders() {
@@ -58,7 +59,9 @@ public final class ShowAllVariablesExecutor extends AbstractShowExecutor {
rows.add(Arrays.asList(each.toLowerCase(), propertyValue));
});
rows.add(Arrays.asList(VariableEnum.AGENT_PLUGINS_ENABLED.name().toLowerCase(), SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), Boolean.FALSE.toString())));
- rows.add(Arrays.asList(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(), connectionSession.getConnectionSize()));
+ if (connectionSession.getBackendConnection() instanceof JDBCBackendConnection) {
+ rows.add(Arrays.asList(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(), ((JDBCBackendConnection) connectionSession.getBackendConnection()).getConnectionSize()));
+ }
rows.add(Arrays.asList(VariableEnum.TRANSACTION_TYPE.name().toLowerCase(), connectionSession.getTransactionStatus().getTransactionType().name()));
return new MultipleLocalDataMergedResult(rows);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowVariableExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowVariableExecutor.java
index 0ebb137..c8fdc48 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowVariableExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowVariableExecutor.java
@@ -23,13 +23,15 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowVa
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
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.util.SystemPropertyUtil;
import org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
+import org.apache.shardingsphere.transaction.core.TransactionType;
import java.sql.Types;
import java.util.Collections;
@@ -44,7 +46,7 @@ public final class ShowVariableExecutor extends AbstractShowExecutor {
private final ShowVariableStatement sqlStatement;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
@Override
protected List<QueryHeader> createQueryHeaders() {
@@ -63,11 +65,16 @@ public final class ShowVariableExecutor extends AbstractShowExecutor {
case AGENT_PLUGINS_ENABLED:
return new MultipleLocalDataMergedResult(Collections.singletonList(Collections.singletonList(SystemPropertyUtil.getSystemProperty(variable.name(), Boolean.FALSE.toString()))));
case CACHED_CONNECTIONS:
- return new MultipleLocalDataMergedResult(Collections.singletonList(Collections.singletonList(connectionSession.getConnectionSize())));
+ if (connectionSession.getBackendConnection() instanceof JDBCBackendConnection) {
+ int connectionSize = ((JDBCBackendConnection) connectionSession.getBackendConnection()).getConnectionSize();
+ return new MultipleLocalDataMergedResult(Collections.singletonList(Collections.singletonList(connectionSize)));
+ }
+ break;
case TRANSACTION_TYPE:
- return new MultipleLocalDataMergedResult(Collections.singletonList(Collections.singletonList(connectionSession.getTransactionStatus().getTransactionType().name())));
+ TransactionType transactionType = connectionSession.getTransactionStatus().getTransactionType();
+ return new MultipleLocalDataMergedResult(Collections.singletonList(Collections.singletonList(transactionType.name())));
default:
- throw new UnsupportedVariableException(sqlStatement.getName());
}
+ throw new UnsupportedVariableException(sqlStatement.getName());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandler.java
index 4f3e3ea..1d3bcfd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandler.java
@@ -19,11 +19,11 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.query;
import org.apache.shardingsphere.distsql.parser.statement.ral.RALStatement;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
import java.sql.Types;
@@ -38,7 +38,7 @@ public final class QueryableRALBackendHandler extends SchemaRequiredBackendHandl
private final DistSQLResultSet resultSet;
- public QueryableRALBackendHandler(final RALStatement sqlStatement, final JDBCConnectionSession connectionSession, final DistSQLResultSet resultSet) {
+ public QueryableRALBackendHandler(final RALStatement sqlStatement, final ConnectionSession connectionSession, final DistSQLResultSet resultSet) {
super(sqlStatement, connectionSession);
this.resultSet = resultSet;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandlerFactory.java
index b9f5f77..7aae25f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/query/QueryableRALBackendHandlerFactory.java
@@ -21,7 +21,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
@@ -45,7 +45,7 @@ public final class QueryableRALBackendHandlerFactory {
* @param connectionSession connection session
* @return queryable RAL backend handler
*/
- public static TextProtocolBackendHandler newInstance(final QueryableRALStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ public static TextProtocolBackendHandler newInstance(final QueryableRALStatement sqlStatement, final ConnectionSession connectionSession) {
DistSQLResultSet resultSet = TypedSPIRegistry.getRegisteredService(DistSQLResultSet.class, sqlStatement.getClass().getCanonicalName(), new Properties());
return new QueryableRALBackendHandler(sqlStatement, connectionSession, resultSet);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
index 34e27a4..c12f92d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/RDLBackendHandlerFactory.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.distsql.parser.statement.rdl.alter.AlterResourc
import org.apache.shardingsphere.distsql.parser.statement.rdl.create.AddResourceStatement;
import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropResourceStatement;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource.AddResourceBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource.AlterResourceBackendHandler;
@@ -49,11 +49,11 @@ public final class RDLBackendHandlerFactory {
* @return RDL backend handler
* @throws SQLException SQL exception
*/
- public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final RDLStatement sqlStatement, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static TextProtocolBackendHandler newInstance(final DatabaseType databaseType, final RDLStatement sqlStatement, final ConnectionSession connectionSession) throws SQLException {
return createBackendHandler(databaseType, sqlStatement, connectionSession);
}
- private static TextProtocolBackendHandler createBackendHandler(final DatabaseType databaseType, final RDLStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ private static TextProtocolBackendHandler createBackendHandler(final DatabaseType databaseType, final RDLStatement sqlStatement, final ConnectionSession connectionSession) {
if (sqlStatement instanceof AddResourceStatement) {
return new AddResourceBackendHandler(databaseType, (AddResourceStatement) sqlStatement, connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
index 8a08301..1494a3d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
@@ -26,10 +26,10 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.resource.DuplicateResourceException;
import org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourcesException;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.SchemaRequiredBackendHandler;
import java.sql.SQLException;
@@ -49,7 +49,7 @@ public final class AddResourceBackendHandler extends SchemaRequiredBackendHandle
private final DataSourceConfigurationValidator dataSourceConfigValidator;
- public AddResourceBackendHandler(final DatabaseType databaseType, final AddResourceStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ public AddResourceBackendHandler(final DatabaseType databaseType, final AddResourceStatement sqlStatement, final ConnectionSession connectionSession) {
super(sqlStatement, connectionSession);
this.databaseType = databaseType;
dataSourceConfigValidator = new DataSourceConfigurationValidator();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
index 4fc24e5..000587d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
@@ -27,10 +27,10 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.resource.DuplicateResourceException;
import org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourcesException;
import org.apache.shardingsphere.infra.distsql.exception.resource.RequiredResourceMissedException;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.SchemaRequiredBackendHandler;
import javax.sql.DataSource;
@@ -49,7 +49,7 @@ public final class AlterResourceBackendHandler extends SchemaRequiredBackendHand
private final DataSourceConfigurationValidator dataSourceConfigValidator;
- public AlterResourceBackendHandler(final DatabaseType databaseType, final AlterResourceStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ public AlterResourceBackendHandler(final DatabaseType databaseType, final AlterResourceStatement sqlStatement, final ConnectionSession connectionSession) {
super(sqlStatement, connectionSession);
this.databaseType = databaseType;
dataSourceConfigValidator = new DataSourceConfigurationValidator();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandler.java
index f6eea72..739fac1 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandler.java
@@ -27,10 +27,10 @@ import org.apache.shardingsphere.infra.distsql.exception.resource.ResourceInUsed
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.SchemaRequiredBackendHandler;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
@@ -46,7 +46,7 @@ import java.util.stream.Collectors;
*/
public final class DropResourceBackendHandler extends SchemaRequiredBackendHandler<DropResourceStatement> {
- public DropResourceBackendHandler(final DropResourceStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ public DropResourceBackendHandler(final DropResourceStatement sqlStatement, final ConnectionSession connectionSession) {
super(sqlStatement, connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
index b99c4c6..edb4fec 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/rule/RuleDefinitionBackendHandler.java
@@ -26,10 +26,10 @@ import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdate
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.SchemaRequiredBackendHandler;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
@@ -51,7 +51,7 @@ public final class RuleDefinitionBackendHandler<T extends RuleDefinitionStatemen
ShardingSphereServiceLoader.register(RuleDefinitionAlterPreprocessor.class);
}
- public RuleDefinitionBackendHandler(final T sqlStatement, final JDBCConnectionSession connectionSession) {
+ public RuleDefinitionBackendHandler(final T sqlStatement, final ConnectionSession connectionSession) {
super(sqlStatement, connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandler.java
index 46ccc2d..9a101ef 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandler.java
@@ -19,11 +19,11 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.rql;
import org.apache.shardingsphere.distsql.parser.statement.rql.RQLStatement;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
import java.sql.Types;
@@ -38,7 +38,7 @@ public final class RQLBackendHandler extends SchemaRequiredBackendHandler<RQLSta
private final DistSQLResultSet resultSet;
- public RQLBackendHandler(final RQLStatement sqlStatement, final JDBCConnectionSession connectionSession, final DistSQLResultSet resultSet) {
+ public RQLBackendHandler(final RQLStatement sqlStatement, final ConnectionSession connectionSession, final DistSQLResultSet resultSet) {
super(sqlStatement, connectionSession);
this.resultSet = resultSet;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerFactory.java
index d907e6f..1fe6330 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerFactory.java
@@ -21,7 +21,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.distsql.parser.statement.rql.RQLStatement;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.typed.TypedSPIRegistry;
@@ -45,7 +45,7 @@ public final class RQLBackendHandlerFactory {
* @param connectionSession connection session
* @return RDL backend handler
*/
- public static TextProtocolBackendHandler newInstance(final RQLStatement sqlStatement, final JDBCConnectionSession connectionSession) {
+ public static TextProtocolBackendHandler newInstance(final RQLStatement sqlStatement, final ConnectionSession connectionSession) {
DistSQLResultSet resultSet = TypedSPIRegistry.getRegisteredService(DistSQLResultSet.class, sqlStatement.getClass().getCanonicalName(), new Properties());
return new RQLBackendHandler(sqlStatement, connectionSession, resultSet);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandler.java
index 5592050..b2bb94a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandler.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.backend.text.transaction;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
@@ -46,11 +46,11 @@ public final class TransactionBackendHandler implements TextProtocolBackendHandl
private final ConnectionSession connectionSession;
- public TransactionBackendHandler(final TCLStatement tclStatement, final TransactionOperationType operationType, final JDBCConnectionSession connectionSession) {
+ public TransactionBackendHandler(final TCLStatement tclStatement, final TransactionOperationType operationType, final ConnectionSession connectionSession) {
this.tclStatement = tclStatement;
this.operationType = operationType;
this.connectionSession = connectionSession;
- backendTransactionManager = new BackendTransactionManager(connectionSession);
+ backendTransactionManager = new BackendTransactionManager((JDBCBackendConnection) connectionSession.getBackendConnection());
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java
index 1babbbe..7fa8da6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactory.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.backend.text.transaction;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseBackendHandler;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.BeginTransactionStatement;
@@ -47,7 +47,7 @@ public final class TransactionBackendHandlerFactory {
* @param connectionSession connection session
* @return backend handler
*/
- public static TextProtocolBackendHandler newInstance(final SQLStatementContext<? extends TCLStatement> sqlStatementContext, final String sql, final JDBCConnectionSession connectionSession) {
+ public static TextProtocolBackendHandler newInstance(final SQLStatementContext<? extends TCLStatement> sqlStatementContext, final String sql, final ConnectionSession connectionSession) {
TCLStatement tclStatement = sqlStatementContext.getSqlStatement();
if (tclStatement instanceof BeginTransactionStatement) {
return new TransactionBackendHandler(tclStatement, TransactionOperationType.BEGIN, connectionSession);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
index 148f6c5..87896e9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerCon
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.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.junit.Before;
import org.junit.Test;
@@ -54,9 +54,6 @@ public final class DatabaseCommunicationEngineFactoryTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
- JDBCConnectionSession connectionSession = mock(JDBCConnectionSession.class, RETURNS_DEEP_STUBS);
- when(connectionSession.getSchemaName()).thenReturn("schema");
- when(connectionSession.isSerialExecute()).thenReturn(true);
}
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
@@ -68,18 +65,18 @@ public final class DatabaseCommunicationEngineFactoryTest {
@Test
public void assertNewTextProtocolInstance() {
- JDBCConnectionSession connectionSession = mock(JDBCConnectionSession.class);
- when(connectionSession.getSchemaName()).thenReturn("schema");
- DatabaseCommunicationEngine engine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(mock(SQLStatementContext.class), "schemaName", connectionSession);
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class, RETURNS_DEEP_STUBS);
+ when(backendConnection.getConnectionSession().getSchemaName()).thenReturn("schema");
+ DatabaseCommunicationEngine engine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(mock(SQLStatementContext.class), "schemaName", backendConnection);
assertThat(engine, instanceOf(DatabaseCommunicationEngine.class));
}
@Test
public void assertNewBinaryProtocolInstance() {
- JDBCConnectionSession connectionSession = mock(JDBCConnectionSession.class);
- when(connectionSession.getSchemaName()).thenReturn("schema");
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class, RETURNS_DEEP_STUBS);
+ when(backendConnection.getConnectionSession().getSchemaName()).thenReturn("schema");
DatabaseCommunicationEngine engine =
- DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), connectionSession);
+ DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), backendConnection);
assertThat(engine, instanceOf(DatabaseCommunicationEngine.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java
index f1ddbe7..7118d1d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineTest.java
@@ -37,13 +37,14 @@ import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
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.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeaderBuilder;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.internal.util.reflection.FieldSetter;
import org.mockito.junit.MockitoJUnitRunner;
@@ -75,8 +76,8 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class DatabaseCommunicationEngineTest {
- @Mock
- private JDBCConnectionSession connectionSession;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private JDBCBackendConnection backendConnection;
@Mock
private Statement statement;
@@ -86,7 +87,7 @@ public final class DatabaseCommunicationEngineTest {
@Before
public void setUp() {
- when(connectionSession.getSchemaName()).thenReturn("schema");
+ when(backendConnection.getConnectionSession().getSchemaName()).thenReturn("schema");
MetaDataContexts metaDataContexts = new MetaDataContexts(
mock(MetaDataPersistService.class), mockMetaDataMap(), mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class),
new ConfigurationProperties(new Properties()), mock(OptimizerContext.class, RETURNS_DEEP_STUBS));
@@ -105,7 +106,7 @@ public final class DatabaseCommunicationEngineTest {
@Test
public void assertBinaryProtocolQueryHeader() throws SQLException, NoSuchFieldException {
DatabaseCommunicationEngine engine =
- DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), connectionSession);
+ DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), backendConnection);
assertNotNull(engine);
assertThat(engine, instanceOf(DatabaseCommunicationEngine.class));
Field queryHeadersField = engine.getClass().getDeclaredField("queryHeaders");
@@ -161,7 +162,7 @@ public final class DatabaseCommunicationEngineTest {
@Test
public void assertAddStatementCorrectly() {
DatabaseCommunicationEngine engine =
- DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), connectionSession);
+ DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), backendConnection);
engine.add(statement);
Collection<?> actual = getField(engine, "cachedStatements");
assertThat(actual.size(), is(1));
@@ -171,7 +172,7 @@ public final class DatabaseCommunicationEngineTest {
@Test
public void assertAddResultSetCorrectly() {
DatabaseCommunicationEngine engine =
- DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), connectionSession);
+ DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), backendConnection);
engine.add(resultSet);
Collection<?> actual = getField(engine, "cachedResultSets");
assertThat(actual.size(), is(1));
@@ -181,7 +182,7 @@ public final class DatabaseCommunicationEngineTest {
@Test
public void assertCloseCorrectly() throws SQLException {
DatabaseCommunicationEngine engine =
- DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), connectionSession);
+ DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), backendConnection);
Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");
cachedResultSets.add(resultSet);
Collection<Statement> cachedStatements = getField(engine, "cachedStatements");
@@ -196,7 +197,7 @@ public final class DatabaseCommunicationEngineTest {
@Test
public void assertCloseResultSetsWithExceptionThrown() throws SQLException {
DatabaseCommunicationEngine engine =
- DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), connectionSession);
+ DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(mock(SQLStatementContext.class), "schemaName", Collections.emptyList(), backendConnection);
Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");
SQLException sqlExceptionByResultSet = new SQLException("ResultSet");
doThrow(sqlExceptionByResultSet).when(resultSet).close();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java
index f9ba599..5684461 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/ProxySQLExecutorTest.java
@@ -25,8 +25,9 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriv
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.route.context.RouteContext;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.exception.TableModifyInTransactionException;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
@@ -51,26 +52,31 @@ import static org.mockito.Mockito.when;
public final class ProxySQLExecutorTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
@Before
public void setUp() {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.XA);
when(connectionSession.getTransactionStatus().isInTransaction()).thenReturn(true);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
}
@Test(expected = TableModifyInTransactionException.class)
public void assertCheckExecutePrerequisitesWhenExecuteDDLInXATransaction() {
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
@Test
public void assertCheckExecutePrerequisitesWhenExecuteDMLInXATransaction() {
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createMySQLInsertStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -78,7 +84,7 @@ public final class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.BASE);
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -86,7 +92,7 @@ public final class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().isInTransaction()).thenReturn(false);
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
@Test(expected = TableModifyInTransactionException.class)
@@ -94,7 +100,7 @@ public final class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createPostgreSQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -102,7 +108,7 @@ public final class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createPostgreSQLInsertStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -110,7 +116,7 @@ public final class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -119,7 +125,7 @@ public final class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().isInTransaction()).thenReturn(false);
ExecutionContext executionContext = new ExecutionContext(
new LogicSQL(createPostgreSQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, connectionSession, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseCommunicationEngine.class)).checkExecutePrerequisites(executionContext);
}
private CreateTableStatementContext createMySQLCreateTableStatementContext() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCConnectionSessionTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
similarity index 78%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCConnectionSessionTest.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
index c6700fb..5d38340 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCConnectionSessionTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnectionTest.java
@@ -18,23 +18,23 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.connection;
import com.google.common.collect.Multimap;
-import io.netty.util.DefaultAttributeMap;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -42,6 +42,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@@ -70,25 +71,32 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
-public final class JDBCConnectionSessionTest {
+public final class JDBCBackendConnectionTest {
private static final String SCHEMA_PATTERN = "schema_%s";
@Mock
private JDBCBackendDataSource backendDataSource;
- private final JDBCConnectionSession connectionSession = new JDBCConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ConnectionSession connectionSession;
+
+ private JDBCBackendConnection backendConnection;
@Before
public void setUp() throws ReflectiveOperationException {
setContextManager();
setBackendDataSource();
- connectionSession.setCurrentSchema(String.format(SCHEMA_PATTERN, 0));
+ when(connectionSession.getSchemaName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
+ backendConnection = spy(new JDBCBackendConnection(connectionSession));
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(connectionSession.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.LOCAL));
}
private void setContextManager() throws ReflectiveOperationException {
@@ -143,30 +151,30 @@ public final class JDBCConnectionSessionTest {
public void assertGetConnectionCacheIsEmpty() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
when(backendDataSource.getConnections(anyString(), anyString(), eq(2), any())).thenReturn(MockConnectionUtil.mockNewConnections(2));
- List<Connection> actualConnections = connectionSession.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actualConnections = backendConnection.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
assertThat(actualConnections.size(), is(2));
- assertThat(connectionSession.getConnectionSize(), is(2));
+ assertThat(backendConnection.getConnectionSize(), is(2));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@Test
public void assertGetConnectionSizeLessThanCache() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
- MockConnectionUtil.setCachedConnections(connectionSession, "ds1", 10);
- List<Connection> actualConnections = connectionSession.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
+ MockConnectionUtil.setCachedConnections(backendConnection, "ds1", 10);
+ List<Connection> actualConnections = backendConnection.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
assertThat(actualConnections.size(), is(2));
- assertThat(connectionSession.getConnectionSize(), is(10));
+ assertThat(backendConnection.getConnectionSize(), is(10));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@Test
public void assertGetConnectionSizeGreaterThanCache() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
- MockConnectionUtil.setCachedConnections(connectionSession, "ds1", 10);
+ MockConnectionUtil.setCachedConnections(backendConnection, "ds1", 10);
when(backendDataSource.getConnections(anyString(), anyString(), eq(2), any())).thenReturn(MockConnectionUtil.mockNewConnections(2));
- List<Connection> actualConnections = connectionSession.getConnections("ds1", 12, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actualConnections = backendConnection.getConnections("ds1", 12, ConnectionMode.MEMORY_STRICTLY);
assertThat(actualConnections.size(), is(12));
- assertThat(connectionSession.getConnectionSize(), is(12));
+ assertThat(backendConnection.getConnectionSize(), is(12));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@@ -175,8 +183,8 @@ public final class JDBCConnectionSessionTest {
connectionSession.getTransactionStatus().setInTransaction(true);
when(backendDataSource.getConnections(anyString(), anyString(), eq(2), any())).thenReturn(MockConnectionUtil.mockNewConnections(2));
setConnectionPostProcessors();
- List<Connection> actualConnections = connectionSession.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
- verify(connectionSession.getConnectionPostProcessors().iterator().next(), times(2)).process(any());
+ List<Connection> actualConnections = backendConnection.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
+ verify(backendConnection.getConnectionPostProcessors().iterator().next(), times(2)).process(any());
assertThat(actualConnections.size(), is(2));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@@ -186,14 +194,14 @@ public final class JDBCConnectionSessionTest {
ConnectionPostProcessor invocation = mock(ConnectionPostProcessor.class);
Collection<ConnectionPostProcessor> connectionPostProcessors = new LinkedList<>();
connectionPostProcessors.add(invocation);
- Field field = connectionSession.getClass().getDeclaredField("connectionPostProcessors");
+ Field field = JDBCBackendConnection.class.getDeclaredField("connectionPostProcessors");
field.setAccessible(true);
- field.set(connectionSession, connectionPostProcessors);
+ field.set(backendConnection, connectionPostProcessors);
}
@Test
public void assertMultiThreadsGetConnection() throws SQLException, InterruptedException {
- MockConnectionUtil.setCachedConnections(connectionSession, "ds1", 10);
+ MockConnectionUtil.setCachedConnections(backendConnection, "ds1", 10);
when(backendDataSource.getConnections(anyString(), anyString(), eq(2), any())).thenReturn(MockConnectionUtil.mockNewConnections(2));
Thread thread1 = new Thread(this::assertOneThreadResult);
Thread thread2 = new Thread(this::assertOneThreadResult);
@@ -206,72 +214,58 @@ public final class JDBCConnectionSessionTest {
@SneakyThrows(SQLException.class)
private void assertOneThreadResult() {
connectionSession.getTransactionStatus().setInTransaction(true);
- List<Connection> actualConnections = connectionSession.getConnections("ds1", 12, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actualConnections = backendConnection.getConnections("ds1", 12, ConnectionMode.MEMORY_STRICTLY);
assertThat(actualConnections.size(), is(12));
- assertThat(connectionSession.getConnectionSize(), is(12));
+ assertThat(backendConnection.getConnectionSize(), is(12));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
- @Test(expected = ShardingSphereException.class)
- public void assertFailedSwitchTransactionTypeWhileBegin() throws SQLException {
- BackendTransactionManager transactionManager = new BackendTransactionManager(connectionSession);
- transactionManager.begin();
- connectionSession.getTransactionStatus().setTransactionType(TransactionType.XA);
- }
-
- @Test(expected = ShardingSphereException.class)
- public void assertFailedSwitchSchemaWhileBegin() throws SQLException {
- BackendTransactionManager transactionManager = new BackendTransactionManager(connectionSession);
- transactionManager.begin();
- connectionSession.setCurrentSchema("newSchema");
- }
-
@Test
public void assertIsNotSerialExecuteWhenNotInTransaction() {
connectionSession.getTransactionStatus().setInTransaction(false);
- assertFalse(connectionSession.isSerialExecute());
+ assertFalse(backendConnection.isSerialExecute());
}
@Test
public void assertIsNotSerialExecuteWhenInTransactionAndBaseTransactionType() {
connectionSession.getTransactionStatus().setInTransaction(false);
connectionSession.getTransactionStatus().setTransactionType(TransactionType.BASE);
- assertFalse(connectionSession.isSerialExecute());
+ assertFalse(backendConnection.isSerialExecute());
}
@Test
public void assertIsSerialExecuteWhenInTransactionAndLocalTransactionType() {
connectionSession.getTransactionStatus().setTransactionType(TransactionType.LOCAL);
connectionSession.getTransactionStatus().setInTransaction(true);
- assertTrue(connectionSession.isSerialExecute());
+ assertTrue(backendConnection.isSerialExecute());
}
@Test
public void assertIsSerialExecuteWhenInTransactionAndXaTransactionType() {
connectionSession.getTransactionStatus().setTransactionType(TransactionType.XA);
connectionSession.getTransactionStatus().setInTransaction(true);
- assertTrue(connectionSession.isSerialExecute());
+ assertTrue(backendConnection.isSerialExecute());
}
@Test
public void assertSetFetchSizeAsExpected() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, SQLException {
Statement statement = mock(Statement.class);
- Method setFetchSizeMethod = connectionSession.getClass().getDeclaredMethod("setFetchSize", Statement.class);
+ Method setFetchSizeMethod = JDBCBackendConnection.class.getDeclaredMethod("setFetchSize", Statement.class);
setFetchSizeMethod.setAccessible(true);
- setFetchSizeMethod.invoke(connectionSession, statement);
+ setFetchSizeMethod.invoke(backendConnection, statement);
verify(statement, times(1)).setFetchSize(Integer.MIN_VALUE);
}
@Test
public void assertCloseConnectionsCorrectlyWhenNotForceRollback() throws NoSuchFieldException, IllegalAccessException, SQLException {
- Field field = connectionSession.getClass().getDeclaredField("cachedConnections");
+ Field field = JDBCBackendConnection.class.getDeclaredField("cachedConnections");
field.setAccessible(true);
- Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) field.get(connectionSession);
+ Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) field.get(backendConnection);
Connection connection = prepareCachedConnections();
cachedConnections.put("ignoredDataSourceName", connection);
ConnectionStatus connectionStatus = mock(ConnectionStatus.class);
prepareConnectionStatus(connectionStatus);
- connectionSession.closeConnections(false);
+ backendConnection.closeConnections(false);
verify(connection, times(1)).close();
assertTrue(cachedConnections.isEmpty());
verifyConnectionPostProcessorsEmpty();
@@ -283,7 +277,7 @@ public final class JDBCConnectionSessionTest {
prepareConnectionStatus(connectionStatus);
connectionSession.getTransactionStatus().setInTransaction(false);
Connection connection = prepareCachedConnections();
- connectionSession.closeConnections(true);
+ backendConnection.closeConnections(true);
verify(connection, never()).rollback();
}
@@ -293,7 +287,7 @@ public final class JDBCConnectionSessionTest {
prepareConnectionStatus(connectionStatus);
connectionSession.getTransactionStatus().setInTransaction(true);
Connection connection = prepareCachedConnections();
- connectionSession.closeConnections(true);
+ backendConnection.closeConnections(true);
verify(connection, times(1)).rollback();
}
@@ -304,7 +298,7 @@ public final class JDBCConnectionSessionTest {
Connection connection = prepareCachedConnections();
SQLException sqlException = new SQLException("");
doThrow(sqlException).when(connection).close();
- assertTrue(connectionSession.closeConnections(false).contains(sqlException));
+ assertTrue(backendConnection.closeConnections(false).contains(sqlException));
}
@Test
@@ -312,7 +306,7 @@ public final class JDBCConnectionSessionTest {
Connection connection = mock(Connection.class);
Statement statement = mock(Statement.class);
when(connection.createStatement()).thenReturn(statement);
- assertThat(connectionSession.createStorageResource(connection, ConnectionMode.MEMORY_STRICTLY, null), is(statement));
+ assertThat(backendConnection.createStorageResource(connection, ConnectionMode.MEMORY_STRICTLY, null), is(statement));
verify(connection, times(1)).createStatement();
}
@@ -321,7 +315,7 @@ public final class JDBCConnectionSessionTest {
connectionSession.getTransactionStatus().setInTransaction(false);
List<Connection> connections = MockConnectionUtil.mockNewConnections(1);
when(backendDataSource.getConnections(anyString(), anyString(), eq(1), any())).thenReturn(connections);
- List<Connection> fetchedConnections = connectionSession.getConnections("ds1", 1, null);
+ List<Connection> fetchedConnections = backendConnection.getConnections("ds1", 1, null);
assertThat(fetchedConnections.size(), is(1));
assertTrue(fetchedConnections.contains(connections.get(0)));
assertConnectionsCached("ds1", connections);
@@ -330,9 +324,9 @@ public final class JDBCConnectionSessionTest {
@SuppressWarnings("unchecked")
@SneakyThrows(ReflectiveOperationException.class)
private void assertConnectionsCached(final String dataSourceName, final Collection<Connection> connections) {
- Field field = connectionSession.getClass().getDeclaredField("cachedConnections");
+ Field field = JDBCBackendConnection.class.getDeclaredField("cachedConnections");
field.setAccessible(true);
- Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) field.get(connectionSession);
+ Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) field.get(backendConnection);
assertTrue(cachedConnections.containsKey(dataSourceName));
assertArrayEquals(cachedConnections.get(dataSourceName).toArray(), connections.toArray());
}
@@ -340,9 +334,9 @@ public final class JDBCConnectionSessionTest {
@SuppressWarnings("unchecked")
@SneakyThrows(ReflectiveOperationException.class)
private Connection prepareCachedConnections() {
- Field field = connectionSession.getClass().getDeclaredField("cachedConnections");
+ Field field = JDBCBackendConnection.class.getDeclaredField("cachedConnections");
field.setAccessible(true);
- Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) field.get(connectionSession);
+ Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) field.get(backendConnection);
Connection connection = mock(Connection.class);
cachedConnections.put("ignoredDataSourceName", connection);
return connection;
@@ -350,24 +344,24 @@ public final class JDBCConnectionSessionTest {
@SneakyThrows(ReflectiveOperationException.class)
private void prepareConnectionStatus(final ConnectionStatus connectionStatus) {
- Field field = connectionSession.getClass().getDeclaredField("connectionStatus");
+ Field field = JDBCBackendConnection.class.getDeclaredField("connectionStatus");
field.setAccessible(true);
- field.set(connectionSession, connectionStatus);
+ field.set(backendConnection, connectionStatus);
}
@SuppressWarnings("unchecked")
@SneakyThrows(ReflectiveOperationException.class)
private void verifyConnectionPostProcessorsEmpty() {
- Field field = connectionSession.getClass().getDeclaredField("connectionPostProcessors");
+ Field field = JDBCBackendConnection.class.getDeclaredField("connectionPostProcessors");
field.setAccessible(true);
- Collection<ConnectionPostProcessor> connectionPostProcessors = (Collection<ConnectionPostProcessor>) field.get(connectionSession);
+ Collection<ConnectionPostProcessor> connectionPostProcessors = (Collection<ConnectionPostProcessor>) field.get(backendConnection);
assertTrue(connectionPostProcessors.isEmpty());
}
@Test
public void assertAddDatabaseCommunicationEngine() {
DatabaseCommunicationEngine expectedEngine = mock(DatabaseCommunicationEngine.class);
- connectionSession.add(expectedEngine);
+ backendConnection.add(expectedEngine);
Collection<DatabaseCommunicationEngine> actual = getDatabaseCommunicationEngines();
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(), is(expectedEngine));
@@ -376,8 +370,8 @@ public final class JDBCConnectionSessionTest {
@Test
public void assertMarkDatabaseCommunicationEngineInUse() {
DatabaseCommunicationEngine expectedEngine = mock(DatabaseCommunicationEngine.class);
- connectionSession.add(expectedEngine);
- connectionSession.markResourceInUse(expectedEngine);
+ backendConnection.add(expectedEngine);
+ backendConnection.markResourceInUse(expectedEngine);
Collection<DatabaseCommunicationEngine> actual = getInUseDatabaseCommunicationEngines();
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(), is(expectedEngine));
@@ -388,7 +382,7 @@ public final class JDBCConnectionSessionTest {
DatabaseCommunicationEngine engine = mock(DatabaseCommunicationEngine.class);
Collection<DatabaseCommunicationEngine> actual = getInUseDatabaseCommunicationEngines();
actual.add(engine);
- connectionSession.unmarkResourceInUse(engine);
+ backendConnection.unmarkResourceInUse(engine);
assertTrue(actual.isEmpty());
}
@@ -403,13 +397,13 @@ public final class JDBCConnectionSessionTest {
databaseCommunicationEngines.add(engine);
databaseCommunicationEngines.add(inUseEngine);
inUseDatabaseCommunicationEngines.add(inUseEngine);
- Collection<SQLException> actual = connectionSession.closeDatabaseCommunicationEngines(false);
+ Collection<SQLException> actual = backendConnection.closeDatabaseCommunicationEngines(false);
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(), is(expectedException));
assertThat(inUseDatabaseCommunicationEngines.size(), is(1));
assertThat(databaseCommunicationEngines.size(), is(1));
verify(engine).close();
- connectionSession.closeDatabaseCommunicationEngines(true);
+ backendConnection.closeDatabaseCommunicationEngines(true);
verify(inUseEngine).close();
assertTrue(databaseCommunicationEngines.isEmpty());
assertTrue(inUseDatabaseCommunicationEngines.isEmpty());
@@ -418,16 +412,40 @@ public final class JDBCConnectionSessionTest {
@SuppressWarnings("unchecked")
@SneakyThrows
private Collection<DatabaseCommunicationEngine> getDatabaseCommunicationEngines() {
- Field field = JDBCConnectionSession.class.getDeclaredField("databaseCommunicationEngines");
+ Field field = JDBCBackendConnection.class.getDeclaredField("databaseCommunicationEngines");
field.setAccessible(true);
- return (Collection<DatabaseCommunicationEngine>) field.get(connectionSession);
+ return (Collection<DatabaseCommunicationEngine>) field.get(backendConnection);
}
@SuppressWarnings("unchecked")
@SneakyThrows
private Collection<DatabaseCommunicationEngine> getInUseDatabaseCommunicationEngines() {
- Field field = JDBCConnectionSession.class.getDeclaredField("inUseDatabaseCommunicationEngines");
+ Field field = JDBCBackendConnection.class.getDeclaredField("inUseDatabaseCommunicationEngines");
field.setAccessible(true);
- return (Collection<DatabaseCommunicationEngine>) field.get(connectionSession);
+ return (Collection<DatabaseCommunicationEngine>) field.get(backendConnection);
+ }
+
+ @Test
+ public void assertPrepareForTaskExecution() throws BackendConnectionException {
+ backendConnection.prepareForTaskExecution();
+ verify(backendConnection).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeConnections(false);
+ }
+
+ @Test
+ public void assertCloseExecutionResources() throws BackendConnectionException {
+ backendConnection.closeExecutionResources();
+ verify(backendConnection).closeDatabaseCommunicationEngines(false);
+ verify(backendConnection).closeFederationExecutor();
+ verify(backendConnection).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeConnections(false);
+ }
+
+ @Test
+ public void assertCloseAllResources() {
+ backendConnection.closeAllResources();
+ verify(backendConnection).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeConnections(true);
+ verify(backendConnection).closeFederationExecutor();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/MockConnectionUtil.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/MockConnectionUtil.java
index 0e08bed..e11e683 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/MockConnectionUtil.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/MockConnectionUtil.java
@@ -39,17 +39,17 @@ final class MockConnectionUtil {
/**
* Mock set cached connections.
*
- * @param connectionSession connection session
+ * @param backendConnection backend connection
* @param dataSourceName datasource name
* @param connectionSize connection size
*/
@SneakyThrows(ReflectiveOperationException.class)
- static void setCachedConnections(final JDBCConnectionSession connectionSession, final String dataSourceName, final int connectionSize) {
+ static void setCachedConnections(final JDBCBackendConnection backendConnection, final String dataSourceName, final int connectionSize) {
Multimap<String, Connection> cachedConnections = HashMultimap.create();
cachedConnections.putAll(dataSourceName, mockNewConnections(connectionSize));
- Field field = connectionSession.getClass().getDeclaredField("cachedConnections");
+ Field field = backendConnection.getClass().getDeclaredField("cachedConnections");
field.setAccessible(true);
- field.set(connectionSession, cachedConnections);
+ field.set(backendConnection, cachedConnections);
}
/**
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManagerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManagerTest.java
index 43854ec..021fbdb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManagerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/BackendTransactionManagerTest.java
@@ -19,8 +19,10 @@ package org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction;
import lombok.SneakyThrows;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
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.transaction.ShardingSphereTransactionManagerEngine;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -45,7 +47,10 @@ import static org.mockito.Mockito.when;
public final class BackendTransactionManagerTest {
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
@Mock
private TransactionStatus transactionStatus;
@@ -63,6 +68,7 @@ public final class BackendTransactionManagerTest {
setTransactionContexts();
when(connectionSession.getSchemaName()).thenReturn("schema");
when(connectionSession.getTransactionStatus()).thenReturn(transactionStatus);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
}
@SneakyThrows(ReflectiveOperationException.class)
@@ -88,8 +94,8 @@ public final class BackendTransactionManagerTest {
newBackendTransactionManager(TransactionType.LOCAL, false);
backendTransactionManager.begin();
verify(transactionStatus).setInTransaction(true);
- verify(connectionSession).closeDatabaseCommunicationEngines(true);
- verify(connectionSession).closeConnections(false);
+ verify(backendConnection).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeConnections(false);
verify(localTransactionManager).begin();
}
@@ -98,7 +104,7 @@ public final class BackendTransactionManagerTest {
newBackendTransactionManager(TransactionType.XA, true);
backendTransactionManager.begin();
verify(transactionStatus, times(0)).setInTransaction(true);
- verify(connectionSession, times(0)).closeConnections(false);
+ verify(backendConnection, times(0)).closeConnections(false);
verify(shardingSphereTransactionManager).begin();
}
@@ -203,7 +209,7 @@ public final class BackendTransactionManagerTest {
private void newBackendTransactionManager(final TransactionType transactionType, final boolean inTransaction) {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(transactionType);
when(transactionStatus.isInTransaction()).thenReturn(inTransaction);
- backendTransactionManager = new BackendTransactionManager(connectionSession);
+ backendTransactionManager = new BackendTransactionManager(backendConnection);
setLocalTransactionManager();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManagerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManagerTest.java
index 72aca10..ca23b14 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManagerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/LocalTransactionManagerTest.java
@@ -21,7 +21,9 @@ package org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,7 +42,10 @@ import static org.mockito.Mockito.when;
public final class LocalTransactionManagerTest {
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
@Mock
private TransactionStatus transactionStatus;
@@ -53,9 +58,10 @@ public final class LocalTransactionManagerTest {
@Before
public void setUp() throws SQLException {
when(connectionSession.getTransactionStatus()).thenReturn(transactionStatus);
- when(connectionSession.getCachedConnections()).thenReturn(setCachedConnections());
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ when(backendConnection.getCachedConnections()).thenReturn(setCachedConnections());
when(transactionStatus.isInTransaction()).thenReturn(true);
- localTransactionManager = new LocalTransactionManager(connectionSession);
+ localTransactionManager = new LocalTransactionManager(backendConnection);
}
private Multimap<String, Connection> setCachedConnections() {
@@ -69,7 +75,7 @@ public final class LocalTransactionManagerTest {
@Test
public void assertBegin() {
localTransactionManager.begin();
- verify(connectionSession).getConnectionPostProcessors();
+ verify(backendConnection).getConnectionPostProcessors();
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/TransactionStatusTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/TransactionStatusTest.java
index 581670d..c205c6a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/TransactionStatusTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/transaction/TransactionStatusTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Before;
import org.junit.Test;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
new file mode 100644
index 0000000..0cce457
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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.session;
+
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.junit.Before;
+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.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class ConnectionSessionTest {
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
+
+ private ConnectionSession connectionSession;
+
+ @Before
+ public void setup() {
+ connectionSession = new ConnectionSession(TransactionType.LOCAL, null);
+ connectionSession.setBackendConnection(backendConnection);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ }
+
+ @Test
+ public void assertSetCurrentSchema() {
+ connectionSession.setCurrentSchema("currentSchema");
+ assertThat(connectionSession.getSchemaName(), is("currentSchema"));
+ }
+
+ @Test(expected = ShardingSphereException.class)
+ public void assertFailedSwitchTransactionTypeWhileBegin() throws SQLException {
+ connectionSession.setCurrentSchema("schema");
+ BackendTransactionManager transactionManager = new BackendTransactionManager(backendConnection);
+ transactionManager.begin();
+ connectionSession.getTransactionStatus().setTransactionType(TransactionType.XA);
+ }
+
+ @Test(expected = ShardingSphereException.class)
+ public void assertFailedSwitchSchemaWhileBegin() throws SQLException {
+ connectionSession.setCurrentSchema("schema");
+ BackendTransactionManager transactionManager = new BackendTransactionManager(backendConnection);
+ transactionManager.begin();
+ connectionSession.setCurrentSchema("newSchema");
+ }
+
+ @Test
+ public void assertDefaultAutocommit() {
+ assertTrue(connectionSession.isAutoCommit());
+ }
+
+ @Test
+ public void assertSetAutocommit() {
+ connectionSession.setAutoCommit(false);
+ assertFalse(connectionSession.isAutoCommit());
+ }
+}
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 813ecec..cc962e8 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
@@ -26,8 +26,9 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminQueryBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminUpdateBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseBackendHandler;
@@ -68,12 +69,17 @@ public final class TextProtocolBackendHandlerFactoryTest {
private final DatabaseType databaseType = DatabaseTypeRegistry.getActualDatabaseType("MySQL");
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
@Before
public void setUp() {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
when(connectionSession.getDefaultSchemaName()).thenReturn("schema");
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
mockGlobalRuleMetaData(metaDataContexts);
ShardingSphereMetaData shardingSphereMetaData = mockShardingSphereMetaData();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java
index fcc2774..f204749 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/DatabaseOperateBackendHandlerFactoryTest.java
@@ -20,17 +20,17 @@ package org.apache.shardingsphere.proxy.backend.text.admin;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
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.database.DatabaseOperateBackendHandlerFactory;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropDatabaseStatement;
@@ -41,6 +41,10 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.ddl
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import java.sql.SQLException;
import java.util.Collections;
@@ -55,15 +59,22 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public final class DatabaseOperateBackendHandlerFactoryTest {
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private ContextManager contextManager;
+
+ @Mock
+ private ConnectionSession connectionSession;
+
@Before
public void setUp() throws IllegalAccessException, NoSuchFieldException {
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
MetaDataContexts metaDataContexts = new MetaDataContexts(mock(MetaDataPersistService.class), getMetaDataMap(),
mock(ShardingSphereRuleMetaData.class), mock(ExecutorEngine.class), new ConfigurationProperties(new Properties()), mock(OptimizerContext.class));
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
+ when(connectionSession.getSchemaName()).thenReturn("schema");
}
@Test
@@ -77,11 +88,9 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
}
private void assertExecuteCreateDatabaseContext(final CreateDatabaseStatement sqlStatement) throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
sqlStatement.setDatabaseName("new_db");
setGovernanceMetaDataContexts(true);
- ResponseHeader response = DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connection).execute();
+ ResponseHeader response = DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@@ -96,11 +105,9 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
}
private void assertExecuteDropDatabaseContext(final DropDatabaseStatement sqlStatement) throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
sqlStatement.setDatabaseName("schema");
setGovernanceMetaDataContexts(true);
- ResponseHeader response = DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connection).execute();
+ ResponseHeader response = DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@@ -115,12 +122,10 @@ public final class DatabaseOperateBackendHandlerFactoryTest {
}
public void assertExecuteCreateDatabaseContextWithException(final CreateDatabaseStatement sqlStatement) throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
sqlStatement.setDatabaseName("schema");
setGovernanceMetaDataContexts(true);
try {
- DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connection);
+ DatabaseOperateBackendHandlerFactory.newInstance(sqlStatement, connectionSession);
} catch (final DBCreateExistsException ex) {
assertNull(ex.getMessage());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcessListExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcessListExecutorTest.java
index 9d520fa..80c6004 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcessListExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowProcessListExecutorTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor;
import io.netty.util.DefaultAttributeMap;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Before;
import org.junit.Test;
@@ -60,7 +60,7 @@ public final class ShowProcessListExecutorTest {
@Test
public void assertExecute() throws SQLException {
- showProcessListExecutor.execute(new JDBCConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap()));
+ showProcessListExecutor.execute(new ConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap()));
assertThat(showProcessListExecutor.getQueryResultMetaData().getColumnCount(), is(8));
MergedResult mergedResult = showProcessListExecutor.getMergedResult();
while (mergedResult.next()) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java
index e748644..721318a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/ShowVersionExecutorTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.text.admin.mysql.executor;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
@@ -36,7 +36,7 @@ public final class ShowVersionExecutorTest {
public void assertExecute() throws SQLException {
MySQLServerInfo.setServerVersion("8.0.26");
ShowVersionExecutor executor = new ShowVersionExecutor();
- executor.execute(mock(JDBCConnectionSession.class));
+ executor.execute(mock(ConnectionSession.class));
assertThat(executor.getQueryResultMetaData().getColumnCount(), is(1));
while (executor.getMergedResult().next()) {
assertThat(executor.getMergedResult().getValue(1, Object.class), is(MySQLServerInfo.getServerVersion()));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java
index d931f04..c058289 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/SelectInformationExecutorTest.java
@@ -37,8 +37,8 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.AbstractDatabaseMetadataExecutor.DefaultDatabaseMetadataExecutor;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -46,6 +46,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectState
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
@@ -79,7 +80,8 @@ public final class SelectInformationExecutorTest {
private final SQLParserRule sqlParserRule = new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build());
- private final JDBCConnectionSession connectionSession = mock(JDBCConnectionSession.class);
+ @Mock
+ private ConnectionSession connectionSession;
@Before
public void setUp() throws IllegalAccessException, NoSuchFieldException, SQLException {
@@ -182,7 +184,7 @@ public final class SelectInformationExecutorTest {
Map<String, ShardingSphereMetaData> metaDataMap = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap();
metaDataMap.put("sharding_db", getEmptyMetaData("sharding_db"));
SelectInformationSchemataExecutor selectSchemataExecutor = new SelectInformationSchemataExecutor((SelectStatement) sqlStatement, sql);
- selectSchemataExecutor.execute(mock(JDBCConnectionSession.class));
+ selectSchemataExecutor.execute(connectionSession);
assertThat(selectSchemataExecutor.getQueryResultMetaData().getColumnCount(), is(mockResultSetMap.size()));
while (selectSchemataExecutor.getMergedResult().next()) {
assertThat(selectSchemataExecutor.getMergedResult().getValue(1, String.class), is("sharding_db"));
@@ -212,7 +214,7 @@ public final class SelectInformationExecutorTest {
metaDataMap.put("demo_ds_0", getMetaData());
metaDataMap.put("test", getEmptyMetaData("test"));
DefaultDatabaseMetadataExecutor selectExecutor = new DefaultDatabaseMetadataExecutor(sql);
- selectExecutor.execute(mock(JDBCConnectionSession.class));
+ selectExecutor.execute(connectionSession);
assertThat(selectExecutor.getRows().get(0).get("sn"), is("demo_ds_0"));
assertThat(selectExecutor.getRows().get(0).get("DEFAULT_CHARACTER_SET_NAME"), is("utf8mb4"));
}
@@ -226,7 +228,7 @@ public final class SelectInformationExecutorTest {
Map<String, ShardingSphereMetaData> metaDataMap = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap();
metaDataMap.put("sharding_db", getMetaData());
DefaultDatabaseMetadataExecutor defaultSelectMetaDataExecutor = new DefaultDatabaseMetadataExecutor(sql);
- defaultSelectMetaDataExecutor.execute(mock(JDBCConnectionSession.class));
+ defaultSelectMetaDataExecutor.execute(connectionSession);
assertThat(defaultSelectMetaDataExecutor.getQueryResultMetaData().getColumnCount(), is(mockMap.size()));
while (defaultSelectMetaDataExecutor.getMergedResult().next()) {
assertThat(defaultSelectMetaDataExecutor.getMergedResult().getValue(1, String.class), is("0"));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutorTest.java
index c1cfd64..e29bde3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectDatabaseExecutorTest.java
@@ -34,8 +34,8 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.junit.Before;
@@ -140,7 +140,7 @@ public final class SelectDatabaseExecutorTest {
metaDataMap.put("sharding_db", getMetaData());
metaDataMap.put("test", getEmptyMetaData("test"));
SelectDatabaseExecutor selectSchemataExecutor = new SelectDatabaseExecutor((SelectStatement) sqlStatement, sql);
- selectSchemataExecutor.execute(mock(JDBCConnectionSession.class));
+ selectSchemataExecutor.execute(mock(ConnectionSession.class));
assertThat(selectSchemataExecutor.getQueryResultMetaData().getColumnCount(), is(mockResultSetMap.size()));
int count = 0;
while (selectSchemataExecutor.getMergedResult().next()) {
@@ -173,7 +173,7 @@ public final class SelectDatabaseExecutorTest {
Map<String, ShardingSphereMetaData> metaDataMap = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap();
metaDataMap.put("sharding_db", getEmptyMetaData("sharding_db"));
SelectDatabaseExecutor selectSchemataExecutor = new SelectDatabaseExecutor((SelectStatement) sqlStatement, sql);
- selectSchemataExecutor.execute(mock(JDBCConnectionSession.class));
+ selectSchemataExecutor.execute(mock(ConnectionSession.class));
while (selectSchemataExecutor.getMergedResult().next()) {
assertThat(selectSchemataExecutor.getMergedResult().getValue(1, String.class), is("sharding_db"));
}
@@ -192,7 +192,7 @@ public final class SelectDatabaseExecutorTest {
Map<String, ShardingSphereMetaData> metaDataMap = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap();
metaDataMap.put("sharding_db", getEmptyMetaData("sharding_db"));
SelectDatabaseExecutor selectSchemataExecutor = new SelectDatabaseExecutor((SelectStatement) sqlStatement, sql);
- selectSchemataExecutor.execute(mock(JDBCConnectionSession.class));
+ selectSchemataExecutor.execute(mock(ConnectionSession.class));
while (selectSchemataExecutor.getMergedResult().next()) {
assertThat(selectSchemataExecutor.getMergedResult().getValue(1, String.class), is(""));
assertThat(selectSchemataExecutor.getMergedResult().getValue(2, String.class), is("sharding_db"));
@@ -206,7 +206,7 @@ public final class SelectDatabaseExecutorTest {
final String sql = "SELECT d.oid, d.datname AS databasename, d.datacl, d.datistemplate FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace = t.oid;";
final SQLStatement sqlStatement = new ShardingSphereSQLParserEngine("MySQL", sqlParserRule).parse(sql, false);
SelectDatabaseExecutor selectSchemataExecutor = new SelectDatabaseExecutor((SelectStatement) sqlStatement, sql);
- selectSchemataExecutor.execute(mock(JDBCConnectionSession.class));
+ selectSchemataExecutor.execute(mock(ConnectionSession.class));
assertThat(selectSchemataExecutor.getQueryResultMetaData().getColumnCount(), is(0));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutorTest.java
index 0f34c86..2c2d666 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/SelectTableExecutorTest.java
@@ -21,6 +21,7 @@ import com.zaxxer.hikari.pool.HikariProxyResultSet;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.CachedDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.resource.DataSourcesMetaData;
@@ -28,12 +29,11 @@ import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -120,7 +120,7 @@ public final class SelectTableExecutorTest {
Map<String, ShardingSphereMetaData> metaDataMap = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap();
metaDataMap.put("sharding_db", getMetaData());
SelectTableExecutor selectSchemataExecutor = new SelectTableExecutor(sql);
- selectSchemataExecutor.execute(mock(JDBCConnectionSession.class));
+ selectSchemataExecutor.execute(mock(ConnectionSession.class));
assertThat(selectSchemataExecutor.getQueryResultMetaData().getColumnCount(), is(mockResultSetMap.size()));
int count = 0;
while (selectSchemataExecutor.getMergedResult().next()) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactoryTest.java
index 0770fd4..c4af013 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/DatabaseBackendHandlerFactoryTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.text.data;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.UnicastDatabaseBackendHandler;
@@ -41,7 +41,7 @@ public final class DatabaseBackendHandlerFactoryTest {
String sql = "SET a=1";
SQLStatementContext<SetStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(SetStatement.class));
- DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(JDBCConnectionSession.class));
+ DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(ConnectionSession.class));
assertThat(actual, instanceOf(BroadcastDatabaseBackendHandler.class));
}
@@ -50,7 +50,7 @@ public final class DatabaseBackendHandlerFactoryTest {
String sql = "DESC tbl";
SQLStatementContext<DALStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(DALStatement.class));
- DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(JDBCConnectionSession.class));
+ DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(ConnectionSession.class));
assertThat(actual, instanceOf(UnicastDatabaseBackendHandler.class));
}
@@ -59,7 +59,7 @@ public final class DatabaseBackendHandlerFactoryTest {
String sql = "SELECT 1";
SQLStatementContext<SelectStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(SelectStatement.class));
- DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(JDBCConnectionSession.class));
+ DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(ConnectionSession.class));
assertThat(actual, instanceOf(UnicastDatabaseBackendHandler.class));
}
@@ -68,7 +68,7 @@ public final class DatabaseBackendHandlerFactoryTest {
String sql = "SELECT 1 FROM user WHERE id = 1";
SQLStatementContext<SQLStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(SQLStatement.class));
- DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(JDBCConnectionSession.class));
+ DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(ConnectionSession.class));
assertThat(actual, instanceOf(SchemaAssignedDatabaseBackendHandler.class));
}
@@ -77,7 +77,7 @@ public final class DatabaseBackendHandlerFactoryTest {
String sql = "CREATE USER test IDENTIFIED BY '123456'";
SQLStatementContext<DCLStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(DCLStatement.class));
- DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(JDBCConnectionSession.class));
+ DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(context, sql, mock(ConnectionSession.class));
assertThat(actual, instanceOf(BroadcastDatabaseBackendHandler.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
index 7046ba1..bbbc876 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/BroadcastDatabaseBackendHandlerTest.java
@@ -20,22 +20,20 @@ package org.apache.shardingsphere.proxy.backend.text.data.impl;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.sql.parser.sql.common.statement.SQLStatement;
import org.junit.Before;
import org.junit.Test;
@@ -66,7 +64,7 @@ public final class BroadcastDatabaseBackendHandlerTest {
private static final String SCHEMA_PATTERN = "schema_%s";
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock
private DatabaseCommunicationEngineFactory databaseCommunicationEngineFactory;
@@ -109,14 +107,6 @@ public final class BroadcastDatabaseBackendHandlerTest {
return result;
}
- private Map<String, DatabaseType> getDatabaseTypes() {
- Map<String, DatabaseType> result = new HashMap<>(10, 1);
- for (int i = 0; i < 10; i++) {
- result.put(String.format(SCHEMA_PATTERN, i), new MySQLDatabaseType());
- }
- return result;
- }
-
private void mockDatabaseCommunicationEngine(final ResponseHeader responseHeader) throws SQLException {
when(databaseCommunicationEngine.execute()).thenReturn(responseHeader);
when(databaseCommunicationEngineFactory.newTextProtocolInstance(any(), anyString(), any())).thenReturn(databaseCommunicationEngine);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
index b8fa5ae..9b2caf6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
@@ -22,18 +22,18 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.data.DatabaseBackendHandler;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.junit.Before;
@@ -67,7 +67,7 @@ public final class SchemaAssignedDatabaseBackendHandlerTest {
private SchemaAssignedDatabaseBackendHandler schemaAssignedDatabaseBackendHandler;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock
private DatabaseCommunicationEngineFactory databaseCommunicationEngineFactory;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
index 1fa234d..d34e090 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
@@ -22,18 +22,18 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.data.DatabaseBackendHandler;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.junit.Before;
@@ -67,7 +67,7 @@ public final class UnicastDatabaseBackendHandlerTest {
private UnicastDatabaseBackendHandler unicastDatabaseBackendHandler;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock
private DatabaseCommunicationEngineFactory databaseCommunicationEngineFactory;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
index abafa29..1ba20a9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/DropDatabaseBackendHandlerTest.java
@@ -19,11 +19,11 @@ package org.apache.shardingsphere.proxy.backend.text.database;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException;
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.sql.parser.sql.common.statement.ddl.DropDatabaseStatement;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +46,7 @@ import static org.mockito.Mockito.when;
public final class DropDatabaseBackendHandlerTest {
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock
private DropDatabaseStatement sqlStatement;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
index 736453d..ffb943c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
@@ -26,18 +26,18 @@ import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.jdbc.connection.JDBCConnectionSession;
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.query.QueryResponseHeader;
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.RALBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.RDLBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.distsql.rql.RQLBackendHandlerFactory;
@@ -62,6 +62,9 @@ import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardin
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.sql.SQLException;
@@ -76,8 +79,12 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public final class DistSQLBackendHandlerFactoryTest {
+ @Mock
+ private ConnectionSession connectionSession;
+
@Before
public void setUp() throws IllegalAccessException, NoSuchFieldException {
Field contextManagerField = ProxyContext.getInstance().getClass().getDeclaredField("contextManager");
@@ -87,6 +94,7 @@ public final class DistSQLBackendHandlerFactoryTest {
ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
+ when(connectionSession.getSchemaName()).thenReturn("schema");
}
private Map<String, ShardingSphereMetaData> getMetaDataMap() {
@@ -97,192 +105,152 @@ public final class DistSQLBackendHandlerFactoryTest {
@Test
public void assertExecuteDataSourcesContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AddResourceStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AddResourceStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteShardingTableRuleContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
ShardingSphereMetaData metaData = ProxyContext.getInstance().getMetaData("schema");
when(metaData.getRuleMetaData().getRules()).thenReturn(Collections.emptyList());
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CreateShardingTableRuleStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CreateShardingTableRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteAddResourceContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AddResourceStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AddResourceStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteAlterResourceContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterResourceStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterResourceStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteAlterShadowRuleContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterShadowRuleStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterShadowRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteCreateShadowRuleContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CreateShadowRuleStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CreateShadowRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteDropShadowRuleContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropShadowRuleStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropShadowRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteAlterShadowAlgorithm() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterShadowAlgorithmStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterShadowAlgorithmStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteShowShadowRulesContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowRulesStatement.class), connection).execute();
+ ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowRulesStatement.class), connectionSession).execute();
assertThat(response, instanceOf(QueryResponseHeader.class));
}
@Test
public void assertExecuteShowShadowTableRulesContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowTableRulesStatement.class), connection).execute();
+ ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowTableRulesStatement.class), connectionSession).execute();
assertThat(response, instanceOf(QueryResponseHeader.class));
}
@Test
public void assertExecuteShowShadowAlgorithmsContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowAlgorithmsStatement.class), connection).execute();
+ ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowAlgorithmsStatement.class), connectionSession).execute();
assertThat(response, instanceOf(QueryResponseHeader.class));
}
@Test
public void assertExecuteDropShadowAlgorithmContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
mockShardingSphereRuleMetaData();
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropShadowAlgorithmStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropShadowAlgorithmStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteDropResourceContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropResourceStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropResourceStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test(expected = RequiredRuleMissedException.class)
public void assertExecuteDropReadwriteSplittingRuleContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropReadwriteSplittingRuleStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropReadwriteSplittingRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteCreateReadwriteSplittingRuleContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CreateReadwriteSplittingRuleStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CreateReadwriteSplittingRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test(expected = RequiredRuleMissedException.class)
public void assertExecuteAlterReadwriteSplittingRuleContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterReadwriteSplittingRuleStatement.class), connection).execute();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(AlterReadwriteSplittingRuleStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
@Test
public void assertExecuteShowResourceContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
setContextManager(true);
- ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowResourcesStatement.class), connection).execute();
+ ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowResourcesStatement.class), connectionSession).execute();
assertThat(response, instanceOf(QueryResponseHeader.class));
}
@Test
public void assertExecuteShowScalingCheckAlgorithmsContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
mockScalingContext();
- ResponseHeader response = RALBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(ShowScalingCheckAlgorithmsStatement.class), connection).execute();
+ ResponseHeader response = RALBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(ShowScalingCheckAlgorithmsStatement.class), connectionSession).execute();
assertThat(response, instanceOf(QueryResponseHeader.class));
}
@Test
public void assertExecuteStopScalingSourceWritingContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
mockScalingContext();
- ResponseHeader response = RALBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(StopScalingSourceWritingStatement.class), connection).execute();
+ ResponseHeader response = RALBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(StopScalingSourceWritingStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
}
//TODO assertExecuteCheckoutScalingContext throw exception
@Test(expected = RuntimeException.class)
public void assertExecuteCheckoutScalingContext() throws SQLException {
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getSchemaName()).thenReturn("schema");
mockScalingContext();
- ResponseHeader response = RALBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CheckoutScalingStatement.class), connection).execute();
+ ResponseHeader response = RALBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(CheckoutScalingStatement.class), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.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 a8e2727..70dd471 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
@@ -22,18 +22,18 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVari
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.communication.jdbc.connection.JDBCConnectionSession;
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.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
@@ -60,7 +60,7 @@ public final class SetVariableBackendHandlerTest {
private static final String SCHEMA_PATTERN = "schema_%s";
- private final JDBCConnectionSession connectionSession = new JDBCConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
+ private final ConnectionSession connectionSession = new ConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowAllVariablesBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowAllVariablesBackendHandlerTest.java
index 8a20a85..60c1050 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowAllVariablesBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowAllVariablesBackendHandlerTest.java
@@ -22,10 +22,10 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowAl
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.query.QueryResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.ShowDistSQLBackendHandler;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Test;
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.when;
public final class ShowAllVariablesBackendHandlerTest {
- private final JDBCConnectionSession connectionSession = new JDBCConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
+ private final ConnectionSession connectionSession = new ConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
@Test
public void assertShowPropsVariable() throws SQLException {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java
index 97aea16..8bace3c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/ShowVariableBackendHandlerTest.java
@@ -22,10 +22,11 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowVa
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
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.query.QueryResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.ShowDistSQLBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.enums.VariableEnum;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.exception.UnsupportedVariableException;
@@ -44,7 +45,7 @@ import static org.mockito.Mockito.when;
public final class ShowVariableBackendHandlerTest {
- private final JDBCConnectionSession connectionSession = new JDBCConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
+ private final ConnectionSession connectionSession = new ConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
@Test
public void assertShowTransactionType() throws SQLException {
@@ -61,6 +62,7 @@ public final class ShowVariableBackendHandlerTest {
@Test
public void assertShowCachedConnections() throws SQLException {
connectionSession.setCurrentSchema("schema");
+ connectionSession.setBackendConnection(mock(JDBCBackendConnection.class));
ShowDistSQLBackendHandler backendHandler = new ShowDistSQLBackendHandler(new ShowVariableStatement("cached_connections"), connectionSession);
ResponseHeader actual = backendHandler.execute();
assertThat(actual, instanceOf(QueryResponseHeader.class));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advance/ParseDistSQLBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advance/ParseDistSQLBackendHandlerTest.java
index 94d9bbc..fa1e217 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advance/ParseDistSQLBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/advance/ParseDistSQLBackendHandlerTest.java
@@ -24,8 +24,8 @@ import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.advanced.ParseDistSQLBackendHandler;
import org.apache.shardingsphere.sql.parser.exception.SQLParsingException;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -63,7 +63,7 @@ public final class ParseDistSQLBackendHandlerTest {
public void assertGetRowData() {
String sql = "select * from t_order";
ParseStatement parseStatement = new ParseStatement(sql);
- ParseDistSQLBackendHandler parseDistSQLBackendHandler = new ParseDistSQLBackendHandler(new MySQLDatabaseType(), parseStatement, mock(JDBCConnectionSession.class));
+ ParseDistSQLBackendHandler parseDistSQLBackendHandler = new ParseDistSQLBackendHandler(new MySQLDatabaseType(), parseStatement, mock(ConnectionSession.class));
parseDistSQLBackendHandler.execute();
SQLStatement statement = new ShardingSphereSQLParserEngine("MySQL", sqlParserRule).parse(sql, false);
assertThat(new LinkedList<>(parseDistSQLBackendHandler.getRowData()).getFirst(), is(new Gson().toJson(statement)));
@@ -73,7 +73,7 @@ public final class ParseDistSQLBackendHandlerTest {
public void assertExecute() {
String sql = "wrong sql";
ParseStatement parseStatement = new ParseStatement(sql);
- ParseDistSQLBackendHandler parseDistSQLBackendHandler = new ParseDistSQLBackendHandler(new MySQLDatabaseType(), parseStatement, mock(JDBCConnectionSession.class));
+ ParseDistSQLBackendHandler parseDistSQLBackendHandler = new ParseDistSQLBackendHandler(new MySQLDatabaseType(), parseStatement, mock(ConnectionSession.class));
parseDistSQLBackendHandler.execute();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactoryTest.java
index 326c8f6..5494920 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/hint/HintStatementExecutorFactoryTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.HintDistSQLStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.hint.ClearHintStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.executor.AddShardingHintDatabaseValueExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.executor.AddShardingHintTableValueExecutor;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.hint.executor.ClearHintExecutor;
@@ -52,7 +52,7 @@ import static org.mockito.Mockito.mock;
public final class HintStatementExecutorFactoryTest {
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Test
public void assertSetReadwriteSplittingHintSourceExecutor() throws SQLException {
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
index b3b825e..0d10947 100644
--- 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
@@ -20,7 +20,7 @@ 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.communication.jdbc.connection.JDBCConnectionSession;
+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;
@@ -40,7 +40,7 @@ import static org.mockito.Mockito.mock;
public final class SetStatementExecutorFactoryTest {
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Test
public void assertSetVariableExecutor() throws SQLException {
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 63f998e..427ea5e 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,14 +20,17 @@ 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.communication.jdbc.connection.JDBCConnectionSession;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.TransactionStatus;
+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.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.util.SystemPropertyUtil;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
@@ -36,22 +39,24 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+@RunWith(MockitoJUnitRunner.class)
public final class SetVariableExecutorTest {
+ @Mock
+ private ConnectionSession connectionSession;
+
@Test
public void assertExecuteWithTransactionType() {
SetVariableStatement statement = new SetVariableStatement("transaction_type", "local");
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- when(connection.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.XA));
- new SetVariableExecutor(statement, connection).execute();
- assertThat(connection.getTransactionStatus().getTransactionType().name(), is(TransactionType.LOCAL.name()));
+ when(connectionSession.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.XA));
+ new SetVariableExecutor(statement, connectionSession).execute();
+ assertThat(connectionSession.getTransactionStatus().getTransactionType().name(), is(TransactionType.LOCAL.name()));
}
@Test
public void assertExecuteWithAgent() {
SetVariableStatement statement = new SetVariableStatement("AGENT_PLUGINS_ENABLED", "false");
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- new SetVariableExecutor(statement, connection).execute();
+ new SetVariableExecutor(statement, connectionSession).execute();
String actualValue = SystemPropertyUtil.getSystemProperty(VariableEnum.AGENT_PLUGINS_ENABLED.name(), "default");
assertThat(actualValue, is("false"));
}
@@ -63,8 +68,7 @@ public final class SetVariableExecutorTest {
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
ProxyContext.getInstance().init(contextManager);
SetVariableStatement statement = new SetVariableStatement("proxy_frontend_flush_threshold", "1024");
- JDBCConnectionSession connection = mock(JDBCConnectionSession.class);
- new SetVariableExecutor(statement, connection).execute();
+ new SetVariableExecutor(statement, connectionSession).execute();
Object actualValue = contextManager.getMetaDataContexts().getProps().getProps().get("proxy-frontend-flush-threshold");
assertNotNull(actualValue);
assertThat(actualValue.toString(), is("1024"));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
index 3a8e1d6..3ca9053 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
@@ -27,10 +27,10 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -59,7 +59,7 @@ public final class AddResourceBackendHandlerTest {
private AddResourceStatement addResourceStatement;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private MetaDataContexts metaDataContexts;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
index 394c551..e30eaf2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
@@ -28,10 +28,10 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,7 +61,7 @@ public final class AlterResourceBackendHandlerTest {
private AlterResourceStatement alterResourceStatement;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private MetaDataContexts metaDataContexts;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
index 22cb314..ffd6c58 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
@@ -26,10 +26,10 @@ import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.shadow.rule.ShadowRule;
import org.apache.shardingsphere.singletable.rule.SingleTableRule;
import org.junit.Before;
@@ -60,7 +60,7 @@ public final class DropResourceBackendHandlerTest {
private DropResourceStatement dropResourceStatement;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock
private ShardingSphereMetaData metaData;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
index 45b11e1..48a0660 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RQLBackendHandlerTest.java
@@ -18,16 +18,16 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.rql;
import org.apache.shardingsphere.distsql.parser.statement.rql.RQLStatement;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
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.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.junit.Before;
import org.junit.Test;
@@ -63,7 +63,7 @@ public final class RQLBackendHandlerTest {
public void assertExecute() {
DistSQLResultSet resultSet = mock(DistSQLResultSet.class);
when(resultSet.getColumnNames()).thenReturn(Arrays.asList("foo", "bar"));
- RQLBackendHandler handler = new RQLBackendHandler(mock(RQLStatement.class), mock(JDBCConnectionSession.class), resultSet);
+ RQLBackendHandler handler = new RQLBackendHandler(mock(RQLStatement.class), mock(ConnectionSession.class), resultSet);
ResponseHeader responseHeader = handler.execute("test", mock(RQLStatement.class));
assertThat(((QueryResponseHeader) responseHeader).getQueryHeaders().size(), is(2));
assertQueryHeader(((QueryResponseHeader) responseHeader).getQueryHeaders().get(0), "foo");
@@ -89,7 +89,7 @@ public final class RQLBackendHandlerTest {
public void assertGetRowData() {
DistSQLResultSet resultSet = mock(DistSQLResultSet.class);
when(resultSet.getRowData()).thenReturn(Arrays.asList("foo_value", "bar_value"));
- RQLBackendHandler handler = new RQLBackendHandler(mock(RQLStatement.class), mock(JDBCConnectionSession.class), resultSet);
+ RQLBackendHandler handler = new RQLBackendHandler(mock(RQLStatement.class), mock(ConnectionSession.class), resultSet);
handler.execute("test", mock(RQLStatement.class));
Collection<Object> rowData = handler.getRowData();
assertThat(rowData.size(), is(2));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
index 2cba9ca..990d299 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RuleDefinitionBackendHandlerTest.java
@@ -21,10 +21,10 @@ import io.netty.util.DefaultAttributeMap;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
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.fixture.CreateFixtureRuleStatement;
import org.apache.shardingsphere.proxy.backend.text.distsql.rdl.rule.RuleDefinitionBackendHandler;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
@@ -59,7 +59,7 @@ public final class RuleDefinitionBackendHandlerTest {
@Test
public void assertExecute() throws SQLException {
- JDBCConnectionSession connectionSession = new JDBCConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
+ ConnectionSession connectionSession = new ConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
connectionSession.setCurrentSchema("test");
ResponseHeader response = new RuleDefinitionBackendHandler<>(new CreateFixtureRuleStatement(), connectionSession).execute();
assertThat(response, instanceOf(UpdateResponseHeader.class));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactoryTest.java
index 91a35ba..6d605a1 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerFactoryTest.java
@@ -20,9 +20,10 @@ package org.apache.shardingsphere.proxy.backend.text.transaction;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.data.impl.BroadcastDatabaseBackendHandler;
import org.apache.shardingsphere.sql.parser.sql.common.statement.tcl.CommitStatement;
@@ -59,33 +60,39 @@ public final class TransactionBackendHandlerFactoryTest {
@Test
public void assertTransactionBackendHandlerReturnedWhenTCLStatementInstanceOfCommitStatement() {
- JDBCConnectionSession connectionSession = mock(JDBCConnectionSession.class, Answers.RETURNS_DEEP_STUBS);
+ ConnectionSession connectionSession = mock(ConnectionSession.class, Answers.RETURNS_DEEP_STUBS);
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
SQLStatementContext<CommitStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(CommitStatement.class));
TextProtocolBackendHandler textProtocolBackendHandler = TransactionBackendHandlerFactory.newInstance(context, null, connectionSession);
assertThat(textProtocolBackendHandler, instanceOf(TransactionBackendHandler.class));
TransactionBackendHandler transactionBackendHandler = (TransactionBackendHandler) textProtocolBackendHandler;
assertFieldOfInstance(transactionBackendHandler, "operationType", is(TransactionOperationType.COMMIT));
- assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(connectionSession));
+ assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(backendConnection));
}
@Test
public void assertTransactionBackendHandlerReturnedWhenTCLStatementInstanceOfRollbackStatement() {
- JDBCConnectionSession connectionSession = mock(JDBCConnectionSession.class, Answers.RETURNS_DEEP_STUBS);
+ ConnectionSession connectionSession = mock(ConnectionSession.class, Answers.RETURNS_DEEP_STUBS);
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
SQLStatementContext<RollbackStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(RollbackStatement.class));
TextProtocolBackendHandler textProtocolBackendHandler = TransactionBackendHandlerFactory.newInstance(context, null, connectionSession);
assertThat(textProtocolBackendHandler, instanceOf(TransactionBackendHandler.class));
TransactionBackendHandler transactionBackendHandler = (TransactionBackendHandler) textProtocolBackendHandler;
assertFieldOfInstance(transactionBackendHandler, "operationType", is(TransactionOperationType.ROLLBACK));
- assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(connectionSession));
+ assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(backendConnection));
}
@Test
public void assertBroadcastBackendHandlerReturnedWhenTCLStatementNotHit() {
SQLStatementContext<TCLStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(TCLStatement.class));
- assertThat(TransactionBackendHandlerFactory.newInstance(context, null, null), instanceOf(BroadcastDatabaseBackendHandler.class));
+ assertThat(TransactionBackendHandlerFactory.newInstance(context, null, mock(ConnectionSession.class)), instanceOf(BroadcastDatabaseBackendHandler.class));
}
@SuppressWarnings("unchecked")
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerTest.java
index b523ad4..17f9feb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/transaction/TransactionBackendHandlerTest.java
@@ -17,17 +17,16 @@
package org.apache.shardingsphere.proxy.backend.text.transaction;
-import io.netty.util.DefaultAttributeMap;
import lombok.SneakyThrows;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
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.sql.parser.sql.common.statement.tcl.TCLStatement;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionOperationType;
-import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Before;
import org.junit.Test;
@@ -42,7 +41,7 @@ import static org.mockito.Mockito.when;
public final class TransactionBackendHandlerTest {
- private final JDBCConnectionSession connectionSession = new JDBCConnectionSession(TransactionType.LOCAL, new DefaultAttributeMap());
+ private final ConnectionSession connectionSession = mock(ConnectionSession.class, RETURNS_DEEP_STUBS);
@Before
@SneakyThrows(ReflectiveOperationException.class)
@@ -57,6 +56,9 @@ public final class TransactionBackendHandlerTest {
@Test
public void assertExecute() throws SQLException {
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
TransactionBackendHandler transactionBackendHandler = new TransactionBackendHandler(mock(TCLStatement.class), TransactionOperationType.BEGIN, connectionSession);
ResponseHeader actual = transactionBackendHandler.execute();
assertThat(actual, instanceOf(UpdateResponseHeader.class));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index 8deca8c..b0dd397 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -27,9 +27,8 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.proxy.backend.communication.SQLStatementSchemaHolder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.ConnectionStatus;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager;
+import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
import org.apache.shardingsphere.proxy.frontend.exception.ExpectedExceptions;
@@ -37,8 +36,9 @@ import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngi
import java.sql.SQLException;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.Collections;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Command executor task.
@@ -49,7 +49,7 @@ public final class CommandExecutorTask implements Runnable {
private final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
private final ChannelHandlerContext context;
@@ -65,16 +65,8 @@ public final class CommandExecutorTask implements Runnable {
public void run() {
boolean isNeedFlush = false;
try (PacketPayload payload = databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload((ByteBuf) message, context.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get())) {
- ConnectionStatus connectionStatus = connectionSession.getConnectionStatus();
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- connectionStatus.waitUntilConnectionRelease();
- connectionStatus.switchToUsing();
- }
- if (!connectionSession.isAutoCommit() && !connectionSession.getTransactionStatus().isInTransaction()) {
- BackendTransactionManager transactionManager = new BackendTransactionManager(connectionSession);
- transactionManager.begin();
- }
- isNeedFlush = executeCommand(context, payload, connectionSession);
+ connectionSession.getBackendConnection().prepareForTaskExecution();
+ isNeedFlush = executeCommand(context, payload);
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
@@ -82,11 +74,11 @@ public final class CommandExecutorTask implements Runnable {
} finally {
// TODO optimize SQLStatementSchemaHolder
SQLStatementSchemaHolder.remove();
- Collection<SQLException> exceptions = closeExecutionResources();
- if (!connectionSession.getTransactionStatus().isInConnectionHeldTransaction()) {
- exceptions.addAll(connectionSession.closeDatabaseCommunicationEngines(true));
- exceptions.addAll(connectionSession.closeConnections(false));
- connectionSession.getConnectionStatus().switchToReleased();
+ Collection<SQLException> exceptions = Collections.emptyList();
+ try {
+ connectionSession.getBackendConnection().closeExecutionResources();
+ } catch (final BackendConnectionException ex) {
+ exceptions = ex.getExceptions().stream().filter(SQLException.class::isInstance).map(SQLException.class::cast).collect(Collectors.toList());
}
if (isNeedFlush) {
context.flush();
@@ -95,7 +87,7 @@ public final class CommandExecutorTask implements Runnable {
}
}
- private boolean executeCommand(final ChannelHandlerContext context, final PacketPayload payload, final JDBCConnectionSession connectionSession) throws SQLException {
+ private boolean executeCommand(final ChannelHandlerContext context, final PacketPayload payload) throws SQLException {
CommandExecuteEngine commandExecuteEngine = databaseProtocolFrontendEngine.getCommandExecuteEngine();
CommandPacketType type = commandExecuteEngine.getCommandPacketType(payload);
CommandPacket commandPacket = commandExecuteEngine.getCommandPacket(payload, type, connectionSession);
@@ -107,7 +99,7 @@ public final class CommandExecutorTask implements Runnable {
}
responsePackets.forEach(context::write);
if (commandExecutor instanceof QueryCommandExecutor) {
- return commandExecuteEngine.writeQueryData(context, connectionSession, (QueryCommandExecutor) commandExecutor, responsePackets.size());
+ return commandExecuteEngine.writeQueryData(context, connectionSession.getBackendConnection(), (QueryCommandExecutor) commandExecutor, responsePackets.size());
}
} finally {
commandExecutor.close();
@@ -125,13 +117,6 @@ public final class CommandExecutorTask implements Runnable {
context.flush();
}
- private Collection<SQLException> closeExecutionResources() {
- Collection<SQLException> result = new LinkedList<>();
- result.addAll(connectionSession.closeDatabaseCommunicationEngines(false));
- result.addAll(connectionSession.closeFederationExecutor());
- return result;
- }
-
private void processClosedExceptions(final Collection<SQLException> exceptions) {
if (exceptions.isEmpty()) {
return;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
index af0d23f..8192bee 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
@@ -25,8 +25,9 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.db.protocol.CommonConstants;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.authentication.AuthenticationResult;
import org.apache.shardingsphere.proxy.frontend.executor.ConnectionThreadExecutorGroup;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
@@ -44,13 +45,15 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
private final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
private volatile boolean authenticated;
public FrontendChannelInboundHandler(final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final Channel channel) {
this.databaseProtocolFrontendEngine = databaseProtocolFrontendEngine;
- connectionSession = new JDBCConnectionSession(getTransactionRule().getDefaultType(), channel);
+ connectionSession = new ConnectionSession(getTransactionRule().getDefaultType(), channel);
+ // TODO Decouple JDBCBackendConnection from this class.
+ connectionSession.setBackendConnection(new JDBCBackendConnection(connectionSession));
}
private TransactionRule getTransactionRule() {
@@ -101,16 +104,13 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
private void closeAllResources() {
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(connectionSession.getConnectionId());
- connectionSession.closeDatabaseCommunicationEngines(true);
- connectionSession.closeConnections(true);
- connectionSession.closeFederationExecutor();
databaseProtocolFrontendEngine.release(connectionSession);
}
@Override
public void channelWritabilityChanged(final ChannelHandlerContext context) {
if (context.channel().isWritable()) {
- connectionSession.getResourceLock().doNotify();
+ ((JDBCBackendConnection) connectionSession.getBackendConnection()).getResourceLock().doNotify();
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyState.java
index 9cbd4db..6baf240 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyState.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.frontend.state;
import io.netty.channel.ChannelHandlerContext;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
/**
@@ -28,11 +28,10 @@ public interface ProxyState {
/**
* Execute command.
- *
- * @param context channel handler context
+ * @param context channel handler context
* @param message message
* @param databaseProtocolFrontendEngine database protocol frontend engine
* @param connectionSession connection session
*/
- void execute(ChannelHandlerContext context, Object message, DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, JDBCConnectionSession connectionSession);
+ void execute(ChannelHandlerContext context, Object message, DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, ConnectionSession connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
index 846bc91..a5f267d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
@@ -21,8 +21,8 @@ import io.netty.channel.ChannelHandlerContext;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.state.StateType;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
import org.apache.shardingsphere.proxy.frontend.state.impl.CircuitBreakProxyState;
import org.apache.shardingsphere.proxy.frontend.state.impl.LockProxyState;
@@ -47,14 +47,13 @@ public final class ProxyStateContext {
/**
* Execute command.
- *
- * @param context channel handler context
+ * @param context channel handler context
* @param message message
* @param databaseProtocolFrontendEngine database protocol frontend engine
* @param connectionSession connection session
*/
public static void execute(final ChannelHandlerContext context, final Object message,
- final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final JDBCConnectionSession connectionSession) {
+ final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final ConnectionSession connectionSession) {
STATES.get(ProxyContext.getInstance().getStateContext().getCurrentState()).execute(context, message, databaseProtocolFrontendEngine, connectionSession);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/CircuitBreakProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/CircuitBreakProxyState.java
index 0a69bf5..af118e6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/CircuitBreakProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/CircuitBreakProxyState.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.proxy.frontend.state.impl;
import io.netty.channel.ChannelHandlerContext;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
import org.apache.shardingsphere.proxy.frontend.state.ProxyState;
@@ -32,7 +32,7 @@ import java.util.Optional;
public final class CircuitBreakProxyState implements ProxyState {
@Override
- public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final JDBCConnectionSession connectionSession) {
+ public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final ConnectionSession connectionSession) {
context.writeAndFlush(databaseProtocolFrontendEngine.getCommandExecuteEngine().getErrorPacket(new CircuitBreakException(), connectionSession));
Optional<DatabasePacket<?>> databasePacket = databaseProtocolFrontendEngine.getCommandExecuteEngine().getOtherPacket(connectionSession);
databasePacket.ifPresent(context::writeAndFlush);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
index f7c1c2e..39e6aa7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.frontend.state.impl;
import io.netty.channel.ChannelHandlerContext;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
import org.apache.shardingsphere.proxy.frontend.state.ProxyState;
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.proxy.frontend.state.ProxyState;
public final class LockProxyState implements ProxyState {
@Override
- public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final JDBCConnectionSession connectionSession) {
+ public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final ConnectionSession connectionSession) {
throw new UnsupportedOperationException("LockProxyState");
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyState.java
index 17d92d8..65c0c1b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyState.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.proxy.frontend.state.impl;
import io.netty.channel.ChannelHandlerContext;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
@@ -37,7 +36,7 @@ import java.util.concurrent.ExecutorService;
public final class OKProxyState implements ProxyState {
@Override
- public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final JDBCConnectionSession connectionSession) {
+ public void execute(final ChannelHandlerContext context, final Object message, final DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine, final ConnectionSession connectionSession) {
CommandExecutorTask commandExecutorTask = new CommandExecutorTask(databaseProtocolFrontendEngine, connectionSession, context, message);
ExecutorService executorService = determineSuitableExecutorService(context, databaseProtocolFrontendEngine, connectionSession);
executorService.execute(commandExecutorTask);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
index 6dedc4a..b538310 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
@@ -24,8 +24,10 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.ConnectionStatus;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
import org.apache.shardingsphere.proxy.frontend.context.FrontendContext;
@@ -43,7 +45,6 @@ import java.util.Collections;
import java.util.Optional;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
@@ -61,7 +62,10 @@ public final class CommandExecutorTaskTest {
private PacketPayload payload;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ChannelHandlerContext handlerContext;
@@ -92,81 +96,68 @@ public final class CommandExecutorTaskTest {
@Before
public void setup() {
- when(connectionSession.closeDatabaseCommunicationEngines(anyBoolean())).thenReturn(Collections.emptyList());
- when(connectionSession.isAutoCommit()).thenReturn(true);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
when(handlerContext.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get()).thenReturn(StandardCharsets.UTF_8);
}
@Test
- public void assertRunNeedFlushByFalse() throws SQLException {
+ public void assertRunNeedFlushByFalse() throws SQLException, BackendConnectionException {
when(queryCommandExecutor.execute()).thenReturn(Collections.emptyList());
when(engine.getCommandExecuteEngine().getCommandPacket(payload, commandPacketType, connectionSession)).thenReturn(commandPacket);
when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, commandPacket, connectionSession)).thenReturn(queryCommandExecutor);
when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
- when(connectionSession.getConnectionStatus()).thenReturn(connectionStatus);
when(engine.getCodecEngine().createPacketPayload(message, StandardCharsets.UTF_8)).thenReturn(payload);
- when(connectionSession.closeConnections(false)).thenReturn(Collections.emptyList());
- when(connectionSession.closeFederationExecutor()).thenReturn(Collections.emptyList());
CommandExecutorTask actual = new CommandExecutorTask(engine, connectionSession, handlerContext, message);
actual.run();
verify(queryCommandExecutor).close();
- verify(connectionSession).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeExecutionResources();
}
@Test
- public void assertRunNeedFlushByTrue() throws SQLException {
+ public void assertRunNeedFlushByTrue() throws SQLException, BackendConnectionException {
when(queryCommandExecutor.execute()).thenReturn(Collections.singletonList(databasePacket));
when(engine.getCommandExecuteEngine().getCommandPacket(payload, commandPacketType, connectionSession)).thenReturn(commandPacket);
when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, commandPacket, connectionSession)).thenReturn(queryCommandExecutor);
when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
- when(engine.getCommandExecuteEngine().writeQueryData(any(ChannelHandlerContext.class), any(JDBCConnectionSession.class), any(QueryCommandExecutor.class), anyInt())).thenReturn(true);
- when(connectionSession.getConnectionStatus()).thenReturn(connectionStatus);
+ when(engine.getCommandExecuteEngine().writeQueryData(any(ChannelHandlerContext.class), any(JDBCBackendConnection.class), any(QueryCommandExecutor.class), anyInt())).thenReturn(true);
when(engine.getCodecEngine().createPacketPayload(message, StandardCharsets.UTF_8)).thenReturn(payload);
- when(connectionSession.closeConnections(false)).thenReturn(Collections.emptyList());
- when(connectionSession.closeFederationExecutor()).thenReturn(Collections.emptyList());
CommandExecutorTask actual = new CommandExecutorTask(engine, connectionSession, handlerContext, message);
actual.run();
verify(handlerContext).write(databasePacket);
verify(handlerContext).flush();
- verify(engine.getCommandExecuteEngine()).writeQueryData(handlerContext, connectionSession, queryCommandExecutor, 1);
+ verify(engine.getCommandExecuteEngine()).writeQueryData(handlerContext, backendConnection, queryCommandExecutor, 1);
verify(queryCommandExecutor).close();
- verify(connectionSession).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeExecutionResources();
}
@Test
- public void assertRunByCommandExecutor() throws SQLException {
+ public void assertRunByCommandExecutor() throws SQLException, BackendConnectionException {
when(frontendContext.isFlushForPerCommandPacket()).thenReturn(true);
when(engine.getFrontendContext()).thenReturn(frontendContext);
when(commandExecutor.execute()).thenReturn(Collections.singletonList(databasePacket));
when(engine.getCommandExecuteEngine().getCommandPacket(payload, commandPacketType, connectionSession)).thenReturn(commandPacket);
when(engine.getCommandExecuteEngine().getCommandExecutor(commandPacketType, commandPacket, connectionSession)).thenReturn(commandExecutor);
when(engine.getCommandExecuteEngine().getCommandPacketType(payload)).thenReturn(commandPacketType);
- when(connectionSession.getConnectionStatus()).thenReturn(connectionStatus);
when(engine.getCodecEngine().createPacketPayload(message, StandardCharsets.UTF_8)).thenReturn(payload);
- when(connectionSession.closeConnections(false)).thenReturn(Collections.emptyList());
- when(connectionSession.closeFederationExecutor()).thenReturn(Collections.emptyList());
CommandExecutorTask actual = new CommandExecutorTask(engine, connectionSession, handlerContext, message);
actual.run();
verify(handlerContext).write(databasePacket);
verify(handlerContext).flush();
verify(commandExecutor).close();
- verify(connectionSession).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeExecutionResources();
}
@Test
- public void assertRunWithError() {
+ public void assertRunWithError() throws BackendConnectionException {
RuntimeException mockException = new RuntimeException("mock");
- when(connectionSession.getConnectionStatus()).thenReturn(connectionStatus);
- doThrow(mockException).when(connectionSession).isAutoCommit();
+ doThrow(mockException).when(backendConnection).prepareForTaskExecution();
when(engine.getCodecEngine().createPacketPayload(message, StandardCharsets.UTF_8)).thenReturn(payload);
when(engine.getCommandExecuteEngine().getErrorPacket(mockException, connectionSession)).thenReturn(databasePacket);
when(engine.getCommandExecuteEngine().getOtherPacket(connectionSession)).thenReturn(Optional.of(databasePacket));
- when(connectionSession.closeConnections(false)).thenReturn(Collections.emptyList());
- when(connectionSession.closeFederationExecutor()).thenReturn(Collections.emptyList());
CommandExecutorTask actual = new CommandExecutorTask(engine, connectionSession, handlerContext, message);
actual.run();
verify(handlerContext, times(2)).write(databasePacket);
verify(handlerContext).flush();
- verify(connectionSession).closeDatabaseCommunicationEngines(true);
+ verify(backendConnection).closeExecutionResources();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
index c68d095..a0974ec 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/OKProxyStateTest.java
@@ -22,8 +22,9 @@ import io.netty.util.concurrent.EventExecutor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
import org.apache.shardingsphere.proxy.frontend.executor.ConnectionThreadExecutorGroup;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
@@ -59,7 +60,7 @@ public final class OKProxyStateTest {
private DatabaseProtocolFrontendEngine frontendEngine;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private JDBCConnectionSession connection;
+ private ConnectionSession connectionSession;
@BeforeClass
public static void setupGlobal() {
@@ -68,14 +69,15 @@ public final class OKProxyStateTest {
@Before
public void setup() {
- when(connection.getConnectionId()).thenReturn(1);
+ when(connectionSession.getConnectionId()).thenReturn(1);
+ when(connectionSession.getBackendConnection()).thenReturn(mock(JDBCBackendConnection.class));
}
@Test
public void assertExecuteWithProxyHintEnabled() {
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_HINT_ENABLED)).thenReturn(true);
ExecutorService executorService = registerMockExecutorService(1);
- new OKProxyState().execute(context, null, frontendEngine, connection);
+ new OKProxyState().execute(context, null, frontendEngine, connectionSession);
verify(executorService).execute(any(CommandExecutorTask.class));
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(1);
}
@@ -83,9 +85,9 @@ public final class OKProxyStateTest {
@Test
public void assertExecuteWithDistributedTransaction() {
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_HINT_ENABLED)).thenReturn(false);
- when(connection.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.XA);
+ when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.XA);
ExecutorService executorService = registerMockExecutorService(1);
- new OKProxyState().execute(context, null, frontendEngine, connection);
+ new OKProxyState().execute(context, null, frontendEngine, connectionSession);
verify(executorService).execute(any(CommandExecutorTask.class));
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(1);
}
@@ -96,7 +98,7 @@ public final class OKProxyStateTest {
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<String>getValue(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE)).thenReturn("OLTP");
EventExecutor eventExecutor = mock(EventExecutor.class);
when(context.executor()).thenReturn(eventExecutor);
- new OKProxyState().execute(context, null, frontendEngine, connection);
+ new OKProxyState().execute(context, null, frontendEngine, connectionSession);
verify(eventExecutor).execute(any(CommandExecutorTask.class));
}
@@ -106,7 +108,7 @@ public final class OKProxyStateTest {
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<String>getValue(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE)).thenReturn("OLAP");
when(frontendEngine.getFrontendContext().isRequiredSameThreadForConnection()).thenReturn(true);
ExecutorService executorService = registerMockExecutorService(1);
- new OKProxyState().execute(context, null, frontendEngine, connection);
+ new OKProxyState().execute(context, null, frontendEngine, connectionSession);
verify(executorService).execute(any(CommandExecutorTask.class));
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(1);
}
@@ -115,7 +117,7 @@ public final class OKProxyStateTest {
public void assertExecuteWithProxyBackendExecutorSuitableForInvalidValue() {
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_HINT_ENABLED)).thenReturn(false);
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<String>getValue(ConfigurationPropertyKey.PROXY_BACKEND_EXECUTOR_SUITABLE)).thenReturn("invalid value");
- new OKProxyState().execute(context, null, frontendEngine, connection);
+ new OKProxyState().execute(context, null, frontendEngine, connectionSession);
}
@SuppressWarnings({"unchecked", "SameParameterValue"})
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
index e9bba13..7c058dd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
@@ -29,7 +29,8 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
@@ -57,7 +58,7 @@ public final class MySQLCommandExecuteEngine implements CommandExecuteEngine {
}
@Override
- public CommandExecutor getCommandExecutor(final CommandPacketType type, final CommandPacket packet, final JDBCConnectionSession connectionSession) throws SQLException {
+ public CommandExecutor getCommandExecutor(final CommandPacketType type, final CommandPacket packet, final ConnectionSession connectionSession) throws SQLException {
return MySQLCommandExecutorFactory.newInstance((MySQLCommandPacketType) type, packet, connectionSession);
}
@@ -78,7 +79,7 @@ public final class MySQLCommandExecuteEngine implements CommandExecuteEngine {
@Override
public boolean writeQueryData(final ChannelHandlerContext context,
- final JDBCConnectionSession connectionSession, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
+ final BackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
if (ResponseType.QUERY != queryCommandExecutor.getResponseType() || !context.channel().isActive()) {
return true;
}
@@ -89,7 +90,7 @@ public final class MySQLCommandExecuteEngine implements CommandExecuteEngine {
count++;
while (!context.channel().isWritable() && context.channel().isActive()) {
context.flush();
- connectionSession.getResourceLock().doAwait();
+ ((JDBCBackendConnection) backendConnection).getResourceLock().doAwait();
}
DatabasePacket<?> dataValue = queryCommandExecutor.getQueryRowPacket();
context.write(dataValue);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactory.java
index d612328..4b8640f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactory.java
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.binary.r
import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.fieldlist.MySQLComFieldListPacket;
import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.query.MySQLComQueryPacket;
import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.mysql.command.admin.initdb.MySQLComInitDbExecutor;
import org.apache.shardingsphere.proxy.frontend.mysql.command.admin.ping.MySQLComPingExecutor;
@@ -60,7 +60,7 @@ public final class MySQLCommandExecutorFactory {
* @return command executor
* @throws SQLException SQL exception
*/
- public static CommandExecutor newInstance(final MySQLCommandPacketType commandPacketType, final CommandPacket commandPacket, final JDBCConnectionSession connectionSession) throws SQLException {
+ public static CommandExecutor newInstance(final MySQLCommandPacketType commandPacketType, final CommandPacket commandPacket, final ConnectionSession connectionSession) throws SQLException {
log.debug("Execute packet type: {}, value: {}", commandPacketType, commandPacket);
switch (commandPacketType) {
case COM_QUIT:
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
index 69d6ddd..64a33f4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
@@ -38,13 +38,14 @@ import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
import org.apache.shardingsphere.proxy.backend.communication.SQLStatementSchemaHolder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
import org.apache.shardingsphere.proxy.backend.response.data.impl.BinaryQueryResponseCell;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
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.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
@@ -76,7 +77,7 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
private int currentSequenceId;
- public MySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket packet, final JDBCConnectionSession connectionSession) throws SQLException {
+ public MySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket packet, final ConnectionSession connectionSession) throws SQLException {
String schemaName = connectionSession.getSchemaName();
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
Optional<SQLParserRule> sqlParserRule = metaDataContexts.getGlobalRuleMetaData().findSingleRule(SQLParserRule.class);
@@ -99,7 +100,8 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
return;
}
textProtocolBackendHandler = null;
- databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext, packet.getSql(), packet.getParameters(), connectionSession);
+ databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext, packet.getSql(), packet.getParameters(),
+ (JDBCBackendConnection) connectionSession.getBackendConnection());
}
private static Collection<ShardingSphereRule> getRules(final String schemaName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
index 6517bed..cce8d5d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
@@ -31,8 +31,9 @@ import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -59,7 +60,7 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
private int currentSequenceId;
- public MySQLComFieldListPacketExecutor(final MySQLComFieldListPacket packet, final JDBCConnectionSession connectionSession) {
+ public MySQLComFieldListPacketExecutor(final MySQLComFieldListPacket packet, final ConnectionSession connectionSession) {
this.packet = packet;
schemaName = connectionSession.getDefaultSchemaName();
String sql = String.format(SQL, packet.getTable(), schemaName);
@@ -69,7 +70,8 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
DatabaseTypeRegistry.getTrunkDatabaseTypeName(metaDataContexts.getMetaData(schemaName).getResource().getDatabaseType()), sqlParserRule.orElse(null));
SQLStatement sqlStatement = sqlStatementParserEngine.parse(sql, false);
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaDataMap(), Collections.emptyList(), sqlStatement, schemaName);
- databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext, sql, connectionSession);
+ JDBCBackendConnection backendConnection = (JDBCBackendConnection) connectionSession.getBackendConnection();
+ databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext, sql, backendConnection);
characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
index 8c86224..8626370 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
@@ -24,10 +24,10 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.MyS
import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.query.MySQLComQueryPacket;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
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.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
@@ -51,7 +51,7 @@ public final class MySQLComQueryPacketExecutor implements QueryCommandExecutor {
private int currentSequenceId;
- public MySQLComQueryPacketExecutor(final MySQLComQueryPacket packet, final JDBCConnectionSession connectionSession) throws SQLException {
+ public MySQLComQueryPacketExecutor(final MySQLComQueryPacket packet, final ConnectionSession connectionSession) throws SQLException {
textProtocolBackendHandler = TextProtocolBackendHandlerFactory.newInstance(DatabaseTypeRegistry.getActualDatabaseType("MySQL"), packet.getSql(), connectionSession);
characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
index 83ec3c8..4c3b22f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
@@ -31,16 +31,17 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.mysql.command.admin.initdb.MySQLComInitDbExecutor;
import org.apache.shardingsphere.proxy.frontend.mysql.command.admin.ping.MySQLComPingExecutor;
import org.apache.shardingsphere.proxy.frontend.mysql.command.admin.quit.MySQLComQuitExecutor;
@@ -77,13 +78,18 @@ public final class MySQLCommandExecutorFactoryTest {
private final SQLParserRule sqlParserRule = new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build());
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
@Before
public void setUp() throws ReflectiveOperationException {
when(connectionSession.getSchemaName()).thenReturn("logic_db");
when(connectionSession.getDefaultSchemaName()).thenReturn("logic_db");
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get()).thenReturn(MySQLCharacterSet.UTF8MB4_GENERAL_CI);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
Field contextManagerField = ProxyContext.getInstance().getClass().getDeclaredField("contextManager");
contextManagerField.setAccessible(true);
ShardingSphereMetaData metaData = mockShardingSphereMetaData();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
index c06416b..463a6c2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
@@ -23,20 +23,21 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.binary.e
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.federation.optimizer.context.OptimizerContext;
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.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
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.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -71,7 +72,10 @@ public final class MySQLComStmtExecuteExecutorTest {
private DatabaseCommunicationEngine databaseCommunicationEngine;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
+
+ @Mock
+ private JDBCBackendConnection backendConnection;
@Before
public void setUp() throws ReflectiveOperationException {
@@ -85,6 +89,8 @@ public final class MySQLComStmtExecuteExecutorTest {
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
contextManagerField.set(ProxyContext.getInstance(), contextManager);
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get()).thenReturn(MySQLCharacterSet.UTF8MB4_GENERAL_CI);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(SQLParserRule.class)).thenReturn(Optional.of(sqlParserRule));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
index 2f81eb5..3a96185 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
@@ -20,10 +20,10 @@ package org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCharacterSet;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.query.MySQLComQueryPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
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.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -53,7 +53,7 @@ public final class MySQLComQueryPacketExecutorTest {
private MySQLComQueryPacket packet;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Before
public void setUp() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java
index 2cdfa8b..0a1d0a8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.BackendConnection;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
@@ -56,7 +56,7 @@ public final class OpenGaussCommandExecuteEngine implements CommandExecuteEngine
}
@Override
- public CommandExecutor getCommandExecutor(final CommandPacketType type, final CommandPacket packet, final JDBCConnectionSession connectionSession) throws SQLException {
+ public CommandExecutor getCommandExecutor(final CommandPacketType type, final CommandPacket packet, final ConnectionSession connectionSession) throws SQLException {
PostgreSQLConnectionContext connectionContext = PostgreSQLConnectionContextRegistry.getInstance().get(connectionSession.getConnectionId());
return OpenGaussCommandExecutorFactory.newInstance(type, packet, connectionSession, connectionContext);
}
@@ -79,7 +79,7 @@ public final class OpenGaussCommandExecuteEngine implements CommandExecuteEngine
@Override
public boolean writeQueryData(final ChannelHandlerContext context,
- final JDBCConnectionSession connectionSession, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
- return postgreSQLCommandExecuteEngine.writeQueryData(context, connectionSession, queryCommandExecutor, headerPackagesCount);
+ final BackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
+ return postgreSQLCommandExecuteEngine.writeQueryData(context, backendConnection, queryCommandExecutor, headerPackagesCount);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactory.java
index 4f904fb..9df0c76 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactory.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.opengauss.command.query.extended.bind.OpenGaussComBatchBindExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.PostgreSQLCommandExecutorFactory;
@@ -52,7 +52,7 @@ public final class OpenGaussCommandExecutorFactory {
* @throws SQLException SQL exception
*/
public static CommandExecutor newInstance(final CommandPacketType commandPacketType, final CommandPacket commandPacket,
- final JDBCConnectionSession connectionSession, final PostgreSQLConnectionContext connectionContext) throws SQLException {
+ final ConnectionSession connectionSession, final PostgreSQLConnectionContext connectionContext) throws SQLException {
return commandPacketType == OpenGaussCommandPacketType.BATCH_BIND_COMMAND ? new OpenGaussComBatchBindExecutor((OpenGaussComBatchBindPacket) commandPacket, connectionSession)
: PostgreSQLCommandExecutorFactory.newInstance((PostgreSQLCommandPacketType) commandPacketType, (PostgreSQLCommandPacket) commandPacket, connectionSession, connectionContext);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java
index ef40f6b..966336d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java
@@ -32,10 +32,11 @@ import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
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.frontend.command.executor.QueryCommandExecutor;
import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.PostgreSQLCommand;
@@ -56,7 +57,7 @@ public final class OpenGaussComBatchBindExecutor implements QueryCommandExecutor
private final OpenGaussComBatchBindPacket packet;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
private SQLStatement sqlStatement;
@@ -76,14 +77,15 @@ public final class OpenGaussComBatchBindExecutor implements QueryCommandExecutor
updateCount += ((UpdateResponseHeader) responseHeader).getUpdateCount();
}
} finally {
- connectionSession.closeDatabaseCommunicationEngines(false);
+ ((JDBCBackendConnection) connectionSession.getBackendConnection()).closeDatabaseCommunicationEngines(false);
}
}
return Collections.singletonList(new PostgreSQLBindCompletePacket());
}
private DatabaseCommunicationEngine newEngine(final List<Object> parameter) {
- return DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(getSqlStatementContext(parameter), packet.getSql(), parameter, connectionSession);
+ return DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(getSqlStatementContext(parameter), packet.getSql(), parameter,
+ (JDBCBackendConnection) connectionSession.getBackendConnection());
}
private SQLStatementContext<?> getSqlStatementContext(final List<Object> parameters) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
index 009b326..f7f2b11 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
@@ -31,7 +31,8 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQ
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
@@ -65,7 +66,7 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
}
@Override
- public CommandExecutor getCommandExecutor(final CommandPacketType type, final CommandPacket packet, final JDBCConnectionSession connectionSession) throws SQLException {
+ public CommandExecutor getCommandExecutor(final CommandPacketType type, final CommandPacket packet, final ConnectionSession connectionSession) throws SQLException {
PostgreSQLConnectionContext connectionContext = PostgreSQLConnectionContextRegistry.getInstance().get(connectionSession.getConnectionId());
if (connectionContext.isErrorOccurred() && PostgreSQLCommandPacketType.isExtendedProtocolPacketType((PostgreSQLCommandPacketType) type) && PostgreSQLCommandPacketType.SYNC_COMMAND != type) {
return Collections::emptyList;
@@ -97,7 +98,7 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
@Override
public boolean writeQueryData(final ChannelHandlerContext context,
- final JDBCConnectionSession connectionSession, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
+ final BackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
if (queryCommandExecutor instanceof PostgreSQLComSyncExecutor) {
return true;
}
@@ -106,26 +107,26 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
return true;
}
if (queryCommandExecutor instanceof PostgreSQLComQueryExecutor) {
- return processSimpleQuery(context, connectionSession, (PostgreSQLComQueryExecutor) queryCommandExecutor);
+ return processSimpleQuery(context, (JDBCBackendConnection) backendConnection, (PostgreSQLComQueryExecutor) queryCommandExecutor);
}
- writeDataPackets(context, connectionSession, queryCommandExecutor);
+ writeDataPackets(context, (JDBCBackendConnection) backendConnection, queryCommandExecutor);
return false;
}
- private boolean processSimpleQuery(final ChannelHandlerContext context, final JDBCConnectionSession connectionSession, final PostgreSQLComQueryExecutor queryExecutor) throws SQLException {
+ private boolean processSimpleQuery(final ChannelHandlerContext context, final JDBCBackendConnection backendConnection, final PostgreSQLComQueryExecutor queryExecutor) throws SQLException {
if (ResponseType.UPDATE == queryExecutor.getResponseType()) {
- context.write(new PostgreSQLReadyForQueryPacket(connectionSession.getTransactionStatus().isInTransaction()));
+ context.write(new PostgreSQLReadyForQueryPacket(backendConnection.getConnectionSession().getTransactionStatus().isInTransaction()));
return true;
}
- long dataRows = writeDataPackets(context, connectionSession, queryExecutor);
+ long dataRows = writeDataPackets(context, backendConnection, queryExecutor);
if (ResponseType.QUERY == queryExecutor.getResponseType()) {
context.write(new PostgreSQLCommandCompletePacket(PostgreSQLCommand.SELECT.name(), dataRows));
}
- context.write(new PostgreSQLReadyForQueryPacket(connectionSession.getTransactionStatus().isInTransaction()));
+ context.write(new PostgreSQLReadyForQueryPacket(backendConnection.getConnectionSession().getTransactionStatus().isInTransaction()));
return true;
}
- private long writeDataPackets(final ChannelHandlerContext context, final JDBCConnectionSession connectionSession, final QueryCommandExecutor queryCommandExecutor) throws SQLException {
+ private long writeDataPackets(final ChannelHandlerContext context, final JDBCBackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor) throws SQLException {
long dataRows = 0;
int flushCount = 0;
int proxyFrontendFlushThreshold = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Integer>getValue(ConfigurationPropertyKey.PROXY_FRONTEND_FLUSH_THRESHOLD);
@@ -133,7 +134,7 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
flushCount++;
while (!context.channel().isWritable() && context.channel().isActive()) {
context.flush();
- connectionSession.getResourceLock().doAwait();
+ backendConnection.getResourceLock().doAwait();
}
DatabasePacket<?> resultValue = queryCommandExecutor.getQueryRowPacket();
context.write(resultValue);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactory.java
index 412e04c..fb453211 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactory.java
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.execute.PostgreSQLComExecutePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.parse.PostgreSQLComParsePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.generic.PostgreSQLComTerminationExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.generic.PostgreSQLUnsupportedCommandExecutor;
@@ -61,7 +61,7 @@ public final class PostgreSQLCommandExecutorFactory {
* @throws SQLException SQL exception
*/
public static CommandExecutor newInstance(final PostgreSQLCommandPacketType commandPacketType, final PostgreSQLCommandPacket commandPacket,
- final JDBCConnectionSession connectionSession, final PostgreSQLConnectionContext connectionContext) throws SQLException {
+ final ConnectionSession connectionSession, final PostgreSQLConnectionContext connectionContext) throws SQLException {
log.debug("Execute packet type: {}, value: {}", commandPacketType, commandPacket);
switch (commandPacketType) {
case SIMPLE_QUERY:
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContext.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContext.java
index 514d42e..947024f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContext.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContext.java
@@ -23,7 +23,7 @@ import lombok.Setter;
import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLValueFormat;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLPreparedStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.PostgreSQLPortal;
@@ -57,13 +57,13 @@ public final class PostgreSQLConnectionContext {
* @param preparedStatement prepared statement
* @param parameters bind parameters
* @param resultFormats result formats
- * @param connectionSession connection session
+ * @param backendConnection backend connection
* @return a new portal
* @throws SQLException SQL exception
*/
public PostgreSQLPortal createPortal(final String portal, final PostgreSQLPreparedStatement preparedStatement, final List<Object> parameters, final List<PostgreSQLValueFormat> resultFormats,
- final JDBCConnectionSession connectionSession) throws SQLException {
- PostgreSQLPortal result = new PostgreSQLPortal(preparedStatement, parameters, resultFormats, connectionSession);
+ final JDBCBackendConnection backendConnection) throws SQLException {
+ PostgreSQLPortal result = new PostgreSQLPortal(preparedStatement, parameters, resultFormats, backendConnection);
portals.put(portal, result);
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortal.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortal.java
index 3d2f3bd..6de8d56 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortal.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortal.java
@@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
@@ -68,25 +68,25 @@ public final class PostgreSQLPortal {
private final TextProtocolBackendHandler textProtocolBackendHandler;
- private final JDBCConnectionSession connectionSession;
+ private final JDBCBackendConnection backendConnection;
private ResponseHeader responseHeader;
public PostgreSQLPortal(final PostgreSQLPreparedStatement preparedStatement, final List<Object> parameters, final List<PostgreSQLValueFormat> resultFormats,
- final JDBCConnectionSession connectionSession) throws SQLException {
+ final JDBCBackendConnection backendConnection) throws SQLException {
this.sqlStatement = preparedStatement.getSqlStatement();
this.resultFormats = resultFormats;
- this.connectionSession = connectionSession;
+ this.backendConnection = backendConnection;
if (sqlStatement instanceof TCLStatement || sqlStatement instanceof EmptyStatement || sqlStatement instanceof DistSQLStatement) {
databaseCommunicationEngine = null;
textProtocolBackendHandler =
- TextProtocolBackendHandlerFactory.newInstance(DatabaseTypeRegistry.getActualDatabaseType("PostgreSQL"), preparedStatement.getSql(), connectionSession);
+ TextProtocolBackendHandlerFactory.newInstance(DatabaseTypeRegistry.getActualDatabaseType("PostgreSQL"), preparedStatement.getSql(), backendConnection.getConnectionSession());
return;
}
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(
- ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), parameters, sqlStatement, connectionSession.getDefaultSchemaName());
+ ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataMap(), parameters, sqlStatement, backendConnection.getConnectionSession().getDefaultSchemaName());
databaseCommunicationEngine = DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
- preparedStatement.getSql(), parameters, connectionSession);
+ preparedStatement.getSql(), parameters, backendConnection);
textProtocolBackendHandler = null;
}
@@ -181,7 +181,7 @@ public final class PostgreSQLPortal {
* Suspend the portal.
*/
public void suspend() {
- connectionSession.markResourceInUse(databaseCommunicationEngine);
+ backendConnection.markResourceInUse(databaseCommunicationEngine);
}
/**
@@ -191,7 +191,7 @@ public final class PostgreSQLPortal {
*/
public void close() throws SQLException {
if (null != databaseCommunicationEngine) {
- connectionSession.unmarkResourceInUse(databaseCommunicationEngine);
+ backendConnection.unmarkResourceInUse(databaseCommunicationEngine);
}
if (null != textProtocolBackendHandler) {
textProtocolBackendHandler.close();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java
index feefa71..cbd928f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java
@@ -23,7 +23,8 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLPreparedStatementRegistry;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.PostgreSQLBindCompletePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.PostgreSQLComBindPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.PostgreSQLConnectionContext;
@@ -41,12 +42,13 @@ public final class PostgreSQLComBindExecutor implements CommandExecutor {
private final PostgreSQLComBindPacket packet;
- private final JDBCConnectionSession connectionSession;
+ private final ConnectionSession connectionSession;
@Override
public Collection<DatabasePacket<?>> execute() throws SQLException {
PostgreSQLPreparedStatement preparedStatement = PostgreSQLPreparedStatementRegistry.getInstance().get(connectionSession.getConnectionId(), packet.getStatementId());
- connectionContext.createPortal(packet.getPortal(), preparedStatement, packet.getParameters(), packet.getResultFormats(), connectionSession).execute();
+ JDBCBackendConnection backendConnection = (JDBCBackendConnection) connectionSession.getBackendConnection();
+ connectionContext.createPortal(packet.getPortal(), preparedStatement, packet.getParameters(), packet.getResultFormats(), backendConnection).execute();
return Collections.singletonList(new PostgreSQLBindCompletePacket());
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java
index 069e814..db95bc7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutor.java
@@ -27,11 +27,11 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.sim
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLDataRowPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
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.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
@@ -61,7 +61,7 @@ public final class PostgreSQLComQueryExecutor implements QueryCommandExecutor {
private volatile ResponseType responseType;
public PostgreSQLComQueryExecutor(final PostgreSQLConnectionContext connectionContext, final PostgreSQLComQueryPacket comQueryPacket,
- final JDBCConnectionSession connectionSession) throws SQLException {
+ final ConnectionSession connectionSession) throws SQLException {
this.connectionContext = connectionContext;
textProtocolBackendHandler = TextProtocolBackendHandlerFactory.newInstance(DatabaseTypeRegistry.getActualDatabaseType("PostgreSQL"), comQueryPacket.getSql(), connectionSession);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
index 0d81572..277c582 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
@@ -22,9 +22,10 @@ import io.netty.channel.ChannelHandlerContext;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.ResourceLock;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.sync.PostgreSQLComSyncExecutor;
@@ -63,7 +64,7 @@ public final class PostgreSQLCommandExecuteEngineTest {
private QueryCommandExecutor queryCommandExecutor;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Before
public void setUp() {
@@ -76,7 +77,9 @@ public final class PostgreSQLCommandExecuteEngineTest {
PostgreSQLComQueryExecutor comQueryExecutor = mock(PostgreSQLComQueryExecutor.class);
when(comQueryExecutor.getResponseType()).thenReturn(ResponseType.UPDATE);
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
- boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, connectionSession, comQueryExecutor, 0);
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, backendConnection, comQueryExecutor, 0);
assertTrue(actual);
verify(channelHandlerContext).write(any(PostgreSQLReadyForQueryPacket.class));
}
@@ -85,14 +88,14 @@ public final class PostgreSQLCommandExecuteEngineTest {
public void assertWriteQueryDataWithUpdate() throws SQLException {
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
when(queryCommandExecutor.getResponseType()).thenReturn(ResponseType.UPDATE);
- boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, connectionSession, queryCommandExecutor, 0);
+ boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, mock(JDBCBackendConnection.class), queryCommandExecutor, 0);
assertFalse(actual);
}
@Test
public void assertWriteQueryDataWithComSync() throws SQLException {
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
- boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, connectionSession, new PostgreSQLComSyncExecutor(connectionContext, connectionSession), 0);
+ boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, mock(JDBCBackendConnection.class), new PostgreSQLComSyncExecutor(connectionContext, connectionSession), 0);
assertTrue(actual);
verify(channelHandlerContext, never()).write(any(Object.class));
}
@@ -102,7 +105,7 @@ public final class PostgreSQLCommandExecuteEngineTest {
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
when(queryCommandExecutor.getResponseType()).thenReturn(ResponseType.QUERY);
when(channel.isActive()).thenReturn(false);
- boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, connectionSession, queryCommandExecutor, 0);
+ boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, mock(JDBCBackendConnection.class), queryCommandExecutor, 0);
assertTrue(actual);
verify(channelHandlerContext).write(isA(PostgreSQLCommandCompletePacket.class));
}
@@ -115,11 +118,13 @@ public final class PostgreSQLCommandExecuteEngineTest {
when(queryCommandExecutor.next()).thenReturn(true, false);
when(channel.isWritable()).thenReturn(false, true);
ResourceLock resourceLock = mock(ResourceLock.class);
- when(connectionSession.getResourceLock()).thenReturn(resourceLock);
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class);
+ when(backendConnection.getResourceLock()).thenReturn(resourceLock);
+ when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
PostgreSQLPacket packet = mock(PostgreSQLPacket.class);
when(queryCommandExecutor.getQueryRowPacket()).thenReturn(packet);
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
- boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, connectionSession, queryCommandExecutor, 0);
+ boolean actual = commandExecuteEngine.writeQueryData(channelHandlerContext, backendConnection, queryCommandExecutor, 0);
assertTrue(actual);
verify(resourceLock).doAwait();
verify(channelHandlerContext).write(packet);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
index d978b71..f5d87f5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.execute.PostgreSQLComExecutePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.parse.PostgreSQLComParsePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.generic.PostgreSQLComTerminationExecutor;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.bind.PostgreSQLComBindExecutor;
@@ -61,7 +61,7 @@ import static org.mockito.Mockito.when;
public final class PostgreSQLCommandExecutorFactoryTest {
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Mock
private PostgreSQLConnectionContext connectionContext;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContextTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContextTest.java
index 528476b..805f313 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContextTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLConnectionContextTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.frontend.postgresql.command;
import lombok.SneakyThrows;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLPreparedStatement;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.PostgreSQLPortal;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.EmptyStatement;
import org.junit.Test;
@@ -48,7 +48,7 @@ public final class PostgreSQLConnectionContextTest {
PostgreSQLPreparedStatement statement = mock(PostgreSQLPreparedStatement.class);
when(statement.getSql()).thenReturn("");
when(statement.getSqlStatement()).thenReturn(new EmptyStatement());
- PostgreSQLPortal actual = context.createPortal("P_1", statement, Collections.emptyList(), Collections.emptyList(), mock(JDBCConnectionSession.class));
+ PostgreSQLPortal actual = context.createPortal("P_1", statement, Collections.emptyList(), Collections.emptyList(), mock(JDBCBackendConnection.class));
assertThat(actual, is(getPortals(context).get("P_1")));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortalTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortalTest.java
index d302b18..2827ef7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortalTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLPortalTest.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.Pos
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLPreparedStatement;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLDataRowPacket;
import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseRow;
import org.apache.shardingsphere.proxy.backend.response.data.impl.BinaryQueryResponseCell;
import org.apache.shardingsphere.proxy.backend.response.data.impl.TextQueryResponseCell;
@@ -67,7 +67,7 @@ public final class PostgreSQLPortalTest {
private TextProtocolBackendHandler textProtocolBackendHandler;
@Mock
- private JDBCConnectionSession connectionSession;
+ private JDBCBackendConnection backendConnection;
private PostgreSQLPortal portal;
@@ -77,7 +77,7 @@ public final class PostgreSQLPortalTest {
when(preparedStatement.getSql()).thenReturn("");
when(preparedStatement.getSqlStatement()).thenReturn(new EmptyStatement());
List<PostgreSQLValueFormat> resultFormats = new ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT, PostgreSQLValueFormat.BINARY));
- portal = new PostgreSQLPortal(preparedStatement, Collections.emptyList(), resultFormats, connectionSession);
+ portal = new PostgreSQLPortal(preparedStatement, Collections.emptyList(), resultFormats, backendConnection);
}
@Test
@@ -164,7 +164,7 @@ public final class PostgreSQLPortalTest {
setDatabaseCommunicationEngine(databaseCommunicationEngine);
setTextProtocolBackendHandler(null);
portal.suspend();
- verify(connectionSession).markResourceInUse(databaseCommunicationEngine);
+ verify(backendConnection).markResourceInUse(databaseCommunicationEngine);
}
@Test
@@ -172,7 +172,7 @@ public final class PostgreSQLPortalTest {
setDatabaseCommunicationEngine(databaseCommunicationEngine);
setTextProtocolBackendHandler(textProtocolBackendHandler);
portal.close();
- verify(connectionSession).unmarkResourceInUse(databaseCommunicationEngine);
+ verify(backendConnection).unmarkResourceInUse(databaseCommunicationEngine);
verify(textProtocolBackendHandler).close();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
index 3a92de7..4ce9df6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
@@ -22,7 +22,8 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLPreparedStatementRegistry;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.PostgreSQLBindCompletePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.PostgreSQLComBindPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.PostgreSQLConnectionContext;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.PostgreSQLPortal;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.EmptyStatement;
@@ -44,6 +45,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -60,7 +62,7 @@ public final class PostgreSQLComBindExecutorTest {
private PostgreSQLComBindPacket bindPacket;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Before
@SuppressWarnings("unchecked")
@@ -72,7 +74,9 @@ public final class PostgreSQLComBindExecutorTest {
when(bindPacket.getParameters()).thenReturn(Collections.emptyList());
when(bindPacket.getResultFormats()).thenReturn(Collections.emptyList());
when(connectionSession.getConnectionId()).thenReturn(1);
- when(connectionContext.createPortal(anyString(), any(PostgreSQLPreparedStatement.class), any(List.class), any(List.class), eq(connectionSession))).thenReturn(portal);
+ JDBCBackendConnection backendConnection = mock(JDBCBackendConnection.class);
+ when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(connectionContext.createPortal(anyString(), any(PostgreSQLPreparedStatement.class), any(List.class), any(List.class), eq(backendConnection))).thenReturn(portal);
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/close/PostgreSQLComCloseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/close/PostgreSQLComCloseExecutorTest.java
index d12e8b7..be8e6f7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/close/PostgreSQLComCloseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/close/PostgreSQLComCloseExecutorTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLPreparedStatementRegistry;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.close.PostgreSQLCloseCompletePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.close.PostgreSQLComClosePacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.PostgreSQLConnectionContext;
import org.junit.Before;
import org.junit.Test;
@@ -48,7 +48,7 @@ public final class PostgreSQLComCloseExecutorTest {
private PostgreSQLComClosePacket packet;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Before
public void setup() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/sync/PostgreSQLComSyncExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/sync/PostgreSQLComSyncExecutorTest.java
index 219e93c..b9ef033 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/sync/PostgreSQLComSyncExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/sync/PostgreSQLComSyncExecutorTest.java
@@ -19,8 +19,8 @@ package org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extend
import lombok.SneakyThrows;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.PostgreSQLConnectionContext;
import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -44,7 +44,7 @@ public final class PostgreSQLComSyncExecutorTest {
private PostgreSQLConnectionContext connectionContext;
@Mock
- private JDBCConnectionSession connectionSession;
+ private ConnectionSession connectionSession;
@Test
public void assertNewInstance() {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java
index aa469d6..c16547d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/simple/PostgreSQLComQueryExecutorTest.java
@@ -20,14 +20,14 @@ package org.apache.shardingsphere.proxy.frontend.postgresql.command.query.simple
import lombok.SneakyThrows;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLDataRowPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLRowDescriptionPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.simple.PostgreSQLComQueryPacket;
-import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLDataRowPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLCommandCompletePacket;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
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.TextProtocolBackendHandler;
import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.PostgreSQLConnectionContext;
@@ -67,7 +67,7 @@ public final class PostgreSQLComQueryExecutorTest {
@Before
public void setUp() throws SQLException {
PostgreSQLComQueryPacket queryPacket = mock(PostgreSQLComQueryPacket.class);
- JDBCConnectionSession connectionSession = mock(JDBCConnectionSession.class);
+ ConnectionSession connectionSession = mock(ConnectionSession.class);
when(queryPacket.getSql()).thenReturn("");
queryExecutor = new PostgreSQLComQueryExecutor(connectionContext, queryPacket, connectionSession);
setMockFieldIntoExecutor(queryExecutor);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecuteEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecuteEngine.java
index e9ed058..8560bd5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecuteEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecuteEngine.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
-import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCConnectionSession;
+import org.apache.shardingsphere.proxy.backend.communication.BackendConnection;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
@@ -63,7 +63,7 @@ public interface CommandExecuteEngine {
* @return command executor
* @throws SQLException SQL exception
*/
- CommandExecutor getCommandExecutor(CommandPacketType type, CommandPacket packet, JDBCConnectionSession connectionSession) throws SQLException;
+ CommandExecutor getCommandExecutor(CommandPacketType type, CommandPacket packet, ConnectionSession connectionSession) throws SQLException;
/**
* Get error packet.
@@ -94,11 +94,11 @@ public interface CommandExecuteEngine {
* Write query data.
*
* @param context channel handler context
- * @param connectionSession connection session
+ * @param backendConnection backend connection
* @param queryCommandExecutor query command executor
* @param headerPackagesCount count of header packages
* @return is need flush
* @throws SQLException SQL exception
*/
- boolean writeQueryData(ChannelHandlerContext context, JDBCConnectionSession connectionSession, QueryCommandExecutor queryCommandExecutor, int headerPackagesCount) throws SQLException;
+ boolean writeQueryData(ChannelHandlerContext context, BackendConnection backendConnection, QueryCommandExecutor queryCommandExecutor, int headerPackagesCount) throws SQLException;
}