You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/05/06 11:14:54 UTC
[shardingsphere] branch master updated: Rename DatabaseConnectionManager (#25496)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 03ec587d848 Rename DatabaseConnectionManager (#25496)
03ec587d848 is described below
commit 03ec587d8480d9315e36c45de957db11082b33f4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat May 6 19:14:46 2023 +0800
Rename DatabaseConnectionManager (#25496)
---
...Manager.java => DatabaseConnectionManager.java} | 10 +--
.../driver/DriverExecutionPrepareEngine.java | 8 +-
.../driver/executor/DriverExecutor.java | 4 +-
.../jdbc/adapter/AbstractStatementAdapter.java | 4 +-
...r.java => DriverDatabaseConnectionManager.java} | 8 +-
.../core/connection/ShardingSphereConnection.java | 48 +++++-----
.../metadata/ShardingSphereDatabaseMetaData.java | 4 +-
.../statement/ShardingSpherePreparedStatement.java | 18 ++--
.../core/statement/ShardingSphereStatement.java | 16 ++--
.../batch/BatchPreparedStatementExecutorTest.java | 4 +-
...va => DriverDatabaseConnectionManagerTest.java} | 44 ++++-----
.../connection/ShardingSphereConnectionTest.java | 42 ++++-----
.../datasource/ShardingSphereDataSourceTest.java | 2 +-
.../ShardingSphereDatabaseMetaDataTest.java | 4 +-
.../proxy/backend/connector/DatabaseConnector.java | 38 ++++----
.../connector/DatabaseConnectorFactory.java | 10 +--
...on.java => ProxyDatabaseConnectionManager.java} | 6 +-
.../proxy/backend/connector/ProxySQLExecutor.java | 41 +++++----
.../transaction/BackendTransactionManager.java | 10 +--
.../jdbc/transaction/LocalTransactionManager.java | 14 +--
.../handler/ProxyBackendHandlerFactory.java | 2 +-
.../data/DatabaseBackendHandlerFactory.java | 2 +-
.../data/impl/UnicastDatabaseBackendHandler.java | 2 +-
.../ral/queryable/ShowDistVariableExecutor.java | 2 +-
.../ral/queryable/ShowDistVariablesExecutor.java | 2 +-
.../handler/distsql/rul/sql/PreviewHandler.java | 2 +-
.../transaction/TransactionBackendHandler.java | 2 +-
.../TransactionBackendHandlerFactory.java | 2 +-
.../handler/transaction/TransactionXAHandler.java | 2 +-
.../proxy/backend/session/ConnectionSession.java | 10 +--
.../connector/DatabaseConnectorFactoryTest.java | 12 +--
.../backend/connector/DatabaseConnectorTest.java | 18 ++--
.../backend/connector/MockConnectionUtils.java | 8 +-
...ava => ProxyDatabaseConnectionManagerTest.java} | 100 ++++++++++-----------
.../backend/connector/ProxySQLExecutorTest.java | 30 +++----
.../transaction/BackendTransactionManagerTest.java | 14 +--
.../transaction/LocalTransactionManagerTest.java | 12 +--
.../handler/ProxyBackendHandlerFactoryTest.java | 8 +-
.../data/DatabaseBackendHandlerFactoryTest.java | 6 +-
.../impl/UnicastDatabaseBackendHandlerTest.java | 6 +-
.../queryable/ShowDistVariableExecutorTest.java | 2 +-
.../TransactionBackendHandlerFactoryTest.java | 20 ++---
.../transaction/TransactionBackendHandlerTest.java | 8 +-
.../backend/session/ConnectionSessionTest.java | 10 +--
.../admin/MySQLSetVariableAdminExecutor.java | 2 +-
.../executor/UnicastResourceShowExecutor.java | 2 +-
.../MySQLSetVariableAdminExecutorTest.java | 8 +-
.../frontend/command/CommandExecutorTask.java | 4 +-
.../netty/FrontendChannelInboundHandler.java | 4 +-
.../frontend/command/CommandExecutorTaskTest.java | 18 ++--
.../frontend/command/CommandExecuteEngine.java | 7 +-
.../mysql/command/MySQLCommandExecuteEngine.java | 8 +-
.../admin/MySQLComResetConnectionExecutor.java | 2 +-
.../fieldlist/MySQLComFieldListPacketExecutor.java | 6 +-
.../text/query/MySQLMultiStatementsHandler.java | 4 +-
.../command/MySQLCommandExecutorFactoryTest.java | 6 +-
.../admin/MySQLComResetConnectionExecutorTest.java | 6 +-
.../execute/MySQLComStmtExecuteExecutorTest.java | 6 +-
.../query/MySQLMultiStatementsHandlerTest.java | 8 +-
.../command/OpenGaussCommandExecuteEngine.java | 6 +-
.../bind/OpenGaussComBatchBindExecutor.java | 2 +-
.../bind/OpenGaussComBatchBindExecutorTest.java | 8 +-
.../command/PostgreSQLCommandExecuteEngine.java | 20 +++--
.../postgresql/command/query/extended/Portal.java | 18 ++--
.../PostgreSQLBatchedStatementsExecutor.java | 4 +-
.../extended/bind/PostgreSQLComBindExecutor.java | 6 +-
.../describe/PostgreSQLComDescribeExecutor.java | 6 +-
.../PostgreSQLCommandExecuteEngineTest.java | 24 ++---
.../command/query/extended/PortalTest.java | 24 ++---
...egatedBatchedStatementsCommandExecutorTest.java | 8 +-
.../PostgreSQLBatchedStatementsExecutorTest.java | 8 +-
.../bind/PostgreSQLComBindExecutorTest.java | 8 +-
.../PostgreSQLComDescribeExecutorTest.java | 8 +-
73 files changed, 432 insertions(+), 426 deletions(-)
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/ExecutorConnectionManager.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DatabaseConnectionManager.java
similarity index 89%
rename from infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/ExecutorConnectionManager.java
rename to infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DatabaseConnectionManager.java
index 0182ae295fe..2bbcb171526 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/ExecutorConnectionManager.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DatabaseConnectionManager.java
@@ -24,19 +24,19 @@ import java.util.Collection;
import java.util.List;
/**
- * Executor connection manager.
+ * Database connection manager.
*
- * @param <C> type of resource connection
+ * @param <C> type of database connection
*/
-public interface ExecutorConnectionManager<C> {
+public interface DatabaseConnectionManager<C> {
/**
- * Get connections.
+ * Get database connections.
*
* @param dataSourceName data source name
* @param connectionSize connection size
* @param connectionMode connection mode
- * @return connections
+ * @return database connections
* @throws SQLException SQL exception
*/
List<C> getConnections(String dataSourceName, int connectionSize, ConnectionMode connectionMode) throws SQLException;
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
index 4481d9188b3..382661151da 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
@@ -45,7 +45,7 @@ public final class DriverExecutionPrepareEngine<T extends DriverExecutionUnit<?>
@SuppressWarnings("rawtypes")
private static final Map<String, SQLExecutionUnitBuilder> TYPE_TO_BUILDER_MAP = new ConcurrentHashMap<>(8, 1);
- private final ExecutorConnectionManager<C> connectionManager;
+ private final DatabaseConnectionManager<C> databaseConnectionManager;
private final ExecutorStatementManager<C, ?, ?> statementManager;
@@ -56,11 +56,11 @@ public final class DriverExecutionPrepareEngine<T extends DriverExecutionUnit<?>
private final Map<String, DatabaseType> databaseTypes;
- public DriverExecutionPrepareEngine(final String type, final int maxConnectionsSizePerQuery, final ExecutorConnectionManager<C> connectionManager,
+ public DriverExecutionPrepareEngine(final String type, final int maxConnectionsSizePerQuery, final DatabaseConnectionManager<C> databaseConnectionManager,
final ExecutorStatementManager<C, ?, ?> statementManager, final StorageResourceOption option, final Collection<ShardingSphereRule> rules,
final Map<String, DatabaseType> databaseTypes) {
super(maxConnectionsSizePerQuery, rules);
- this.connectionManager = connectionManager;
+ this.databaseConnectionManager = databaseConnectionManager;
this.statementManager = statementManager;
this.option = option;
sqlExecutionUnitBuilder = getCachedSqlExecutionUnitBuilder(type);
@@ -85,7 +85,7 @@ public final class DriverExecutionPrepareEngine<T extends DriverExecutionUnit<?>
@Override
protected List<ExecutionGroup<T>> group(final String dataSourceName, final List<List<SQLUnit>> sqlUnitGroups, final ConnectionMode connectionMode) throws SQLException {
List<ExecutionGroup<T>> result = new LinkedList<>();
- List<C> connections = connectionManager.getConnections(dataSourceName, sqlUnitGroups.size(), connectionMode);
+ List<C> connections = databaseConnectionManager.getConnections(dataSourceName, sqlUnitGroups.size(), connectionMode);
int count = 0;
for (List<SQLUnit> each : sqlUnitGroups) {
result.add(createExecutionGroup(dataSourceName, each, connections.get(count++), connectionMode));
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java
index c77ee141203..e937e0e5f30 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java
@@ -48,9 +48,9 @@ public final class DriverExecutor implements AutoCloseable {
public DriverExecutor(final ShardingSphereConnection connection) {
MetaDataContexts metaDataContexts = connection.getContextManager().getMetaDataContexts();
ExecutorEngine executorEngine = connection.getContextManager().getExecutorEngine();
- JDBCExecutor jdbcExecutor = new JDBCExecutor(executorEngine, connection.getConnectionManager().getConnectionContext());
+ JDBCExecutor jdbcExecutor = new JDBCExecutor(executorEngine, connection.getDatabaseConnectionManager().getConnectionContext());
regularExecutor = new DriverJDBCExecutor(connection.getDatabaseName(), connection.getContextManager(), jdbcExecutor);
- rawExecutor = new RawExecutor(executorEngine, connection.getConnectionManager().getConnectionContext());
+ rawExecutor = new RawExecutor(executorEngine, connection.getDatabaseConnectionManager().getConnectionContext());
DatabaseType protocolType = metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType();
String schemaName = DatabaseTypeEngine.getDefaultSchemaName(protocolType, connection.getDatabaseName());
SQLFederationRule sqlFederationRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLFederationRule.class);
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java
index cb18db5d493..9566a29645f 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/adapter/AbstractStatementAdapter.java
@@ -193,10 +193,10 @@ public abstract class AbstractStatementAdapter extends AbstractUnsupportedOperat
}
protected final void handleExceptionInTransaction(final ShardingSphereConnection connection, final MetaDataContexts metaDataContexts) {
- if (connection.getConnectionManager().getConnectionTransaction().isInTransaction()) {
+ if (connection.getDatabaseConnectionManager().getConnectionTransaction().isInTransaction()) {
DatabaseType databaseType = metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType();
if (databaseType instanceof SchemaSupportedDatabaseType) {
- connection.getConnectionManager().getConnectionTransaction().setRollbackOnly(true);
+ connection.getDatabaseConnectionManager().getConnectionTransaction().setRollbackOnly(true);
}
}
}
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java
similarity index 98%
rename from jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
rename to jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java
index 43c11938116..c62e1906020 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManager.java
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCre
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.exception.OverallConnectionNotEnoughException;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
-import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorConnectionManager;
+import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager;
import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
import org.apache.shardingsphere.infra.instance.metadata.proxy.ProxyInstanceMetaData;
@@ -60,9 +60,9 @@ import java.util.Optional;
import java.util.Random;
/**
- * Connection manager.
+ * Database connection manager of ShardingSphere-JDBC.
*/
-public final class ConnectionManager implements ExecutorConnectionManager<Connection>, AutoCloseable {
+public final class DriverDatabaseConnectionManager implements DatabaseConnectionManager<Connection>, AutoCloseable {
private final Map<String, DataSource> dataSourceMap = new LinkedHashMap<>();
@@ -82,7 +82,7 @@ public final class ConnectionManager implements ExecutorConnectionManager<Connec
@Getter
private final ConnectionContext connectionContext;
- public ConnectionManager(final String databaseName, final ContextManager contextManager) {
+ public DriverDatabaseConnectionManager(final String databaseName, final ContextManager contextManager) {
dataSourceMap.putAll(contextManager.getDataSourceMap(databaseName));
dataSourceMap.putAll(getTrafficDataSourceMap(databaseName, contextManager));
physicalDataSourceMap.putAll(contextManager.getDataSourceMap(databaseName));
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index bc99c44487c..f98b6a5a0d5 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -51,7 +51,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
private final JDBCContext jdbcContext;
@Getter
- private final ConnectionManager connectionManager;
+ private final DriverDatabaseConnectionManager databaseConnectionManager;
private boolean autoCommit = true;
@@ -65,7 +65,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
this.databaseName = databaseName;
this.contextManager = contextManager;
this.jdbcContext = jdbcContext;
- connectionManager = new ConnectionManager(databaseName, contextManager);
+ databaseConnectionManager = new DriverDatabaseConnectionManager(databaseName, contextManager);
}
/**
@@ -74,7 +74,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
* @return true or false
*/
public boolean isHoldTransaction() {
- return connectionManager.getConnectionTransaction().isHoldTransaction(autoCommit);
+ return databaseConnectionManager.getConnectionTransaction().isHoldTransaction(autoCommit);
}
@Override
@@ -135,7 +135,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@Override
public void setAutoCommit(final boolean autoCommit) throws SQLException {
this.autoCommit = autoCommit;
- if (connectionManager.getConnectionTransaction().isLocalTransaction()) {
+ if (databaseConnectionManager.getConnectionTransaction().isLocalTransaction()) {
processLocalTransaction();
} else {
processDistributeTransaction();
@@ -143,21 +143,21 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
}
private void processLocalTransaction() throws SQLException {
- connectionManager.setAutoCommit(autoCommit);
+ databaseConnectionManager.setAutoCommit(autoCommit);
if (!autoCommit) {
getConnectionContext().getTransactionContext().setInTransaction(true);
}
}
private void processDistributeTransaction() throws SQLException {
- switch (connectionManager.getConnectionTransaction().getDistributedTransactionOperationType(autoCommit)) {
+ switch (databaseConnectionManager.getConnectionTransaction().getDistributedTransactionOperationType(autoCommit)) {
case BEGIN:
- connectionManager.close();
- connectionManager.getConnectionTransaction().begin();
+ databaseConnectionManager.close();
+ databaseConnectionManager.getConnectionTransaction().begin();
getConnectionContext().getTransactionContext().setInTransaction(true);
break;
case COMMIT:
- connectionManager.getConnectionTransaction().commit();
+ databaseConnectionManager.getConnectionTransaction().commit();
break;
default:
break;
@@ -167,9 +167,9 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@Override
public void commit() throws SQLException {
try {
- connectionManager.commit();
+ databaseConnectionManager.commit();
} finally {
- connectionManager.getConnectionTransaction().setRollbackOnly(false);
+ databaseConnectionManager.getConnectionTransaction().setRollbackOnly(false);
getConnectionContext().close();
}
}
@@ -177,9 +177,9 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@Override
public void rollback() throws SQLException {
try {
- connectionManager.rollback();
+ databaseConnectionManager.rollback();
} finally {
- connectionManager.getConnectionTransaction().setRollbackOnly(false);
+ databaseConnectionManager.getConnectionTransaction().setRollbackOnly(false);
getConnectionContext().close();
}
}
@@ -187,7 +187,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@Override
public void rollback(final Savepoint savepoint) throws SQLException {
checkClose();
- connectionManager.rollback(savepoint);
+ databaseConnectionManager.rollback(savepoint);
}
@Override
@@ -196,14 +196,14 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
if (!isHoldTransaction()) {
throw new SQLFeatureNotSupportedException("Savepoint can only be used in transaction blocks.");
}
- return connectionManager.setSavepoint(name);
+ return databaseConnectionManager.setSavepoint(name);
}
@Override
public Savepoint setSavepoint() throws SQLException {
checkClose();
ShardingSpherePreconditions.checkState(isHoldTransaction(), () -> new SQLFeatureNotSupportedException("Savepoint can only be used in transaction blocks."));
- return connectionManager.setSavepoint();
+ return databaseConnectionManager.setSavepoint();
}
@Override
@@ -212,7 +212,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
if (!isHoldTransaction()) {
return;
}
- connectionManager.releaseSavepoint(savepoint);
+ databaseConnectionManager.releaseSavepoint(savepoint);
}
private void checkClose() throws SQLException {
@@ -222,13 +222,13 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@SuppressWarnings("MagicConstant")
@Override
public int getTransactionIsolation() throws SQLException {
- return connectionManager.getTransactionIsolation().orElseGet(() -> transactionIsolation);
+ return databaseConnectionManager.getTransactionIsolation().orElseGet(() -> transactionIsolation);
}
@Override
public void setTransactionIsolation(final int level) throws SQLException {
transactionIsolation = level;
- connectionManager.setTransactionIsolation(level);
+ databaseConnectionManager.setTransactionIsolation(level);
}
@Override
@@ -239,17 +239,17 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@Override
public void setReadOnly(final boolean readOnly) throws SQLException {
this.readOnly = readOnly;
- connectionManager.setReadOnly(readOnly);
+ databaseConnectionManager.setReadOnly(readOnly);
}
@Override
public boolean isValid(final int timeout) throws SQLException {
- return connectionManager.isValid(timeout);
+ return databaseConnectionManager.isValid(timeout);
}
@Override
public Array createArrayOf(final String typeName, final Object[] elements) throws SQLException {
- return connectionManager.getRandomConnection().createArrayOf(typeName, elements);
+ return databaseConnectionManager.getRandomConnection().createArrayOf(typeName, elements);
}
@Override
@@ -266,10 +266,10 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
@Override
public void close() throws SQLException {
closed = true;
- connectionManager.close();
+ databaseConnectionManager.close();
}
private ConnectionContext getConnectionContext() {
- return connectionManager.getConnectionContext();
+ return databaseConnectionManager.getConnectionContext();
}
}
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java
index f305ba87876..c6e61a76bb3 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java
@@ -57,7 +57,7 @@ public final class ShardingSphereDatabaseMetaData extends AdaptedDatabaseMetaDat
@Override
public Connection getConnection() throws SQLException {
if (null == currentPhysicalConnection) {
- currentPhysicalConnection = connection.getConnectionManager().getRandomConnection();
+ currentPhysicalConnection = connection.getDatabaseConnectionManager().getRandomConnection();
}
return currentPhysicalConnection;
}
@@ -235,7 +235,7 @@ public final class ShardingSphereDatabaseMetaData extends AdaptedDatabaseMetaDat
private String getDataSourceName() {
if (null == currentPhysicalDataSourceName) {
- currentPhysicalDataSourceName = connection.getConnectionManager().getRandomPhysicalDataSourceName();
+ currentPhysicalDataSourceName = connection.getDatabaseConnectionManager().getRandomPhysicalDataSourceName();
}
return currentPhysicalDataSourceName;
}
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index e9cd1cac443..44016d6fdfd 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -207,7 +207,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement);
statementOption = returnGeneratedKeys ? new StatementOption(true, columns) : new StatementOption(resultSetType, resultSetConcurrency, resultSetHoldability);
executor = new DriverExecutor(connection);
- JDBCExecutor jdbcExecutor = new JDBCExecutor(connection.getContextManager().getExecutorEngine(), connection.getConnectionManager().getConnectionContext());
+ JDBCExecutor jdbcExecutor = new JDBCExecutor(connection.getContextManager().getExecutorEngine(), connection.getDatabaseConnectionManager().getConnectionContext());
batchPreparedStatementExecutor = new BatchPreparedStatementExecutor(metaDataContexts, jdbcExecutor, connection.getDatabaseName());
kernelProcessor = new KernelProcessor();
statementsCacheable = isStatementsCacheable(metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getRuleMetaData());
@@ -302,12 +302,12 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
}
private Optional<String> getInstanceIdAndSet(final QueryContext queryContext) {
- Optional<String> result = connection.getConnectionManager().getConnectionContext().getTrafficInstanceId();
+ Optional<String> result = connection.getDatabaseConnectionManager().getConnectionContext().getTrafficInstanceId();
if (!result.isPresent()) {
result = getInstanceId(queryContext);
}
if (connection.isHoldTransaction() && result.isPresent()) {
- connection.getConnectionManager().getConnectionContext().setTrafficInstanceId(result.get());
+ connection.getDatabaseConnectionManager().getConnectionContext().setTrafficInstanceId(result.get());
}
return result;
}
@@ -347,7 +347,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriverExecutionPrepareEngine() {
int maxConnectionsSizePerQuery = metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
- return new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT, maxConnectionsSizePerQuery, connection.getConnectionManager(), statementManager,
+ return new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT, maxConnectionsSizePerQuery, connection.getDatabaseConnectionManager(), statementManager,
statementOption, metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getRuleMetaData().getRules(),
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getResourceMetaData().getStorageTypes());
}
@@ -467,8 +467,8 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
}
private boolean isNeedImplicitCommitTransaction(final ExecutionContext executionContext) {
- ConnectionTransaction connectionTransaction = connection.getConnectionManager().getConnectionTransaction();
- boolean isInTransaction = connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction();
+ ConnectionTransaction connectionTransaction = connection.getDatabaseConnectionManager().getConnectionTransaction();
+ boolean isInTransaction = connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction();
SQLStatement sqlStatement = executionContext.getSqlStatementContext().getSqlStatement();
return TransactionType.isDistributedTransaction(connectionTransaction.getTransactionType()) && !isInTransaction && sqlStatement instanceof DMLStatement
&& !(sqlStatement instanceof SelectStatement) && executionContext.getExecutionUnits().size() > 1;
@@ -582,7 +582,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName());
SQLAuditEngine.audit(queryContext.getSqlStatementContext(), queryContext.getParameters(), globalRuleMetaData, currentDatabase, null);
ExecutionContext result = kernelProcessor.generateExecutionContext(
- queryContext, currentDatabase, globalRuleMetaData, metaDataContexts.getMetaData().getProps(), connection.getConnectionManager().getConnectionContext());
+ queryContext, currentDatabase, globalRuleMetaData, metaDataContexts.getMetaData().getProps(), connection.getDatabaseConnectionManager().getConnectionContext());
findGeneratedKey(result).ifPresent(optional -> generatedValues.addAll(optional.getGeneratedValues()));
return result;
}
@@ -604,7 +604,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
private MergedResult mergeQuery(final List<QueryResult> queryResults) throws SQLException {
MergeEngine mergeEngine = new MergeEngine(metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()),
- metaDataContexts.getMetaData().getProps(), connection.getConnectionManager().getConnectionContext());
+ metaDataContexts.getMetaData().getProps(), connection.getDatabaseConnectionManager().getConnectionContext());
return mergeEngine.merge(queryResults, executionContext.getSqlStatementContext());
}
@@ -697,7 +697,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
private void initBatchPreparedStatementExecutor() throws SQLException {
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT, metaDataContexts.getMetaData().getProps()
- .<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), connection.getConnectionManager(), statementManager, statementOption,
+ .<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), connection.getDatabaseConnectionManager(), statementManager, statementOption,
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getRuleMetaData().getRules(),
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getResourceMetaData().getStorageTypes());
List<ExecutionUnit> executionUnits = new ArrayList<>(batchPreparedStatementExecutor.getBatchExecutionUnits().size());
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index 76640d6aad4..362967fdda7 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -205,12 +205,12 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
}
private Optional<String> getInstanceIdAndSet(final QueryContext queryContext) {
- Optional<String> result = connection.getConnectionManager().getConnectionContext().getTrafficInstanceId();
+ Optional<String> result = connection.getDatabaseConnectionManager().getConnectionContext().getTrafficInstanceId();
if (!result.isPresent()) {
result = getInstanceId(queryContext);
}
if (connection.isHoldTransaction() && result.isPresent()) {
- connection.getConnectionManager().getConnectionContext().setTrafficInstanceId(result.get());
+ connection.getDatabaseConnectionManager().getConnectionContext().setTrafficInstanceId(result.get());
}
return result;
}
@@ -245,7 +245,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriverExecutionPrepareEngine() {
int maxConnectionsSizePerQuery = metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
- return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, connection.getConnectionManager(), statementManager, statementOption,
+ return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, connection.getDatabaseConnectionManager(), statementManager, statementOption,
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getRuleMetaData().getRules(),
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getResourceMetaData().getStorageTypes());
}
@@ -485,7 +485,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
}
private void checkSameDatabaseNameInTransaction(final SQLStatementContext<?> sqlStatementContext, final String connectionDatabaseName) {
- if (!connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction()) {
+ if (!connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction()) {
return;
}
if (sqlStatementContext instanceof TableAvailable) {
@@ -543,7 +543,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName());
SQLAuditEngine.audit(queryContext.getSqlStatementContext(), queryContext.getParameters(), globalRuleMetaData, currentDatabase, null);
return kernelProcessor.generateExecutionContext(queryContext, currentDatabase, globalRuleMetaData, metaDataContexts.getMetaData().getProps(),
- connection.getConnectionManager().getConnectionContext());
+ connection.getDatabaseConnectionManager().getConnectionContext());
}
private ExecutionGroupContext<JDBCExecutionUnit> createExecutionGroupContext() throws SQLException {
@@ -558,8 +558,8 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
}
private boolean isNeedImplicitCommitTransaction(final ExecutionContext executionContext) {
- ConnectionTransaction connectionTransaction = connection.getConnectionManager().getConnectionTransaction();
- boolean isInTransaction = connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction();
+ ConnectionTransaction connectionTransaction = connection.getDatabaseConnectionManager().getConnectionTransaction();
+ boolean isInTransaction = connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction();
SQLStatement sqlStatement = executionContext.getSqlStatementContext().getSqlStatement();
return TransactionType.isDistributedTransaction(connectionTransaction.getTransactionType()) && !isInTransaction && sqlStatement instanceof DMLStatement
&& !(sqlStatement instanceof SelectStatement) && executionContext.getExecutionUnits().size() > 1;
@@ -663,7 +663,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
private MergedResult mergeQuery(final List<QueryResult> queryResults) throws SQLException {
MergeEngine mergeEngine = new MergeEngine(metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()),
- metaDataContexts.getMetaData().getProps(), connection.getConnectionManager().getConnectionContext());
+ metaDataContexts.getMetaData().getProps(), connection.getDatabaseConnectionManager().getConnectionContext());
return mergeEngine.merge(queryResults, executionContext.getSqlStatementContext());
}
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
index c1741f85680..b6f120b78be 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
@@ -88,12 +88,12 @@ class BatchPreparedStatementExecutorTest {
private SQLStatementContext<?> sqlStatementContext;
@BeforeEach
- void setUp() throws SQLException {
+ void setUp() {
SQLExecutorExceptionHandler.setExceptionThrown(true);
TransactionTypeHolder.set(TransactionType.LOCAL);
ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), mock(JDBCContext.class));
executor = new BatchPreparedStatementExecutor(
- connection.getContextManager().getMetaDataContexts(), new JDBCExecutor(executorEngine, connection.getConnectionManager().getConnectionContext()), "foo_db");
+ connection.getContextManager().getMetaDataContexts(), new JDBCExecutor(executorEngine, connection.getDatabaseConnectionManager().getConnectionContext()), "foo_db");
when(sqlStatementContext.getTablesContext()).thenReturn(mock(TablesContext.class));
}
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java
similarity index 79%
rename from jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
rename to jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java
index 791d63a3da6..7037cda1f36 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java
@@ -63,13 +63,13 @@ import static org.mockito.Mockito.when;
@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(DataSourcePoolCreator.class)
@MockitoSettings(strictness = Strictness.LENIENT)
-class ConnectionManagerTest {
+class DriverDatabaseConnectionManagerTest {
- private ConnectionManager connectionManager;
+ private DriverDatabaseConnectionManager databaseConnectionManager;
@BeforeEach
void setUp() throws SQLException {
- connectionManager = new ConnectionManager(DefaultDatabase.LOGIC_NAME, mockContextManager());
+ databaseConnectionManager = new DriverDatabaseConnectionManager(DefaultDatabase.LOGIC_NAME, mockContextManager());
}
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -125,27 +125,27 @@ class ConnectionManagerTest {
@Test
void assertGetRandomPhysicalDataSourceNameFromContextManager() {
- String actual = connectionManager.getRandomPhysicalDataSourceName();
+ String actual = databaseConnectionManager.getRandomPhysicalDataSourceName();
assertTrue(Arrays.asList("ds", "invalid_ds").contains(actual));
}
@Test
void assertGetRandomPhysicalDataSourceNameFromCache() throws SQLException {
- connectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
- String actual = connectionManager.getRandomPhysicalDataSourceName();
+ databaseConnectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ String actual = databaseConnectionManager.getRandomPhysicalDataSourceName();
assertThat(actual, is("ds"));
}
@Test
void assertGetConnection() throws SQLException {
- assertThat(connectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY),
- is(connectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY)));
+ assertThat(databaseConnectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY),
+ is(databaseConnectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY)));
}
@Test
void assertGetConnectionWhenConfigTrafficRule() throws SQLException {
- List<Connection> actual = connectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY);
- assertThat(actual, is(connectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY)));
+ List<Connection> actual = databaseConnectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY);
+ assertThat(actual, is(databaseConnectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY)));
assertThat(actual.size(), is(1));
assertThat(actual.get(0).getMetaData().getUserName(), is("root"));
assertThat(actual.get(0).getMetaData().getURL(), is("jdbc:mysql://127.0.0.1:3307/logic_db?serverTimezone=UTC&useSSL=false"));
@@ -154,7 +154,7 @@ class ConnectionManagerTest {
@Test
void assertGetConnectionWhenConfigTrafficRuleInXaTransaction() throws SQLException {
TransactionTypeHolder.set(TransactionType.XA);
- List<Connection> actual = connectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actual = databaseConnectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY);
assertThat(actual.size(), is(1));
assertThat(actual.get(0).getMetaData().getUserName(), is("root"));
assertThat(actual.get(0).getMetaData().getURL(), is("jdbc:mysql://127.0.0.1:3307/logic_db?serverTimezone=UTC&useSSL=false"));
@@ -163,16 +163,16 @@ class ConnectionManagerTest {
@Test
void assertGetConnectionsWhenAllInCache() throws SQLException {
- Connection expected = connectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
- List<Connection> actual = connectionManager.getConnections("ds", 1, ConnectionMode.CONNECTION_STRICTLY);
+ Connection expected = databaseConnectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
+ List<Connection> actual = databaseConnectionManager.getConnections("ds", 1, ConnectionMode.CONNECTION_STRICTLY);
assertThat(actual.size(), is(1));
assertThat(actual.get(0), is(expected));
}
@Test
void assertGetConnectionsWhenConfigTrafficRuleAndAllInCache() throws SQLException {
- Connection expected = connectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
- List<Connection> actual = connectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.CONNECTION_STRICTLY);
+ Connection expected = databaseConnectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
+ List<Connection> actual = databaseConnectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.CONNECTION_STRICTLY);
assertThat(actual.size(), is(1));
assertThat(actual.get(0), is(expected));
assertThat(actual.get(0).getMetaData().getUserName(), is("root"));
@@ -181,13 +181,13 @@ class ConnectionManagerTest {
@Test
void assertGetConnectionsWhenEmptyCache() throws SQLException {
- List<Connection> actual = connectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actual = databaseConnectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
assertThat(actual.size(), is(1));
}
@Test
void assertGetConnectionsWhenConfigTrafficRuleAndEmptyCache() throws SQLException {
- List<Connection> actual = connectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actual = databaseConnectionManager.getConnections("127.0.0.1@3307", 1, ConnectionMode.MEMORY_STRICTLY);
assertThat(actual.size(), is(1));
assertThat(actual.get(0).getMetaData().getUserName(), is("root"));
assertThat(actual.get(0).getMetaData().getURL(), is("jdbc:mysql://127.0.0.1:3307/logic_db?serverTimezone=UTC&useSSL=false"));
@@ -195,21 +195,21 @@ class ConnectionManagerTest {
@Test
void assertGetConnectionsWhenPartInCacheWithMemoryStrictlyMode() throws SQLException {
- connectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
- List<Connection> actual = connectionManager.getConnections("ds", 3, ConnectionMode.MEMORY_STRICTLY);
+ databaseConnectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actual = databaseConnectionManager.getConnections("ds", 3, ConnectionMode.MEMORY_STRICTLY);
assertThat(actual.size(), is(3));
}
@Test
void assertGetConnectionsWhenPartInCacheWithConnectionStrictlyMode() throws SQLException {
- connectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
- List<Connection> actual = connectionManager.getConnections("ds", 3, ConnectionMode.CONNECTION_STRICTLY);
+ databaseConnectionManager.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actual = databaseConnectionManager.getConnections("ds", 3, ConnectionMode.CONNECTION_STRICTLY);
assertThat(actual.size(), is(3));
}
@Test
void assertGetConnectionsWhenConnectionCreateFailed() {
- SQLException ex = assertThrows(SQLException.class, () -> connectionManager.getConnections("invalid_ds", 3, ConnectionMode.CONNECTION_STRICTLY));
+ SQLException ex = assertThrows(SQLException.class, () -> databaseConnectionManager.getConnections("invalid_ds", 3, ConnectionMode.CONNECTION_STRICTLY));
assertThat(ex.getMessage(), is("Can not get 3 connections one time, partition succeed connection(0) have released. "
+ "Please consider increasing the `maxPoolSize` of the data sources or decreasing the `max-connections-size-per-query` in properties."));
}
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
index 861b53bfb1f..cbeb7ea684f 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
@@ -94,7 +94,7 @@ class ShardingSphereConnectionTest {
void assertSetAutoCommitWithLocalTransaction() throws SQLException {
Connection physicalConnection = mock(Connection.class);
when(connection.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).get("ds").getConnection()).thenReturn(physicalConnection);
- connection.getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ connection.getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
connection.setAutoCommit(true);
assertTrue(connection.getAutoCommit());
verify(physicalConnection).setAutoCommit(true);
@@ -114,13 +114,13 @@ class ShardingSphereConnectionTest {
void assertCommitWithLocalTransaction() throws SQLException {
Connection physicalConnection = mock(Connection.class);
when(connection.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).get("ds").getConnection()).thenReturn(physicalConnection);
- connection.getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ connection.getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
connection.setAutoCommit(false);
assertFalse(connection.getAutoCommit());
- assertTrue(connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
+ assertTrue(connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
verify(physicalConnection).setAutoCommit(false);
connection.commit();
- assertFalse(connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
+ assertFalse(connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
verify(physicalConnection).commit();
}
@@ -128,22 +128,22 @@ class ShardingSphereConnectionTest {
void assertCommitWithDistributedTransaction() throws SQLException {
ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class);
when(connectionTransaction.getDistributedTransactionOperationType(false)).thenReturn(DistributedTransactionOperationType.BEGIN);
- ConnectionManager connectionManager = mockConnectionManager(connectionTransaction);
+ DriverDatabaseConnectionManager databaseConnectionManager = mockConnectionManager(connectionTransaction);
connection.setAutoCommit(false);
- assertTrue(connectionManager.getConnectionContext().getTransactionContext().isInTransaction());
+ assertTrue(databaseConnectionManager.getConnectionContext().getTransactionContext().isInTransaction());
assertFalse(connection.getAutoCommit());
- assertTrue(connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
+ assertTrue(connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
verify(connectionTransaction).begin();
connection.commit();
- assertFalse(connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
- verify(connectionManager).commit();
+ assertFalse(connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
+ verify(databaseConnectionManager).commit();
}
@Test
void assertRollbackWithLocalTransaction() throws SQLException {
Connection physicalConnection = mock(Connection.class);
when(connection.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).get("ds").getConnection()).thenReturn(physicalConnection);
- connection.getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ connection.getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
connection.setAutoCommit(false);
assertFalse(connection.getAutoCommit());
connection.rollback();
@@ -154,22 +154,22 @@ class ShardingSphereConnectionTest {
void assertRollbackWithDistributedTransaction() throws SQLException {
ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class);
when(connectionTransaction.getDistributedTransactionOperationType(false)).thenReturn(DistributedTransactionOperationType.BEGIN);
- final ConnectionManager connectionManager = mockConnectionManager(connectionTransaction);
+ final DriverDatabaseConnectionManager databaseConnectionManager = mockConnectionManager(connectionTransaction);
connection.setAutoCommit(false);
assertFalse(connection.getAutoCommit());
- assertTrue(connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
+ assertTrue(connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
verify(connectionTransaction).begin();
connection.rollback();
- assertFalse(connection.getConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
- verify(connectionManager).rollback();
+ assertFalse(connection.getDatabaseConnectionManager().getConnectionContext().getTransactionContext().isInTransaction());
+ verify(databaseConnectionManager).rollback();
}
@SneakyThrows(ReflectiveOperationException.class)
- private ConnectionManager mockConnectionManager(final ConnectionTransaction connectionTransaction) {
- ConnectionManager result = mock(ConnectionManager.class);
+ private DriverDatabaseConnectionManager mockConnectionManager(final ConnectionTransaction connectionTransaction) {
+ DriverDatabaseConnectionManager result = mock(DriverDatabaseConnectionManager.class);
when(result.getConnectionTransaction()).thenReturn(connectionTransaction);
when(result.getConnectionContext()).thenReturn(new ConnectionContext());
- Plugins.getMemberAccessor().set(connection.getClass().getDeclaredField("connectionManager"), connection, result);
+ Plugins.getMemberAccessor().set(connection.getClass().getDeclaredField("databaseConnectionManager"), connection, result);
return result;
}
@@ -180,14 +180,14 @@ class ShardingSphereConnectionTest {
@Test
void assertIsInvalid() throws SQLException {
- connection.getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ connection.getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
assertFalse(connection.isValid(0));
}
@Test
void assertSetReadOnly() throws SQLException {
assertFalse(connection.isReadOnly());
- Connection physicalConnection = connection.getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
+ Connection physicalConnection = connection.getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
connection.setReadOnly(true);
assertTrue(connection.isReadOnly());
verify(physicalConnection).setReadOnly(true);
@@ -200,7 +200,7 @@ class ShardingSphereConnectionTest {
@Test
void assertSetTransactionIsolation() throws SQLException {
- Connection physicalConnection = connection.getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
+ Connection physicalConnection = connection.getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0);
connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
verify(physicalConnection).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
}
@@ -209,7 +209,7 @@ class ShardingSphereConnectionTest {
void assertCreateArrayOf() throws SQLException {
Connection physicalConnection = mock(Connection.class);
when(connection.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME).get("ds").getConnection()).thenReturn(physicalConnection);
- connection.getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ connection.getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
assertNull(connection.createArrayOf("int", null));
verify(physicalConnection).createArrayOf("int", null);
}
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
index 0effe85a42b..b18de8d0407 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
@@ -101,7 +101,7 @@ class ShardingSphereDataSourceTest {
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getURL()).thenReturn("jdbc:mock://127.0.0.1/foo_ds");
try (ShardingSphereDataSource actual = createShardingSphereDataSource(new MockedDataSource(connection))) {
- assertThat(((ShardingSphereConnection) actual.getConnection("", "")).getConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0), is(connection));
+ assertThat(((ShardingSphereConnection) actual.getConnection("", "")).getDatabaseConnectionManager().getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY).get(0), is(connection));
}
}
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
index 2be83c62dbc..5dd5de72c59 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaDataTest.java
@@ -91,8 +91,8 @@ class ShardingSphereDatabaseMetaDataTest {
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(resultSet.getMetaData()).thenReturn(mock(ResultSetMetaData.class));
- when(shardingSphereConnection.getConnectionManager().getRandomPhysicalDataSourceName()).thenReturn(DATA_SOURCE_NAME);
- when(shardingSphereConnection.getConnectionManager().getRandomConnection()).thenReturn(connection);
+ when(shardingSphereConnection.getDatabaseConnectionManager().getRandomPhysicalDataSourceName()).thenReturn(DATA_SOURCE_NAME);
+ when(shardingSphereConnection.getDatabaseConnectionManager().getRandomConnection()).thenReturn(connection);
when(shardingSphereConnection.getContextManager().getMetaDataContexts()).thenReturn(metaDataContexts);
when(shardingSphereConnection.getContextManager().getDataSourceMap(DefaultDatabase.LOGIC_NAME)).thenReturn(dataSourceMap);
when(shardingSphereConnection.getDatabaseName()).thenReturn(DefaultDatabase.LOGIC_NAME);
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
index ff2b0af55d6..c3f5fb81680 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
@@ -115,7 +115,7 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
private final QueryContext queryContext;
- private final BackendConnection backendConnection;
+ private final ProxyDatabaseConnectionManager databaseConnectionManager;
private volatile SQLFederationExecutor federationExecutor;
@@ -123,18 +123,18 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
private MergedResult mergedResult;
- public DatabaseConnector(final String driverType, final ShardingSphereDatabase database, final QueryContext queryContext, final BackendConnection backendConnection) {
+ public DatabaseConnector(final String driverType, final ShardingSphereDatabase database, final QueryContext queryContext, final ProxyDatabaseConnectionManager databaseConnectionManager) {
SQLStatementContext<?> sqlStatementContext = queryContext.getSqlStatementContext();
- failedIfBackendNotReady(backendConnection.getConnectionSession(), sqlStatementContext);
+ failedIfBackendNotReady(databaseConnectionManager.getConnectionSession(), sqlStatementContext);
this.driverType = driverType;
this.database = database;
this.transparentStatement = isTransparentStatement(sqlStatementContext);
this.queryContext = queryContext;
- this.backendConnection = backendConnection;
+ this.databaseConnectionManager = databaseConnectionManager;
if (sqlStatementContext instanceof CursorAvailable) {
- prepareCursorStatementContext((CursorAvailable) sqlStatementContext, backendConnection.getConnectionSession());
+ prepareCursorStatementContext((CursorAvailable) sqlStatementContext, databaseConnectionManager.getConnectionSession());
}
- proxySQLExecutor = new ProxySQLExecutor(driverType, backendConnection, this);
+ proxySQLExecutor = new ProxySQLExecutor(driverType, databaseConnectionManager, this);
}
private void failedIfBackendNotReady(final ConnectionSession connectionSession, final SQLStatementContext<?> sqlStatementContext) {
@@ -213,14 +213,14 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
Collection<ExecutionContext> result = new LinkedList<>();
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
ExecutionContext executionContext = new KernelProcessor().generateExecutionContext(queryContext, database, metaDataContexts.getMetaData().getGlobalRuleMetaData(),
- metaDataContexts.getMetaData().getProps(), backendConnection.getConnectionSession().getConnectionContext());
+ metaDataContexts.getMetaData().getProps(), databaseConnectionManager.getConnectionSession().getConnectionContext());
result.add(executionContext);
// TODO support logical SQL optimize to generate multiple logical SQL
return result;
}
private boolean isNeedImplicitCommitTransaction(final Collection<ExecutionContext> executionContexts) {
- TransactionStatus transactionStatus = backendConnection.getConnectionSession().getTransactionStatus();
+ TransactionStatus transactionStatus = databaseConnectionManager.getConnectionSession().getTransactionStatus();
if (!TransactionType.isDistributedTransaction(transactionStatus.getTransactionType()) || transactionStatus.isInTransaction()) {
return false;
}
@@ -237,7 +237,7 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
private ResponseHeader doExecuteWithImplicitCommitTransaction(final Collection<ExecutionContext> executionContexts) throws SQLException {
ResponseHeader result;
- BackendTransactionManager transactionManager = new BackendTransactionManager(backendConnection);
+ BackendTransactionManager transactionManager = new BackendTransactionManager(databaseConnectionManager);
try {
transactionManager.begin();
result = doExecute(executionContexts);
@@ -246,7 +246,7 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
} catch (final Exception ex) {
// CHECKSTYLE:ON
transactionManager.rollback();
- String databaseName = backendConnection.getConnectionSession().getDatabaseName();
+ String databaseName = databaseConnectionManager.getConnectionSession().getDatabaseName();
throw SQLExceptionTransformEngine.toSQLException(ex, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData()
.getDatabase(databaseName).getProtocolType().getType());
}
@@ -278,17 +278,17 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
private void prepareFederationExecutor() {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- String databaseName = backendConnection.getConnectionSession().getDatabaseName();
+ String databaseName = databaseConnectionManager.getConnectionSession().getDatabaseName();
DatabaseType databaseType = queryContext.getSqlStatementContext().getDatabaseType();
String schemaName = queryContext.getSqlStatementContext().getTablesContext().getSchemaName().orElseGet(() -> DatabaseTypeEngine.getDefaultSchemaName(databaseType, databaseName));
SQLFederationRule sqlFederationRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLFederationRule.class);
federationExecutor = sqlFederationRule.getSQLFederationExecutor(databaseName, schemaName, metaDataContexts.getMetaData(), metaDataContexts.getShardingSphereData(),
- new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), backendConnection.getConnectionSession().getConnectionContext()));
+ new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), databaseConnectionManager.getConnectionSession().getConnectionContext()));
}
private ResultSet doExecuteFederation(final QueryContext queryContext, final MetaDataContexts metaDataContexts) throws SQLException {
boolean isReturnGeneratedKeys = queryContext.getSqlStatementContext().getSqlStatement() instanceof MySQLInsertStatement;
- ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(backendConnection.getConnectionSession().getDatabaseName());
+ ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName());
DatabaseType protocolType = database.getProtocolType();
Map<String, DatabaseType> storageTypes = database.getResourceMetaData().getStorageTypes();
ProxyJDBCExecutorCallback callback = ProxyJDBCExecutorCallbackFactory.newInstance(driverType, protocolType, storageTypes,
@@ -300,16 +300,16 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriverExecutionPrepareEngine(final boolean isReturnGeneratedKeys, final MetaDataContexts metaData) {
int maxConnectionsSizePerQuery = metaData.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
- JDBCBackendStatement statementManager = (JDBCBackendStatement) backendConnection.getConnectionSession().getStatementManager();
- return new DriverExecutionPrepareEngine<>(driverType, maxConnectionsSizePerQuery, backendConnection, statementManager,
- new StatementOption(isReturnGeneratedKeys), metaData.getMetaData().getDatabase(backendConnection.getConnectionSession().getDatabaseName()).getRuleMetaData().getRules(),
- metaData.getMetaData().getDatabase(backendConnection.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageTypes());
+ JDBCBackendStatement statementManager = (JDBCBackendStatement) databaseConnectionManager.getConnectionSession().getStatementManager();
+ return new DriverExecutionPrepareEngine<>(driverType, maxConnectionsSizePerQuery, databaseConnectionManager, statementManager,
+ new StatementOption(isReturnGeneratedKeys), metaData.getMetaData().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getRuleMetaData().getRules(),
+ metaData.getMetaData().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageTypes());
}
private ResponseHeader processExecuteFederation(final ResultSet resultSet, final MetaDataContexts metaDataContexts) throws SQLException {
int columnCount = resultSet.getMetaData().getColumnCount();
queryHeaders = new ArrayList<>(columnCount);
- ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(backendConnection.getConnectionSession().getDatabaseName());
+ ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName());
QueryHeaderBuilderEngine queryHeaderBuilderEngine = new QueryHeaderBuilderEngine(null == database ? null : database.getProtocolType());
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
queryHeaders.add(queryHeaderBuilderEngine.build(new JDBCQueryResultMetaData(resultSet.getMetaData()), database, columnIndex));
@@ -389,7 +389,7 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
private MergedResult mergeQuery(final SQLStatementContext<?> sqlStatementContext, final List<QueryResult> queryResults) throws SQLException {
MergeEngine mergeEngine = new MergeEngine(database, ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps(),
- backendConnection.getConnectionSession().getConnectionContext());
+ databaseConnectionManager.getConnectionSession().getConnectionContext());
return mergeEngine.merge(queryResults, sqlStatementContext);
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactory.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactory.java
index 6520bc97a0b..1a63db44e00 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactory.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactory.java
@@ -45,15 +45,15 @@ public final class DatabaseConnectorFactory {
* Create new instance of {@link DatabaseConnector}.
*
* @param queryContext query context
- * @param backendConnection backend connection
+ * @param databaseConnectionManager database connection manager
* @param preferPreparedStatement use prepared statement as possible
* @return created instance
*/
- public DatabaseConnector newInstance(final QueryContext queryContext, final BackendConnection backendConnection, final boolean preferPreparedStatement) {
- ShardingSphereDatabase database = ProxyContext.getInstance().getDatabase(backendConnection.getConnectionSession().getDatabaseName());
+ public DatabaseConnector newInstance(final QueryContext queryContext, final ProxyDatabaseConnectionManager databaseConnectionManager, final boolean preferPreparedStatement) {
+ ShardingSphereDatabase database = ProxyContext.getInstance().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName());
String driverType = preferPreparedStatement || !queryContext.getParameters().isEmpty() ? JDBCDriverType.PREPARED_STATEMENT : JDBCDriverType.STATEMENT;
- DatabaseConnector result = new DatabaseConnector(driverType, database, queryContext, backendConnection);
- backendConnection.add(result);
+ DatabaseConnector result = new DatabaseConnector(driverType, database, queryContext, databaseConnectionManager);
+ databaseConnectionManager.add(result);
return result;
}
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/BackendConnection.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManager.java
similarity index 98%
rename from proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/BackendConnection.java
rename to proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManager.java
index 4efa358fb64..e15c612e415 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/BackendConnection.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManager.java
@@ -23,7 +23,7 @@ import com.google.common.collect.Multimap;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
-import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorConnectionManager;
+import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager;
import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ConnectionPostProcessor;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ResourceLock;
@@ -47,11 +47,11 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
/**
- * Backend connection.
+ * Database connection manager of ShardingSphere-Proxy.
*/
@RequiredArgsConstructor
@Getter
-public final class BackendConnection implements ExecutorConnectionManager<Connection> {
+public final class ProxyDatabaseConnectionManager implements DatabaseConnectionManager<Connection> {
private final ConnectionSession connectionSession;
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java
index 532dc236587..5c463d1121e 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java
@@ -76,7 +76,7 @@ public final class ProxySQLExecutor {
private final String type;
- private final BackendConnection backendConnection;
+ private final ProxyDatabaseConnectionManager databaseConnectionManager;
private final ProxyJDBCExecutor jdbcExecutor;
@@ -84,12 +84,12 @@ public final class ProxySQLExecutor {
private final Collection<TransactionHook> transactionHooks = ShardingSphereServiceLoader.getServiceInstances(TransactionHook.class);
- public ProxySQLExecutor(final String type, final BackendConnection backendConnection, final DatabaseConnector databaseConnector) {
+ public ProxySQLExecutor(final String type, final ProxyDatabaseConnectionManager databaseConnectionManager, final DatabaseConnector databaseConnector) {
this.type = type;
- this.backendConnection = backendConnection;
+ this.databaseConnectionManager = databaseConnectionManager;
ExecutorEngine executorEngine = BackendExecutorContext.getInstance().getExecutorEngine();
- ConnectionContext connectionContext = backendConnection.getConnectionSession().getConnectionContext();
- jdbcExecutor = new ProxyJDBCExecutor(type, backendConnection.getConnectionSession(), databaseConnector, new JDBCExecutor(executorEngine, connectionContext));
+ ConnectionContext connectionContext = databaseConnectionManager.getConnectionSession().getConnectionContext();
+ jdbcExecutor = new ProxyJDBCExecutor(type, databaseConnectionManager.getConnectionSession(), databaseConnector, new JDBCExecutor(executorEngine, connectionContext));
rawExecutor = new RawExecutor(executorEngine, connectionContext);
}
@@ -108,7 +108,7 @@ public final class ProxySQLExecutor {
}
private boolean isExecuteDDLInXATransaction(final SQLStatement sqlStatement) {
- TransactionStatus transactionStatus = backendConnection.getConnectionSession().getTransactionStatus();
+ TransactionStatus transactionStatus = databaseConnectionManager.getConnectionSession().getTransactionStatus();
return TransactionType.XA == transactionStatus.getTransactionType() && transactionStatus.isInTransaction() && isUnsupportedDDLStatement(sqlStatement);
}
@@ -116,7 +116,8 @@ public final class ProxySQLExecutor {
// TODO implement DDL statement commit/rollback in PostgreSQL/openGauss transaction
boolean isPostgreSQLOpenGaussStatement = isPostgreSQLOrOpenGaussStatement(sqlStatement);
boolean isSupportedStatement = isSupportedSQLStatement(sqlStatement);
- return sqlStatement instanceof DDLStatement && !isSupportedStatement && isPostgreSQLOpenGaussStatement && backendConnection.getConnectionSession().getTransactionStatus().isInTransaction();
+ return sqlStatement instanceof DDLStatement
+ && !isSupportedStatement && isPostgreSQLOpenGaussStatement && databaseConnectionManager.getConnectionSession().getTransactionStatus().isInTransaction();
}
private boolean isSupportedSQLStatement(final SQLStatement sqlStatement) {
@@ -153,7 +154,7 @@ public final class ProxySQLExecutor {
* @throws SQLException SQL exception
*/
public List<ExecuteResult> execute(final ExecutionContext executionContext) throws SQLException {
- String databaseName = backendConnection.getConnectionSession().getDatabaseName();
+ String databaseName = databaseConnectionManager.getConnectionSession().getDatabaseName();
Collection<ShardingSphereRule> rules = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabase(databaseName).getRuleMetaData().getRules();
int maxConnectionsSizePerQuery = ProxyContext.getInstance()
.getContextManager().getMetaDataContexts().getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
@@ -175,8 +176,9 @@ public final class ProxySQLExecutor {
RawExecutionPrepareEngine prepareEngine = new RawExecutionPrepareEngine(maxConnectionsSizePerQuery, rules);
ExecutionGroupContext<RawSQLExecutionUnit> executionGroupContext;
try {
- executionGroupContext = prepareEngine.prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits(), new ExecutionGroupReportContext(
- backendConnection.getConnectionSession().getProcessId(), backendConnection.getConnectionSession().getDatabaseName(), backendConnection.getConnectionSession().getGrantee()));
+ executionGroupContext = prepareEngine.prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits(),
+ new ExecutionGroupReportContext(databaseConnectionManager.getConnectionSession().getProcessId(),
+ databaseConnectionManager.getConnectionSession().getDatabaseName(), databaseConnectionManager.getConnectionSession().getGrantee()));
} catch (final SQLException ex) {
return getSaneExecuteResults(executionContext, ex);
}
@@ -186,18 +188,19 @@ public final class ProxySQLExecutor {
private List<ExecuteResult> useDriverToExecute(final ExecutionContext executionContext, final Collection<ShardingSphereRule> rules,
final int maxConnectionsSizePerQuery, final boolean isReturnGeneratedKeys, final boolean isExceptionThrown) throws SQLException {
- JDBCBackendStatement statementManager = (JDBCBackendStatement) backendConnection.getConnectionSession().getStatementManager();
+ JDBCBackendStatement statementManager = (JDBCBackendStatement) databaseConnectionManager.getConnectionSession().getStatementManager();
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = new DriverExecutionPrepareEngine<>(
- type, maxConnectionsSizePerQuery, backendConnection, statementManager, new StatementOption(isReturnGeneratedKeys), rules,
- ProxyContext.getInstance().getDatabase(backendConnection.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageTypes());
+ type, maxConnectionsSizePerQuery, databaseConnectionManager, statementManager, new StatementOption(isReturnGeneratedKeys), rules,
+ ProxyContext.getInstance().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getResourceMetaData().getStorageTypes());
ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext;
try {
- executionGroupContext = prepareEngine.prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits(), new ExecutionGroupReportContext(
- backendConnection.getConnectionSession().getProcessId(), backendConnection.getConnectionSession().getDatabaseName(), backendConnection.getConnectionSession().getGrantee()));
+ executionGroupContext = prepareEngine.prepare(executionContext.getRouteContext(), executionContext.getExecutionUnits(),
+ new ExecutionGroupReportContext(databaseConnectionManager.getConnectionSession().getProcessId(),
+ databaseConnectionManager.getConnectionSession().getDatabaseName(), databaseConnectionManager.getConnectionSession().getGrantee()));
} catch (final SQLException ex) {
return getSaneExecuteResults(executionContext, ex);
}
- executeTransactionHooksBeforeExecuteSQL(backendConnection.getConnectionSession());
+ executeTransactionHooksBeforeExecuteSQL(databaseConnectionManager.getConnectionSession());
return jdbcExecutor.execute(executionContext.getQueryContext(), executionGroupContext, isReturnGeneratedKeys, isExceptionThrown);
}
@@ -206,16 +209,16 @@ public final class ProxySQLExecutor {
return;
}
for (TransactionHook each : transactionHooks) {
- each.beforeExecuteSQL(connectionSession.getBackendConnection().getCachedConnections().values(), getTransactionContext(connectionSession), connectionSession.getIsolationLevel());
+ each.beforeExecuteSQL(connectionSession.getDatabaseConnectionManager().getCachedConnections().values(), getTransactionContext(connectionSession), connectionSession.getIsolationLevel());
}
}
private TransactionConnectionContext getTransactionContext(final ConnectionSession connectionSession) {
- return connectionSession.getBackendConnection().getConnectionSession().getConnectionContext().getTransactionContext();
+ return connectionSession.getDatabaseConnectionManager().getConnectionSession().getConnectionContext().getTransactionContext();
}
private List<ExecuteResult> getSaneExecuteResults(final ExecutionContext executionContext, final SQLException originalException) throws SQLException {
- DatabaseType databaseType = ProxyContext.getInstance().getDatabase(backendConnection.getConnectionSession().getDatabaseName()).getProtocolType();
+ DatabaseType databaseType = ProxyContext.getInstance().getDatabase(databaseConnectionManager.getConnectionSession().getDatabaseName()).getProtocolType();
Optional<ExecuteResult> executeResult = TypedSPILoader.getService(SaneQueryResultEngine.class, databaseType.getType())
.getSaneQueryResult(executionContext.getSqlStatementContext().getSqlStatement(), originalException);
if (executeResult.isPresent()) {
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java
index eae8ccc6981..e28247a4da6 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction;
import org.apache.shardingsphere.infra.connection.transaction.TransactionConnectionContext;
import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.TransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.transaction.ConnectionSavepointManager;
@@ -40,7 +40,7 @@ import java.util.LinkedList;
*/
public final class BackendTransactionManager implements TransactionManager {
- private final BackendConnection connection;
+ private final ProxyDatabaseConnectionManager connection;
private final TransactionType transactionType;
@@ -50,10 +50,10 @@ public final class BackendTransactionManager implements TransactionManager {
private final Collection<TransactionHook> transactionHooks;
- public BackendTransactionManager(final BackendConnection backendConnection) {
- connection = backendConnection;
+ public BackendTransactionManager(final ProxyDatabaseConnectionManager databaseConnectionManager) {
+ connection = databaseConnectionManager;
transactionType = connection.getConnectionSession().getTransactionStatus().getTransactionType();
- localTransactionManager = new LocalTransactionManager(backendConnection);
+ localTransactionManager = new LocalTransactionManager(databaseConnectionManager);
TransactionRule transactionRule = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(TransactionRule.class);
ShardingSphereTransactionManagerEngine engine = transactionRule.getResource();
shardingSphereTransactionManager = null == engine ? null : engine.getTransactionManager(transactionType);
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManager.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManager.java
index 130c8ef3315..7a517e6762d 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManager.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManager.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.transaction.ConnectionSavepointManager;
import java.sql.Connection;
@@ -33,13 +33,13 @@ import java.util.LinkedList;
@RequiredArgsConstructor
public final class LocalTransactionManager {
- private final BackendConnection connection;
+ private final ProxyDatabaseConnectionManager databaseConnectionManager;
/**
* Begin transaction.
*/
public void begin() {
- connection.getConnectionPostProcessors().add(target -> target.setAutoCommit(false));
+ databaseConnectionManager.getConnectionPostProcessors().add(target -> target.setAutoCommit(false));
}
/**
@@ -49,7 +49,7 @@ public final class LocalTransactionManager {
*/
public void commit() throws SQLException {
Collection<SQLException> exceptions = new LinkedList<>();
- if (connection.getConnectionSession().getTransactionStatus().isRollbackOnly()) {
+ if (databaseConnectionManager.getConnectionSession().getTransactionStatus().isRollbackOnly()) {
exceptions.addAll(rollbackConnections());
} else {
exceptions.addAll(commitConnections());
@@ -59,7 +59,7 @@ public final class LocalTransactionManager {
private Collection<SQLException> commitConnections() {
Collection<SQLException> result = new LinkedList<>();
- for (Connection each : connection.getCachedConnections().values()) {
+ for (Connection each : databaseConnectionManager.getCachedConnections().values()) {
try {
each.commit();
} catch (final SQLException ex) {
@@ -77,7 +77,7 @@ public final class LocalTransactionManager {
* @throws SQLException SQL exception
*/
public void rollback() throws SQLException {
- if (connection.getConnectionSession().getTransactionStatus().isInTransaction()) {
+ if (databaseConnectionManager.getConnectionSession().getTransactionStatus().isInTransaction()) {
Collection<SQLException> exceptions = new LinkedList<>(rollbackConnections());
throwSQLExceptionIfNecessary(exceptions);
}
@@ -85,7 +85,7 @@ public final class LocalTransactionManager {
private Collection<SQLException> rollbackConnections() {
Collection<SQLException> result = new LinkedList<>();
- for (Connection each : connection.getCachedConnections().values()) {
+ for (Connection each : databaseConnectionManager.getCachedConnections().values()) {
try {
each.rollback();
} catch (final SQLException ex) {
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
index 26b69092282..5b5400d09d9 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
@@ -184,7 +184,7 @@ public final class ProxyBackendHandlerFactory {
private static void handleAutoCommit(final SQLStatement sqlStatement, final ConnectionSession connectionSession) {
if (AutoCommitUtils.needOpenTransaction(sqlStatement)) {
- connectionSession.getBackendConnection().handleAutoCommit();
+ connectionSession.getDatabaseConnectionManager().handleAutoCommit();
}
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactory.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactory.java
index c8fd12bd095..302d6f8d01f 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactory.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactory.java
@@ -57,6 +57,6 @@ public final class DatabaseBackendHandlerFactory {
if (sqlStatement instanceof DALStatement || sqlStatement instanceof SelectStatement && null == ((SelectStatement) sqlStatement).getFrom()) {
return new UnicastDatabaseBackendHandler(queryContext, connectionSession);
}
- return DatabaseConnectorFactory.getInstance().newInstance(queryContext, connectionSession.getBackendConnection(), preferPreparedStatement);
+ return DatabaseConnectorFactory.getInstance().newInstance(queryContext, connectionSession.getDatabaseConnectionManager(), preferPreparedStatement);
}
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
index 655f29fe829..ae0715bb391 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandler.java
@@ -58,7 +58,7 @@ public final class UnicastDatabaseBackendHandler implements DatabaseBackendHandl
ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getDatabase(databaseName).containsDataSource(), () -> new StorageUnitNotExistedException(databaseName));
try {
connectionSession.setCurrentDatabase(databaseName);
- databaseConnector = databaseConnectorFactory.newInstance(queryContext, connectionSession.getBackendConnection(), false);
+ databaseConnector = databaseConnectorFactory.newInstance(queryContext, connectionSession.getDatabaseConnectionManager(), false);
return databaseConnector.execute();
} finally {
connectionSession.setCurrentDatabase(databaseName);
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
index 112fbe1dc1f..d432f2dfd0c 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java
@@ -101,7 +101,7 @@ public final class ShowDistVariableExecutor implements ConnectionSessionRequired
VariableEnum variable = VariableEnum.getValueOf(variableName);
switch (variable) {
case CACHED_CONNECTIONS:
- int connectionSize = connectionSession.getBackendConnection().getConnectionSize();
+ int connectionSize = connectionSession.getDatabaseConnectionManager().getConnectionSize();
return String.valueOf(connectionSize);
case TRANSACTION_TYPE:
TransactionType transactionType = connectionSession.getTransactionStatus().getTransactionType();
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
index b003f2907f3..fe6075f22ef 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java
@@ -53,7 +53,7 @@ public final class ShowDistVariablesExecutor implements ConnectionSessionRequire
result.addAll(TemporaryConfigurationPropertyKey.getKeyNames().stream()
.map(each -> new LocalDataQueryResultRow(each.toLowerCase(), metaData.getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.valueOf(each)).toString()))
.collect(Collectors.toList()));
- result.add(new LocalDataQueryResultRow(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(), connectionSession.getBackendConnection().getConnectionSize()));
+ result.add(new LocalDataQueryResultRow(VariableEnum.CACHED_CONNECTIONS.name().toLowerCase(), connectionSession.getDatabaseConnectionManager().getConnectionSize()));
result.add(new LocalDataQueryResultRow(VariableEnum.TRANSACTION_TYPE.name().toLowerCase(), connectionSession.getTransactionStatus().getTransactionType().name()));
addLoggingPropsRows(metaData, result);
return result.stream().sorted(Comparator.comparing(each -> each.getCell(1).toString())).collect(Collectors.toList());
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java
index 08f535ab968..3b27244be39 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/sql/PreviewHandler.java
@@ -161,7 +161,7 @@ public final class PreviewHandler extends SQLRULBackendHandler<PreviewStatement>
private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriverExecutionPrepareEngine(final boolean isReturnGeneratedKeys, final MetaDataContexts metaDataContexts) {
int maxConnectionsSizePerQuery = metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY);
- return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, getConnectionSession().getBackendConnection(),
+ return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, getConnectionSession().getDatabaseConnectionManager(),
(JDBCBackendStatement) getConnectionSession().getStatementManager(), new StatementOption(isReturnGeneratedKeys),
metaDataContexts.getMetaData().getDatabase(getDatabaseName()).getRuleMetaData().getRules(),
metaDataContexts.getMetaData().getDatabase(getDatabaseName()).getResourceMetaData().getStorageTypes());
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
index b3932087339..6f88d91a95b 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandler.java
@@ -60,7 +60,7 @@ public final class TransactionBackendHandler implements ProxyBackendHandler {
this.tclStatement = tclStatement;
this.operationType = operationType;
this.connectionSession = connectionSession;
- backendTransactionManager = new BackendTransactionManager(connectionSession.getBackendConnection());
+ backendTransactionManager = new BackendTransactionManager(connectionSession.getDatabaseConnectionManager());
}
@Override
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactory.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactory.java
index d1d9089835c..6216a06cab4 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactory.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactory.java
@@ -82,6 +82,6 @@ public final class TransactionBackendHandlerFactory {
return new TransactionXAHandler(sqlStatementContext, sql, connectionSession);
}
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList());
- return DatabaseConnectorFactory.getInstance().newInstance(queryContext, connectionSession.getBackendConnection(), false);
+ return DatabaseConnectorFactory.getInstance().newInstance(queryContext, connectionSession.getDatabaseConnectionManager(), false);
}
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
index a3e37dbbdaf..27d379990a8 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionXAHandler.java
@@ -52,7 +52,7 @@ public final class TransactionXAHandler implements ProxyBackendHandler {
this.tclStatement = (XAStatement) sqlStatementContext.getSqlStatement();
this.connectionSession = connectionSession;
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList());
- backendHandler = DatabaseConnectorFactory.getInstance().newInstance(queryContext, connectionSession.getBackendConnection(), false);
+ backendHandler = DatabaseConnectorFactory.getInstance().newInstance(queryContext, connectionSession.getDatabaseConnectionManager(), false);
}
@Override
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
index 5d52999b2a5..f2493de3ec5 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSession.java
@@ -24,10 +24,10 @@ import lombok.Setter;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.connection.ConnectionContext;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorConnectionManager;
+import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager;
import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager;
import org.apache.shardingsphere.infra.metadata.user.Grantee;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement;
import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.apache.shardingsphere.sql.parser.sql.common.enums.TransactionIsolationLevel;
@@ -61,7 +61,7 @@ public final class ConnectionSession {
private TransactionIsolationLevel isolationLevel;
- private final BackendConnection backendConnection;
+ private final ProxyDatabaseConnectionManager databaseConnectionManager;
private final ExecutorStatementManager statementManager;
@@ -79,9 +79,9 @@ public final class ConnectionSession {
this.protocolType = protocolType;
transactionStatus = new TransactionStatus(initialTransactionType);
this.attributeMap = attributeMap;
- backendConnection = new BackendConnection(this);
+ databaseConnectionManager = new ProxyDatabaseConnectionManager(this);
statementManager = new JDBCBackendStatement();
- connectionContext = new ConnectionContext(((ExecutorConnectionManager<?>) backendConnection)::getDataSourceNamesOfCachedConnections);
+ connectionContext = new ConnectionContext(((DatabaseConnectionManager<?>) databaseConnectionManager)::getDataSourceNamesOfCachedConnections);
}
/**
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java
index e9ed592d406..9f02c10792c 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java
@@ -48,8 +48,8 @@ class DatabaseConnectorFactoryTest {
@Test
void assertNewDatabaseConnectorWithoutParameter() {
- BackendConnection backendConnection = mock(BackendConnection.class, RETURNS_DEEP_STUBS);
- when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("foo_db");
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class, RETURNS_DEEP_STUBS);
+ when(databaseConnectionManager.getConnectionSession().getDatabaseName()).thenReturn("foo_db");
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
QueryContext queryContext = new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList());
@@ -57,21 +57,21 @@ class DatabaseConnectorFactoryTest {
ContextManager contextManager = mockContextManager(database);
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
when(ProxyContext.getInstance().getDatabase("foo_db")).thenReturn(database);
- DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(queryContext, backendConnection, false);
+ DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(queryContext, databaseConnectionManager, false);
assertThat(engine, instanceOf(DatabaseConnector.class));
}
@Test
void assertNewDatabaseConnectorWithParameters() {
- BackendConnection backendConnection = mock(BackendConnection.class, RETURNS_DEEP_STUBS);
- when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("foo_db");
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class, RETURNS_DEEP_STUBS);
+ when(databaseConnectionManager.getConnectionSession().getDatabaseName()).thenReturn("foo_db");
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
ShardingSphereDatabase database = mockDatabase();
ContextManager contextManager = mockContextManager(database);
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
when(ProxyContext.getInstance().getDatabase("foo_db")).thenReturn(database);
- assertThat(DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), backendConnection, false),
+ assertThat(DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), databaseConnectionManager, false),
instanceOf(DatabaseConnector.class));
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java
index e4a7a113117..38fe44c88e5 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorTest.java
@@ -97,7 +97,7 @@ import static org.mockito.Mockito.when;
class DatabaseConnectorTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@Mock
private Statement statement;
@@ -107,7 +107,7 @@ class DatabaseConnectorTest {
@BeforeEach
void setUp() {
- when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("foo_db");
+ when(databaseConnectionManager.getConnectionSession().getDatabaseName()).thenReturn("foo_db");
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
ShardingSphereDatabase database = contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db");
@@ -138,8 +138,8 @@ class DatabaseConnectorTest {
SQLStatementContext<?> sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getDatabaseType()).thenReturn(new MySQLDatabaseType());
DatabaseConnector engine =
- DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), backendConnection, true);
- when(backendConnection.getConnectionSession().getStatementManager()).thenReturn(new JDBCBackendStatement());
+ DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), databaseConnectionManager, true);
+ when(databaseConnectionManager.getConnectionSession().getStatementManager()).thenReturn(new JDBCBackendStatement());
SQLFederationExecutor federationExecutor = mock(SQLFederationExecutor.class);
when(SystemSchemaUtils.containsSystemSchema(any(DatabaseType.class), any(), any(ShardingSphereDatabase.class))).thenReturn(true);
try (MockedStatic<TypedSPILoader> typedSPILoader = mockStatic(TypedSPILoader.class)) {
@@ -164,7 +164,7 @@ class DatabaseConnectorTest {
void assertBinaryProtocolQueryHeader() throws SQLException, NoSuchFieldException, IllegalAccessException {
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
- DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), backendConnection, true);
+ DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), databaseConnectionManager, true);
assertNotNull(engine);
assertThat(engine, instanceOf(DatabaseConnector.class));
Field queryHeadersField = DatabaseConnector.class.getDeclaredField("queryHeaders");
@@ -213,7 +213,7 @@ class DatabaseConnectorTest {
void assertAddStatementCorrectly() {
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
- DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), backendConnection, false);
+ DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), databaseConnectionManager, false);
engine.add(statement);
Collection<?> actual = getField(engine, "cachedStatements");
assertThat(actual.size(), is(1));
@@ -224,7 +224,7 @@ class DatabaseConnectorTest {
void assertAddResultSetCorrectly() {
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
- DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), backendConnection, false);
+ DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), databaseConnectionManager, false);
engine.add(resultSet);
Collection<?> actual = getField(engine, "cachedResultSets");
assertThat(actual.size(), is(1));
@@ -235,7 +235,7 @@ class DatabaseConnectorTest {
void assertCloseCorrectly() throws SQLException {
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
- DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), backendConnection, false);
+ DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), databaseConnectionManager, false);
Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");
cachedResultSets.add(resultSet);
Collection<Statement> cachedStatements = getField(engine, "cachedStatements");
@@ -252,7 +252,7 @@ class DatabaseConnectorTest {
void assertCloseResultSetsWithExceptionThrown() throws SQLException {
SQLStatementContext<?> sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
- DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), backendConnection, false);
+ DatabaseConnector engine = DatabaseConnectorFactory.getInstance().newInstance(new QueryContext(sqlStatementContext, "schemaName", Collections.emptyList()), databaseConnectionManager, false);
Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");
SQLException sqlExceptionByResultSet = new SQLException("ResultSet");
doThrow(sqlExceptionByResultSet).when(resultSet).close();
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/MockConnectionUtils.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/MockConnectionUtils.java
index a21be736066..3621d1d9104 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/MockConnectionUtils.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/MockConnectionUtils.java
@@ -39,15 +39,15 @@ final class MockConnectionUtils {
/**
* Mock set cached connections.
*
- * @param backendConnection backend connection
+ * @param databaseConnectionManager database connection manager
* @param dataSourceName datasource name
* @param connectionSize connection size
*/
@SneakyThrows(ReflectiveOperationException.class)
- static void setCachedConnections(final BackendConnection backendConnection, final String dataSourceName, final int connectionSize) {
+ static void setCachedConnections(final ProxyDatabaseConnectionManager databaseConnectionManager, final String dataSourceName, final int connectionSize) {
Multimap<String, Connection> cachedConnections = HashMultimap.create();
- cachedConnections.putAll(backendConnection.getConnectionSession().getDatabaseName() + "." + dataSourceName, mockNewConnections(connectionSize));
- Plugins.getMemberAccessor().set(backendConnection.getClass().getDeclaredField("cachedConnections"), backendConnection, cachedConnections);
+ cachedConnections.putAll(databaseConnectionManager.getConnectionSession().getDatabaseName() + "." + dataSourceName, mockNewConnections(connectionSize));
+ Plugins.getMemberAccessor().set(databaseConnectionManager.getClass().getDeclaredField("cachedConnections"), databaseConnectionManager, cachedConnections);
}
/**
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/BackendConnectionTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java
similarity index 80%
rename from proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/BackendConnectionTest.java
rename to proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java
index d2dd87f9c53..1cb9463f68a 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/BackendConnectionTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxyDatabaseConnectionManagerTest.java
@@ -76,7 +76,7 @@ import static org.mockito.Mockito.when;
@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(ProxyContext.class)
@MockitoSettings(strictness = Strictness.LENIENT)
-class BackendConnectionTest {
+class ProxyDatabaseConnectionManagerTest {
private static final String SCHEMA_PATTERN = "schema_%s";
@@ -86,14 +86,14 @@ class BackendConnectionTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ConnectionSession connectionSession;
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@BeforeEach
- void setUp() throws ReflectiveOperationException {
+ void setUp() {
when(ProxyContext.getInstance().getBackendDataSource()).thenReturn(backendDataSource);
when(connectionSession.getDatabaseName()).thenReturn(String.format(SCHEMA_PATTERN, 0));
- backendConnection = new BackendConnection(connectionSession);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ databaseConnectionManager = new ProxyDatabaseConnectionManager(connectionSession);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
when(connectionSession.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.LOCAL));
JDBCBackendStatement backendStatement = new JDBCBackendStatement();
when(connectionSession.getStatementManager()).thenReturn(backendStatement);
@@ -111,30 +111,30 @@ class BackendConnectionTest {
void assertGetConnectionCacheIsEmpty() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
when(backendDataSource.getConnections(anyString(), anyString(), eq(2), any())).thenReturn(MockConnectionUtils.mockNewConnections(2));
- List<Connection> actualConnections = backendConnection.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actualConnections = databaseConnectionManager.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
assertThat(actualConnections.size(), is(2));
- assertThat(backendConnection.getConnectionSize(), is(2));
+ assertThat(databaseConnectionManager.getConnectionSize(), is(2));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@Test
void assertGetConnectionSizeLessThanCache() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
- MockConnectionUtils.setCachedConnections(backendConnection, "ds1", 10);
- List<Connection> actualConnections = backendConnection.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
+ MockConnectionUtils.setCachedConnections(databaseConnectionManager, "ds1", 10);
+ List<Connection> actualConnections = databaseConnectionManager.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
assertThat(actualConnections.size(), is(2));
- assertThat(backendConnection.getConnectionSize(), is(10));
+ assertThat(databaseConnectionManager.getConnectionSize(), is(10));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@Test
void assertGetConnectionSizeGreaterThanCache() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
- MockConnectionUtils.setCachedConnections(backendConnection, "ds1", 10);
+ MockConnectionUtils.setCachedConnections(databaseConnectionManager, "ds1", 10);
when(backendDataSource.getConnections(anyString(), anyString(), eq(2), any())).thenReturn(MockConnectionUtils.mockNewConnections(2));
- List<Connection> actualConnections = backendConnection.getConnections("ds1", 12, ConnectionMode.MEMORY_STRICTLY);
+ List<Connection> actualConnections = databaseConnectionManager.getConnections("ds1", 12, ConnectionMode.MEMORY_STRICTLY);
assertThat(actualConnections.size(), is(12));
- assertThat(backendConnection.getConnectionSize(), is(12));
+ assertThat(databaseConnectionManager.getConnectionSize(), is(12));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@@ -143,8 +143,8 @@ class BackendConnectionTest {
connectionSession.getTransactionStatus().setInTransaction(true);
when(backendDataSource.getConnections(anyString(), anyString(), eq(2), any())).thenReturn(MockConnectionUtils.mockNewConnections(2));
setConnectionPostProcessors();
- List<Connection> actualConnections = backendConnection.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
- verify(backendConnection.getConnectionPostProcessors().iterator().next(), times(2)).process(any());
+ List<Connection> actualConnections = databaseConnectionManager.getConnections("ds1", 2, ConnectionMode.MEMORY_STRICTLY);
+ verify(databaseConnectionManager.getConnectionPostProcessors().iterator().next(), times(2)).process(any());
assertThat(actualConnections.size(), is(2));
assertTrue(connectionSession.getTransactionStatus().isInTransaction());
}
@@ -154,17 +154,17 @@ class BackendConnectionTest {
ConnectionPostProcessor connectionPostProcessor = mock(ConnectionPostProcessor.class);
Collection<ConnectionPostProcessor> connectionPostProcessors = new LinkedList<>();
connectionPostProcessors.add(connectionPostProcessor);
- Plugins.getMemberAccessor().set(BackendConnection.class.getDeclaredField("connectionPostProcessors"), backendConnection, connectionPostProcessors);
+ Plugins.getMemberAccessor().set(ProxyDatabaseConnectionManager.class.getDeclaredField("connectionPostProcessors"), databaseConnectionManager, connectionPostProcessors);
}
@SuppressWarnings("unchecked")
@Test
void assertCloseConnectionsCorrectlyWhenNotForceRollback() throws ReflectiveOperationException, SQLException {
Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) Plugins.getMemberAccessor()
- .get(BackendConnection.class.getDeclaredField("cachedConnections"), backendConnection);
+ .get(ProxyDatabaseConnectionManager.class.getDeclaredField("cachedConnections"), databaseConnectionManager);
Connection connection = prepareCachedConnections();
cachedConnections.put("ignoredDataSourceName", connection);
- backendConnection.closeConnections(false);
+ databaseConnectionManager.closeConnections(false);
verify(connection).close();
assertTrue(cachedConnections.isEmpty());
verifyConnectionPostProcessorsEmpty();
@@ -174,7 +174,7 @@ class BackendConnectionTest {
@SneakyThrows(ReflectiveOperationException.class)
private void verifyConnectionPostProcessorsEmpty() {
Collection<ConnectionPostProcessor> connectionPostProcessors = (Collection<ConnectionPostProcessor>) Plugins.getMemberAccessor()
- .get(BackendConnection.class.getDeclaredField("connectionPostProcessors"), backendConnection);
+ .get(ProxyDatabaseConnectionManager.class.getDeclaredField("connectionPostProcessors"), databaseConnectionManager);
assertTrue(connectionPostProcessors.isEmpty());
}
@@ -182,7 +182,7 @@ class BackendConnectionTest {
void assertCloseConnectionsCorrectlyWhenForceRollbackAndNotInTransaction() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(false);
Connection connection = prepareCachedConnections();
- backendConnection.closeConnections(true);
+ databaseConnectionManager.closeConnections(true);
verify(connection, never()).rollback();
}
@@ -190,7 +190,7 @@ class BackendConnectionTest {
void assertCloseConnectionsCorrectlyWhenForceRollbackAndInTransaction() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
Connection connection = prepareCachedConnections();
- backendConnection.closeConnections(true);
+ databaseConnectionManager.closeConnections(true);
verify(connection).rollback();
}
@@ -199,7 +199,7 @@ class BackendConnectionTest {
Connection connection = prepareCachedConnections();
SQLException sqlException = new SQLException("");
doThrow(sqlException).when(connection).close();
- assertTrue(backendConnection.closeConnections(false).contains(sqlException));
+ assertTrue(databaseConnectionManager.closeConnections(false).contains(sqlException));
}
@Test
@@ -220,7 +220,7 @@ class BackendConnectionTest {
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getDatabaseProductName()).thenReturn("PostgreSQL");
when(proxyContext.getBackendDataSource().getConnections(anyString(), anyString(), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
- List<Connection> actualConnections = backendConnection.getConnections("", 1, ConnectionMode.CONNECTION_STRICTLY);
+ List<Connection> actualConnections = databaseConnectionManager.getConnections("", 1, ConnectionMode.CONNECTION_STRICTLY);
Connection actualConnection = actualConnections.get(0);
verify(actualConnection.createStatement()).execute("SET key=value");
}
@@ -235,7 +235,7 @@ class BackendConnectionTest {
when(connection.getMetaData().getDatabaseProductName()).thenReturn("PostgreSQL");
when(connection.createStatement().execute("SET key=value")).thenThrow(expectedException);
when(ProxyContext.getInstance().getBackendDataSource().getConnections(anyString(), anyString(), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
- backendConnection.getConnections("", 1, ConnectionMode.CONNECTION_STRICTLY);
+ databaseConnectionManager.getConnections("", 1, ConnectionMode.CONNECTION_STRICTLY);
} catch (final SQLException ex) {
assertThat(ex, is(expectedException));
verify(connection).close();
@@ -247,7 +247,7 @@ class BackendConnectionTest {
connectionSession.getTransactionStatus().setInTransaction(false);
List<Connection> connections = MockConnectionUtils.mockNewConnections(1);
when(backendDataSource.getConnections(anyString(), anyString(), eq(1), any())).thenReturn(connections);
- List<Connection> fetchedConnections = backendConnection.getConnections("ds1", 1, null);
+ List<Connection> fetchedConnections = databaseConnectionManager.getConnections("ds1", 1, null);
assertThat(fetchedConnections.size(), is(1));
assertTrue(fetchedConnections.contains(connections.get(0)));
assertConnectionsCached(connectionSession.getDatabaseName() + ".ds1", connections);
@@ -257,7 +257,7 @@ class BackendConnectionTest {
@SneakyThrows(ReflectiveOperationException.class)
private void assertConnectionsCached(final String dataSourceName, final Collection<Connection> connections) {
Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) Plugins.getMemberAccessor()
- .get(BackendConnection.class.getDeclaredField("cachedConnections"), backendConnection);
+ .get(ProxyDatabaseConnectionManager.class.getDeclaredField("cachedConnections"), databaseConnectionManager);
assertTrue(cachedConnections.containsKey(dataSourceName));
assertArrayEquals(cachedConnections.get(dataSourceName).toArray(), connections.toArray());
}
@@ -267,7 +267,7 @@ class BackendConnectionTest {
when(connectionSession.isAutoCommit()).thenReturn(false);
connectionSession.getTransactionStatus().setInTransaction(false);
try (MockedConstruction<BackendTransactionManager> mockedConstruction = mockConstruction(BackendTransactionManager.class)) {
- backendConnection.handleAutoCommit();
+ databaseConnectionManager.handleAutoCommit();
verify(mockedConstruction.constructed().get(0)).begin();
}
}
@@ -275,7 +275,7 @@ class BackendConnectionTest {
@Test
void assertAddDatabaseConnector() {
ProxyBackendHandler expectedEngine = mock(DatabaseConnector.class);
- backendConnection.add(expectedEngine);
+ databaseConnectionManager.add(expectedEngine);
Collection<ProxyBackendHandler> actual = getBackendHandlers();
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(), is(expectedEngine));
@@ -284,8 +284,8 @@ class BackendConnectionTest {
@Test
void assertMarkDatabaseConnectorInUse() {
ProxyBackendHandler expectedEngine = mock(DatabaseConnector.class);
- backendConnection.add(expectedEngine);
- backendConnection.markResourceInUse(expectedEngine);
+ databaseConnectionManager.add(expectedEngine);
+ databaseConnectionManager.markResourceInUse(expectedEngine);
Collection<ProxyBackendHandler> actual = getInUseBackendHandlers();
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(), is(expectedEngine));
@@ -296,7 +296,7 @@ class BackendConnectionTest {
ProxyBackendHandler engine = mock(DatabaseConnector.class);
Collection<ProxyBackendHandler> actual = getInUseBackendHandlers();
actual.add(engine);
- backendConnection.unmarkResourceInUse(engine);
+ databaseConnectionManager.unmarkResourceInUse(engine);
assertTrue(actual.isEmpty());
}
@@ -311,13 +311,13 @@ class BackendConnectionTest {
databaseConnectors.add(engine);
databaseConnectors.add(inUseEngine);
inUseDatabaseConnectors.add(inUseEngine);
- Collection<SQLException> actual = backendConnection.closeHandlers(false);
+ Collection<SQLException> actual = databaseConnectionManager.closeHandlers(false);
assertThat(actual.size(), is(1));
assertThat(actual.iterator().next(), is(expectedException));
assertThat(inUseDatabaseConnectors.size(), is(1));
assertThat(databaseConnectors.size(), is(1));
verify(engine).close();
- backendConnection.closeHandlers(true);
+ databaseConnectionManager.closeHandlers(true);
verify(inUseEngine).close();
assertTrue(databaseConnectors.isEmpty());
assertTrue(inUseDatabaseConnectors.isEmpty());
@@ -330,7 +330,7 @@ class BackendConnectionTest {
getBackendHandlers().addAll(Arrays.asList(notInUseHandler, inUseHandler));
getInUseBackendHandlers().add(inUseHandler);
Connection cachedConnection = prepareCachedConnections();
- backendConnection.closeExecutionResources();
+ databaseConnectionManager.closeExecutionResources();
verify(cachedConnection).close();
assertTrue(getBackendHandlers().isEmpty());
assertTrue(getInUseBackendHandlers().isEmpty());
@@ -346,7 +346,7 @@ class BackendConnectionTest {
getBackendHandlers().addAll(Arrays.asList(notInUseHandler, inUseHandler));
getInUseBackendHandlers().add(inUseHandler);
Connection cachedConnection = prepareCachedConnections();
- backendConnection.closeExecutionResources();
+ databaseConnectionManager.closeExecutionResources();
verifyNoInteractions(inUseHandler, cachedConnection);
assertThat(getBackendHandlers(), is(Collections.singleton(inUseHandler)));
assertThat(getInUseBackendHandlers(), is(Collections.singleton(inUseHandler)));
@@ -355,21 +355,21 @@ class BackendConnectionTest {
@SuppressWarnings("unchecked")
@SneakyThrows(ReflectiveOperationException.class)
private Collection<ProxyBackendHandler> getBackendHandlers() {
- return (Collection<ProxyBackendHandler>) Plugins.getMemberAccessor().get(BackendConnection.class.getDeclaredField("backendHandlers"), backendConnection);
+ return (Collection<ProxyBackendHandler>) Plugins.getMemberAccessor().get(ProxyDatabaseConnectionManager.class.getDeclaredField("backendHandlers"), databaseConnectionManager);
}
@SuppressWarnings("unchecked")
@SneakyThrows(ReflectiveOperationException.class)
private Collection<ProxyBackendHandler> getInUseBackendHandlers() {
- return (Collection<ProxyBackendHandler>) Plugins.getMemberAccessor().get(BackendConnection.class.getDeclaredField("inUseBackendHandlers"), backendConnection);
+ return (Collection<ProxyBackendHandler>) Plugins.getMemberAccessor().get(ProxyDatabaseConnectionManager.class.getDeclaredField("inUseBackendHandlers"), databaseConnectionManager);
}
@Test
void assertCloseAllResourcesInTransaction() throws SQLException {
connectionSession.getTransactionStatus().setInTransaction(true);
Connection cachedConnection = prepareCachedConnections();
- backendConnection.closeAllResources();
- assertTrue(backendConnection.getClosed().get());
+ databaseConnectionManager.closeAllResources();
+ assertTrue(databaseConnectionManager.getClosed().get());
verify(cachedConnection).rollback();
}
@@ -377,7 +377,7 @@ class BackendConnectionTest {
@SneakyThrows(ReflectiveOperationException.class)
private Connection prepareCachedConnections() {
Multimap<String, Connection> cachedConnections = (Multimap<String, Connection>) Plugins.getMemberAccessor()
- .get(BackendConnection.class.getDeclaredField("cachedConnections"), backendConnection);
+ .get(ProxyDatabaseConnectionManager.class.getDeclaredField("cachedConnections"), databaseConnectionManager);
Connection connection = mock(Connection.class);
cachedConnections.put("ignoredDataSourceName", connection);
return connection;
@@ -388,8 +388,8 @@ class BackendConnectionTest {
connectionSession.getRequiredSessionVariableRecorder().setVariable("key", "default");
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getDatabaseProductName()).thenReturn("PostgreSQL");
- backendConnection.getCachedConnections().put("", connection);
- backendConnection.closeConnections(false);
+ databaseConnectionManager.getCachedConnections().put("", connection);
+ databaseConnectionManager.closeConnections(false);
verify(connection.createStatement()).execute("RESET ALL");
assertTrue(connectionSession.getRequiredSessionVariableRecorder().isEmpty());
}
@@ -400,8 +400,8 @@ class BackendConnectionTest {
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
SQLException expectedException = new SQLException();
when(connection.getMetaData().getDatabaseProductName()).thenThrow(expectedException);
- backendConnection.getCachedConnections().put("", connection);
- Collection<SQLException> actualExceptions = backendConnection.closeConnections(false);
+ databaseConnectionManager.getCachedConnections().put("", connection);
+ Collection<SQLException> actualExceptions = databaseConnectionManager.closeConnections(false);
assertThat(actualExceptions, is(Collections.singletonList(expectedException)));
}
@@ -412,17 +412,17 @@ class BackendConnectionTest {
when(connection.getMetaData().getDatabaseProductName()).thenReturn("PostgreSQL");
SQLException expectedException = new SQLException();
when(connection.createStatement()).thenThrow(expectedException);
- backendConnection.getCachedConnections().put("", connection);
- Collection<SQLException> actualExceptions = backendConnection.closeConnections(false);
+ databaseConnectionManager.getCachedConnections().put("", connection);
+ Collection<SQLException> actualExceptions = databaseConnectionManager.closeConnections(false);
assertThat(actualExceptions, is(Collections.singletonList(expectedException)));
}
@Test
void assertGetDataSourceNamesOfCachedConnections() {
- backendConnection.getCachedConnections().put(connectionSession.getDatabaseName() + ".ds_0", null);
- backendConnection.getCachedConnections().put(connectionSession.getDatabaseName() + ".ds_1", null);
- backendConnection.getCachedConnections().put(connectionSession.getDatabaseName() + ".ds_2", null);
- List<String> actual = new ArrayList<>(backendConnection.getDataSourceNamesOfCachedConnections());
+ databaseConnectionManager.getCachedConnections().put(connectionSession.getDatabaseName() + ".ds_0", null);
+ databaseConnectionManager.getCachedConnections().put(connectionSession.getDatabaseName() + ".ds_1", null);
+ databaseConnectionManager.getCachedConnections().put(connectionSession.getDatabaseName() + ".ds_2", null);
+ List<String> actual = new ArrayList<>(databaseConnectionManager.getDataSourceNamesOfCachedConnections());
Collections.sort(actual);
assertThat(actual, is(Arrays.asList("ds_0", "ds_1", "ds_2")));
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java
index 5beaffcd7ed..53806ce3098 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java
@@ -80,14 +80,14 @@ class ProxySQLExecutorTest {
private ConnectionSession connectionSession;
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@BeforeEach
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);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
ContextManager contextManager = new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()), mock(InstanceContext.class));
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
}
@@ -97,7 +97,7 @@ class ProxySQLExecutorTest {
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
assertThrows(TableModifyInTransactionException.class,
- () -> new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext));
+ () -> new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext));
}
@Test
@@ -105,7 +105,7 @@ class ProxySQLExecutorTest {
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createMySQLTruncateStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
assertThrows(TableModifyInTransactionException.class,
- () -> new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext));
+ () -> new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext));
}
@Test
@@ -113,14 +113,14 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createMySQLTruncateStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
void assertCheckExecutePrerequisitesWhenExecuteDMLInXATransaction() {
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createMySQLInsertStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -128,7 +128,7 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.BASE);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -136,7 +136,7 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().isInTransaction()).thenReturn(false);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -145,7 +145,7 @@ class ProxySQLExecutorTest {
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createPostgreSQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
assertThrows(TableModifyInTransactionException.class,
- () -> new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext));
+ () -> new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext));
}
@Test
@@ -153,7 +153,7 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createPostgreSQLTruncateStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -161,7 +161,7 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createCursorStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -169,7 +169,7 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createPostgreSQLInsertStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -177,7 +177,7 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createMySQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
@Test
@@ -186,7 +186,7 @@ class ProxySQLExecutorTest {
when(connectionSession.getTransactionStatus().isInTransaction()).thenReturn(false);
ExecutionContext executionContext = new ExecutionContext(
new QueryContext(createPostgreSQLCreateTableStatementContext(), "", Collections.emptyList()), Collections.emptyList(), mock(RouteContext.class));
- new ProxySQLExecutor(JDBCDriverType.STATEMENT, backendConnection, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
+ new ProxySQLExecutor(JDBCDriverType.STATEMENT, databaseConnectionManager, mock(DatabaseConnector.class)).checkExecutePrerequisites(executionContext);
}
private CreateTableStatementContext createMySQLCreateTableStatementContext() {
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java
index 86ecf0dbf95..1bb3a6b8d4e 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.connection.ConnectionContext;
import org.apache.shardingsphere.infra.connection.transaction.TransactionConnectionContext;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
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;
@@ -58,7 +58,7 @@ class BackendTransactionManagerTest {
private ConnectionSession connectionSession;
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@Mock
private TransactionStatus transactionStatus;
@@ -74,7 +74,7 @@ class BackendTransactionManagerTest {
@BeforeEach
void setUp() {
when(connectionSession.getTransactionStatus()).thenReturn(transactionStatus);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
ConnectionContext connectionContext = mock(ConnectionContext.class);
when(connectionSession.getConnectionContext()).thenReturn(connectionContext);
TransactionConnectionContext context = new TransactionConnectionContext();
@@ -88,8 +88,8 @@ class BackendTransactionManagerTest {
newBackendTransactionManager(TransactionType.LOCAL, false);
backendTransactionManager.begin();
verify(transactionStatus).setInTransaction(true);
- verify(backendConnection).closeHandlers(true);
- verify(backendConnection).closeConnections(false);
+ verify(databaseConnectionManager).closeHandlers(true);
+ verify(databaseConnectionManager).closeConnections(false);
verify(localTransactionManager).begin();
}
@@ -100,7 +100,7 @@ class BackendTransactionManagerTest {
newBackendTransactionManager(TransactionType.XA, true);
backendTransactionManager.begin();
verify(transactionStatus, times(0)).setInTransaction(true);
- verify(backendConnection, times(0)).closeConnections(false);
+ verify(databaseConnectionManager, times(0)).closeConnections(false);
verify(shardingSphereTransactionManager).begin();
}
@@ -169,7 +169,7 @@ 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(backendConnection);
+ backendTransactionManager = new BackendTransactionManager(databaseConnectionManager);
setLocalTransactionManager();
setTransactionHooks();
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java
index 67225b2166e..c8ed7bdedb4 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/LocalTransactionManagerTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.session.transaction.TransactionStatus;
import org.junit.jupiter.api.BeforeEach;
@@ -46,7 +46,7 @@ class LocalTransactionManagerTest {
private ConnectionSession connectionSession;
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@Mock
private TransactionStatus transactionStatus;
@@ -59,10 +59,10 @@ class LocalTransactionManagerTest {
@BeforeEach
void setUp() {
when(connectionSession.getTransactionStatus()).thenReturn(transactionStatus);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
- when(backendConnection.getCachedConnections()).thenReturn(setCachedConnections());
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
+ when(databaseConnectionManager.getCachedConnections()).thenReturn(setCachedConnections());
when(transactionStatus.isInTransaction()).thenReturn(true);
- localTransactionManager = new LocalTransactionManager(backendConnection);
+ localTransactionManager = new LocalTransactionManager(databaseConnectionManager);
}
private Multimap<String, Connection> setCachedConnections() {
@@ -76,7 +76,7 @@ class LocalTransactionManagerTest {
@Test
void assertBegin() {
localTransactionManager.begin();
- verify(backendConnection).getConnectionPostProcessors();
+ verify(databaseConnectionManager).getConnectionPostProcessors();
}
@Test
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
index 6584ef780c8..1b6a97c5959 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.admin.DatabaseAdminQueryBackendHandler;
@@ -86,9 +86,9 @@ class ProxyBackendHandlerFactoryTest {
when(connectionSession.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
when(connectionSession.getDefaultDatabaseName()).thenReturn("db");
when(connectionSession.getDatabaseName()).thenReturn("db");
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
ContextManager contextManager = mockContextManager();
when(contextManager.getClusterStateContext().getCurrentState()).thenReturn(ClusterState.OK);
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java
index fdd60f48e2d..4156d7bdd51 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.data.impl.UnicastDatabaseBackendHandler;
@@ -100,8 +100,8 @@ class DatabaseBackendHandlerFactoryTest {
private static ConnectionSession mockConnectionSession() {
ConnectionSession result = mock(ConnectionSession.class);
when(result.getDatabaseName()).thenReturn("foo_db");
- when(result.getBackendConnection()).thenReturn(mock(BackendConnection.class));
- when(result.getBackendConnection().getConnectionSession()).thenReturn(result);
+ when(result.getDatabaseConnectionManager()).thenReturn(mock(ProxyDatabaseConnectionManager.class));
+ when(result.getDatabaseConnectionManager().getConnectionSession()).thenReturn(result);
return result;
}
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java
index f895f74ec24..44b98499769 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRule
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -85,7 +85,7 @@ class UnicastDatabaseBackendHandlerTest {
@BeforeEach
void setUp() throws SQLException {
when(connectionSession.getDefaultDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
- when(connectionSession.getBackendConnection()).thenReturn(mock(BackendConnection.class));
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(mock(ProxyDatabaseConnectionManager.class));
mockDatabaseConnector(new UpdateResponseHeader(mock(SQLStatement.class)));
unicastDatabaseBackendHandler = new UnicastDatabaseBackendHandler(new QueryContext(mock(SQLStatementContext.class), EXECUTE_SQL, Collections.emptyList()), connectionSession);
setBackendHandlerFactory(unicastDatabaseBackendHandler);
@@ -93,7 +93,7 @@ class UnicastDatabaseBackendHandlerTest {
private void mockDatabaseConnector(final ResponseHeader responseHeader) throws SQLException {
when(databaseConnector.execute()).thenReturn(responseHeader);
- when(databaseConnectorFactory.newInstance(any(QueryContext.class), any(BackendConnection.class), eq(false))).thenReturn(databaseConnector);
+ when(databaseConnectorFactory.newInstance(any(QueryContext.class), any(ProxyDatabaseConnectionManager.class), eq(false))).thenReturn(databaseConnector);
}
@SneakyThrows(ReflectiveOperationException.class)
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
index a2533d0c6ec..cbc43f132af 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java
@@ -72,7 +72,7 @@ class ShowDistVariableExecutorTest {
@Test
void assertShowCachedConnections() {
- when(connectionSession.getBackendConnection().getConnectionSize()).thenReturn(1);
+ when(connectionSession.getDatabaseConnectionManager().getConnectionSize()).thenReturn(1);
ShowDistVariableExecutor executor = new ShowDistVariableExecutor();
Collection<LocalDataQueryResultRow> actual = executor.getRows(metaData, connectionSession, new ShowDistVariableStatement("CACHED_CONNECTIONS"));
assertThat(actual.size(), is(1));
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java
index da7a1156b53..9c2a6c1498b 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager;
@@ -62,9 +62,9 @@ class TransactionBackendHandlerFactoryTest {
@Test
void assertTransactionBackendHandlerReturnedWhenTCLStatementInstanceOfCommitStatement() {
ConnectionSession connectionSession = mock(ConnectionSession.class, Answers.RETURNS_DEEP_STUBS);
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
SQLStatementContext<CommitStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(CommitStatement.class));
ContextManager contextManager = mockContextManager();
@@ -73,15 +73,15 @@ class TransactionBackendHandlerFactoryTest {
assertThat(proxyBackendHandler, instanceOf(TransactionBackendHandler.class));
TransactionBackendHandler transactionBackendHandler = (TransactionBackendHandler) proxyBackendHandler;
assertFieldOfInstance(transactionBackendHandler, "operationType", is(TransactionOperationType.COMMIT));
- assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(backendConnection));
+ assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(databaseConnectionManager));
}
@Test
void assertTransactionBackendHandlerReturnedWhenTCLStatementInstanceOfRollbackStatement() {
ConnectionSession connectionSession = mock(ConnectionSession.class, Answers.RETURNS_DEEP_STUBS);
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
SQLStatementContext<RollbackStatement> context = mock(SQLStatementContext.class);
when(context.getSqlStatement()).thenReturn(mock(RollbackStatement.class));
ContextManager contextManager = mockContextManager();
@@ -90,7 +90,7 @@ class TransactionBackendHandlerFactoryTest {
assertThat(proxyBackendHandler, instanceOf(TransactionBackendHandler.class));
TransactionBackendHandler transactionBackendHandler = (TransactionBackendHandler) proxyBackendHandler;
assertFieldOfInstance(transactionBackendHandler, "operationType", is(TransactionOperationType.ROLLBACK));
- assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(backendConnection));
+ assertFieldOfInstance(getBackendTransactionManager(transactionBackendHandler), "connection", is(databaseConnectionManager));
}
private ContextManager mockContextManager() {
@@ -106,7 +106,7 @@ class TransactionBackendHandlerFactoryTest {
when(context.getSqlStatement()).thenReturn(mock(TCLStatement.class));
DatabaseConnectorFactory mockFactory = mock(DatabaseConnectorFactory.class);
when(DatabaseConnectorFactory.getInstance()).thenReturn(mockFactory);
- when(mockFactory.newInstance(any(QueryContext.class), nullable(BackendConnection.class), anyBoolean())).thenReturn(mock(DatabaseConnector.class));
+ when(mockFactory.newInstance(any(QueryContext.class), nullable(ProxyDatabaseConnectionManager.class), anyBoolean())).thenReturn(mock(DatabaseConnector.class));
assertThat(TransactionBackendHandlerFactory.newInstance(context, null, mock(ConnectionSession.class)), instanceOf(DatabaseConnector.class));
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java
index 5ab0b540fa5..36847eef2bb 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.handler.transaction;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -48,9 +48,9 @@ class TransactionBackendHandlerTest {
@Test
void assertExecute() throws SQLException {
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
assertThat(new TransactionBackendHandler(mock(TCLStatement.class), TransactionOperationType.BEGIN, connectionSession).execute(), instanceOf(UpdateResponseHeader.class));
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
index 5982041b23f..f548c710577 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java
@@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
@@ -55,14 +55,14 @@ import static org.mockito.Mockito.when;
class ConnectionSessionTest {
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
private ConnectionSession connectionSession;
@BeforeEach
void setup() {
connectionSession = new ConnectionSession(mock(MySQLDatabaseType.class), TransactionType.LOCAL, null);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
}
@Test
@@ -76,7 +76,7 @@ class ConnectionSessionTest {
connectionSession.setCurrentDatabase("db");
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
- new BackendTransactionManager(backendConnection).begin();
+ new BackendTransactionManager(databaseConnectionManager).begin();
assertThrows(SwitchTypeInTransactionException.class, () -> connectionSession.getTransactionStatus().setTransactionType(TransactionType.XA));
}
@@ -85,7 +85,7 @@ class ConnectionSessionTest {
connectionSession.setCurrentDatabase("db");
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
- new BackendTransactionManager(backendConnection).begin();
+ new BackendTransactionManager(databaseConnectionManager).begin();
connectionSession.setCurrentDatabase("newDB");
assertThat(connectionSession.getDefaultDatabaseName(), is("newDB"));
}
diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutor.java
index 31759684e2e..414681be795 100644
--- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutor.java
+++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLSetVariableAdminExecutor.java
@@ -87,7 +87,7 @@ public final class MySQLSetVariableAdminExecutor implements DatabaseAdminExecuto
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement, connectionSession.getDefaultDatabaseName());
DatabaseBackendHandler databaseBackendHandler = DatabaseConnectorFactory.getInstance()
- .newInstance(new QueryContext(sqlStatementContext, sql, Collections.emptyList()), connectionSession.getBackendConnection(), false);
+ .newInstance(new QueryContext(sqlStatementContext, sql, Collections.emptyList()), connectionSession.getDatabaseConnectionManager(), false);
try {
databaseBackendHandler.execute();
} finally {
diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java
index 3f57bc3c945..2c59141e6f7 100644
--- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java
+++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/UnicastResourceShowExecutor.java
@@ -81,7 +81,7 @@ public final class UnicastResourceShowExecutor implements DatabaseAdminQueryExec
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement, connectionSession.getDefaultDatabaseName());
databaseConnector = databaseConnectorFactory.newInstance(new QueryContext(sqlStatementContext, sql, Collections.emptyList()),
- connectionSession.getBackendConnection(), false);
+ connectionSession.getDatabaseConnectionManager(), false);
responseHeader = databaseConnector.execute();
mergedResult = new TransparentMergedResult(createQueryResult());
} finally {
diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
index d54286cb6e0..defe103c1c5 100644
--- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
+++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLSetVariableAdminExecutorTest.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRule
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLSetVariableAdminExecutor;
@@ -57,9 +57,9 @@ class MySQLSetVariableAdminExecutorTest {
MySQLSetVariableAdminExecutor executor = new MySQLSetVariableAdminExecutor(setStatement);
ConnectionSession connectionSession = mock(ConnectionSession.class);
when(connectionSession.getDatabaseName()).thenReturn("foo_db");
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
try (MockedConstruction<DatabaseConnector> mockConstruction = mockConstruction(DatabaseConnector.class)) {
diff --git a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index 4fbac705911..433ec223ca6 100644
--- a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++ b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -88,7 +88,7 @@ public final class CommandExecutorTask implements Runnable {
connectionSession.clearQueryContext();
Collection<SQLException> exceptions = Collections.emptyList();
try {
- connectionSession.getBackendConnection().closeExecutionResources();
+ connectionSession.getDatabaseConnectionManager().closeExecutionResources();
} catch (final BackendConnectionException ex) {
exceptions = ex.getExceptions().stream().filter(SQLException.class::isInstance).map(SQLException.class::cast).collect(Collectors.toList());
}
@@ -119,7 +119,7 @@ public final class CommandExecutorTask implements Runnable {
}
responsePackets.forEach(context::write);
if (commandExecutor instanceof QueryCommandExecutor) {
- commandExecuteEngine.writeQueryData(context, connectionSession.getBackendConnection(), (QueryCommandExecutor) commandExecutor, responsePackets.size());
+ commandExecuteEngine.writeQueryData(context, connectionSession.getDatabaseConnectionManager(), (QueryCommandExecutor) commandExecutor, responsePackets.size());
}
return true;
} catch (final SQLException | ShardingSphereSQLException | SQLDialectException ex) {
diff --git a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
index d046b9dcc5b..69b2f92b2b4 100644
--- a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
+++ b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
@@ -107,7 +107,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
private void closeAllResources() {
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(connectionSession.getConnectionId());
- connectionSession.getBackendConnection().closeAllResources();
+ connectionSession.getDatabaseConnectionManager().closeAllResources();
Optional.ofNullable(connectionSession.getProcessId()).ifPresent(processEngine::disconnect);
databaseProtocolFrontendEngine.release(connectionSession);
}
@@ -115,7 +115,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
@Override
public void channelWritabilityChanged(final ChannelHandlerContext context) {
if (context.channel().isWritable()) {
- connectionSession.getBackendConnection().getResourceLock().doNotify();
+ connectionSession.getDatabaseConnectionManager().getResourceLock().doNotify();
}
}
}
diff --git a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
index e0e0f18751c..059f1b36f94 100644
--- a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
+++ b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTaskTest.java
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.BackendConnectionException;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -70,7 +70,7 @@ class CommandExecutorTaskTest {
private ConnectionSession connectionSession;
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ChannelHandlerContext handlerContext;
@@ -96,7 +96,7 @@ class CommandExecutorTaskTest {
@BeforeEach
void setup() {
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
when(handlerContext.channel().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).get()).thenReturn(StandardCharsets.UTF_8);
when(ProxyContext.getInstance().getContextManager()).thenReturn(
new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()), mock(InstanceContext.class)));
@@ -112,7 +112,7 @@ class CommandExecutorTaskTest {
CommandExecutorTask actual = new CommandExecutorTask(engine, connectionSession, handlerContext, message);
actual.run();
verify(queryCommandExecutor).close();
- verify(backendConnection).closeExecutionResources();
+ verify(databaseConnectionManager).closeExecutionResources();
}
@SuppressWarnings("unchecked")
@@ -127,9 +127,9 @@ class CommandExecutorTaskTest {
actual.run();
verify(handlerContext).write(databasePacket);
verify(handlerContext).flush();
- verify(engine.getCommandExecuteEngine()).writeQueryData(handlerContext, backendConnection, queryCommandExecutor, 1);
+ verify(engine.getCommandExecuteEngine()).writeQueryData(handlerContext, databaseConnectionManager, queryCommandExecutor, 1);
verify(queryCommandExecutor).close();
- verify(backendConnection).closeExecutionResources();
+ verify(databaseConnectionManager).closeExecutionResources();
}
@SuppressWarnings("unchecked")
@@ -145,7 +145,7 @@ class CommandExecutorTaskTest {
verify(handlerContext).write(databasePacket);
verify(handlerContext).flush();
verify(commandExecutor).close();
- verify(backendConnection).closeExecutionResources();
+ verify(databaseConnectionManager).closeExecutionResources();
}
@SuppressWarnings("unchecked")
@@ -163,7 +163,7 @@ class CommandExecutorTaskTest {
actual.run();
verify(handlerContext, times(2)).write(databasePacket);
verify(handlerContext).flush();
- verify(backendConnection).closeExecutionResources();
+ verify(databaseConnectionManager).closeExecutionResources();
}
@Test
@@ -179,6 +179,6 @@ class CommandExecutorTaskTest {
actual.run();
verify(handlerContext, times(2)).write(databasePacket);
verify(handlerContext).flush();
- verify(backendConnection).closeExecutionResources();
+ verify(databaseConnectionManager).closeExecutionResources();
}
}
diff --git a/proxy/frontend/spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecuteEngine.java b/proxy/frontend/spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecuteEngine.java
index 6ad5e877686..f296c327f25 100644
--- a/proxy/frontend/spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecuteEngine.java
+++ b/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.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
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;
@@ -84,10 +84,11 @@ public interface CommandExecuteEngine {
* Write query data.
*
* @param context channel handler context
- * @param backendConnection backend connection
+ * @param databaseConnectionManager database connection manager
* @param queryCommandExecutor query command executor
* @param headerPackagesCount count of header packages
* @throws SQLException SQL exception
*/
- void writeQueryData(ChannelHandlerContext context, BackendConnection backendConnection, QueryCommandExecutor queryCommandExecutor, int headerPackagesCount) throws SQLException;
+ void writeQueryData(ChannelHandlerContext context,
+ ProxyDatabaseConnectionManager databaseConnectionManager, QueryCommandExecutor queryCommandExecutor, int headerPackagesCount) throws SQLException;
}
diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
index 33a33a99782..2a337ca473c 100644
--- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
+++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
@@ -76,7 +76,7 @@ public final class MySQLCommandExecuteEngine implements CommandExecuteEngine {
@Override
public void writeQueryData(final ChannelHandlerContext context,
- final BackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
+ final ProxyDatabaseConnectionManager databaseConnectionManager, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
if (ResponseType.QUERY != queryCommandExecutor.getResponseType() || !context.channel().isActive()) {
return;
}
@@ -86,7 +86,7 @@ public final class MySQLCommandExecuteEngine implements CommandExecuteEngine {
count++;
while (!context.channel().isWritable() && context.channel().isActive()) {
context.flush();
- backendConnection.getResourceLock().doAwait();
+ databaseConnectionManager.getResourceLock().doAwait();
}
DatabasePacket<?> dataValue = queryCommandExecutor.getQueryRowPacket();
context.write(dataValue);
@@ -95,6 +95,6 @@ public final class MySQLCommandExecuteEngine implements CommandExecuteEngine {
count = 0;
}
}
- context.write(new MySQLEofPacket(ServerStatusFlagCalculator.calculateFor(backendConnection.getConnectionSession())));
+ context.write(new MySQLEofPacket(ServerStatusFlagCalculator.calculateFor(databaseConnectionManager.getConnectionSession())));
}
}
diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutor.java
index 6b611789e3c..c1a450fa90b 100644
--- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutor.java
+++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutor.java
@@ -39,7 +39,7 @@ public final class MySQLComResetConnectionExecutor implements CommandExecutor {
@Override
public Collection<DatabasePacket<?>> execute() throws SQLException {
- new BackendTransactionManager(connectionSession.getBackendConnection()).rollback();
+ new BackendTransactionManager(connectionSession.getDatabaseConnectionManager()).rollback();
connectionSession.setAutoCommit(true);
connectionSession.setDefaultIsolationLevel(null);
connectionSession.setIsolationLevel(null);
diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
index fb2acf147c5..e4a62959827 100644
--- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
+++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnector;
import org.apache.shardingsphere.proxy.backend.connector.DatabaseConnectorFactory;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -67,9 +67,9 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(TypedSPILoader.getService(DatabaseType.class, "MySQL").getType()).parse(sql, false);
SQLStatementContext<?> sqlStatementContext = SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData(), sqlStatement, databaseName);
- BackendConnection backendConnection = connectionSession.getBackendConnection();
+ ProxyDatabaseConnectionManager databaseConnectionManager = connectionSession.getDatabaseConnectionManager();
QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList());
- databaseConnector = DatabaseConnectorFactory.getInstance().newInstance(queryContext, backendConnection, false);
+ databaseConnector = DatabaseConnectorFactory.getInstance().newInstance(queryContext, databaseConnectionManager, false);
databaseConnector.execute();
return createColumnDefinition41Packets(databaseName);
}
diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
index 72f06c1d6b8..96361bb5684 100644
--- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
+++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java
@@ -93,7 +93,7 @@ public final class MySQLMultiStatementsHandler implements ProxyBackendHandler {
public MySQLMultiStatementsHandler(final ConnectionSession connectionSession, final SQLStatement sqlStatementSample, final String sql) {
jdbcExecutor = new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), connectionSession.getConnectionContext());
- connectionSession.getBackendConnection().handleAutoCommit();
+ connectionSession.getDatabaseConnectionManager().handleAutoCommit();
this.connectionSession = connectionSession;
this.sqlStatementSample = sqlStatementSample;
Pattern pattern = sqlStatementSample instanceof UpdateStatement ? MULTI_UPDATE_STATEMENTS : MULTI_DELETE_STATEMENTS;
@@ -138,7 +138,7 @@ public final class MySQLMultiStatementsHandler implements ProxyBackendHandler {
public ResponseHeader execute() throws SQLException {
Collection<ShardingSphereRule> rules = metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getRuleMetaData().getRules();
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, metaDataContexts.getMetaData().getProps()
- .<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), connectionSession.getBackendConnection(),
+ .<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY), connectionSession.getDatabaseConnectionManager(),
(JDBCBackendStatement) connectionSession.getStatementManager(), new StatementOption(false), rules,
metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getResourceMetaData().getStorageTypes());
ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = prepareEngine.prepare(anyExecutionContext.getRouteContext(), samplingExecutionUnit(),
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
index f88c8b500d5..3c50c4af57c 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
@@ -30,7 +30,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.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.mysql.command.admin.MySQLComResetConnectionExecutor;
import org.apache.shardingsphere.proxy.frontend.mysql.command.admin.MySQLComSetOptionExecutor;
@@ -69,12 +69,12 @@ class MySQLCommandExecutorFactoryTest {
private ConnectionSession connectionSession;
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@BeforeEach
void setUp() {
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get()).thenReturn(MySQLCharacterSet.UTF8MB4_GENERAL_CI);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
}
@Test
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutorTest.java
index a20e82edaa9..8d982db486c 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutorTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComResetConnectionExecutorTest.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.frontend.mysql.command.admin;
import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.session.ServerPreparedStatementRegistry;
@@ -50,8 +50,8 @@ class MySQLComResetConnectionExecutorTest {
@Test
void assertExecute() throws SQLException {
ConnectionSession connectionSession = mock(ConnectionSession.class);
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
when(connectionSession.getTransactionStatus()).thenReturn(new TransactionStatus(TransactionType.LOCAL));
when(connectionSession.getServerPreparedStatementRegistry()).thenReturn(new ServerPreparedStatementRegistry());
int statementId = 1;
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
index e3fae352fc6..06605e2c4be 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
@@ -34,7 +34,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.statement.dml.UpdateStatementContext;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell;
@@ -95,12 +95,12 @@ class MySQLComStmtExecuteExecutorTest {
private ConnectionSession connectionSession;
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@BeforeEach
void setUp() {
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get()).thenReturn(MySQLCharacterSet.UTF8MB4_GENERAL_CI);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
SQLStatementContext<?> selectStatementContext = prepareSelectStatementContext();
when(connectionSession.getServerPreparedStatementRegistry().getPreparedStatement(1))
.thenReturn(new MySQLServerPreparedStatement("SELECT * FROM tbl WHERE id = ?", selectStatementContext, Collections.emptyList()));
diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
index e13ddac1bab..313d998078c 100644
--- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
+++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigur
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.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
@@ -89,9 +89,9 @@ class MySQLMultiStatementsHandlerTest {
Statement statement = mock(Statement.class);
when(statement.getConnection()).thenReturn(connection);
when(statement.executeBatch()).thenReturn(new int[]{1, 1, 1});
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(backendConnection.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
- when(result.getBackendConnection()).thenReturn(backendConnection);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(databaseConnectionManager.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
+ when(result.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
JDBCBackendStatement backendStatement = mock(JDBCBackendStatement.class);
when(backendStatement.createStorageResource(eq(connection), any(ConnectionMode.class), any(StatementOption.class), nullable(DatabaseType.class))).thenReturn(statement);
when(result.getStatementManager()).thenReturn(backendStatement);
diff --git a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java
index c52c12bc9d5..95890e4d5bc 100644
--- a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java
+++ b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecuteEngine.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
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;
@@ -74,7 +74,7 @@ public final class OpenGaussCommandExecuteEngine implements CommandExecuteEngine
@Override
public void writeQueryData(final ChannelHandlerContext context,
- final BackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
- postgreSQLCommandExecuteEngine.writeQueryData(context, backendConnection, queryCommandExecutor, headerPackagesCount);
+ final ProxyDatabaseConnectionManager databaseConnectionManager, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
+ postgreSQLCommandExecuteEngine.writeQueryData(context, databaseConnectionManager, queryCommandExecutor, headerPackagesCount);
}
}
diff --git a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java
index 244abb55ef8..e320232162f 100644
--- a/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java
+++ b/proxy/frontend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutor.java
@@ -45,7 +45,7 @@ public final class OpenGaussComBatchBindExecutor implements CommandExecutor {
@Override
public Collection<DatabasePacket<?>> execute() throws SQLException {
- connectionSession.getBackendConnection().handleAutoCommit();
+ connectionSession.getDatabaseConnectionManager().handleAutoCommit();
PostgreSQLServerPreparedStatement preparedStatement = connectionSession.getServerPreparedStatementRegistry().getPreparedStatement(packet.getStatementId());
int updateCount = new PostgreSQLBatchedStatementsExecutor(connectionSession, preparedStatement, packet.readParameterSets(preparedStatement.getParameterTypes())).executeBatch();
return Arrays.asList(PostgreSQLBindCompletePacket.getInstance(), createCommandComplete(preparedStatement.getSqlStatementContext().getSqlStatement(), updateCount));
diff --git a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
index 920eb770cc5..9a3f0a2f95e 100644
--- a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
+++ b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
@@ -36,7 +36,7 @@ import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -98,17 +98,17 @@ class OpenGaussComBatchBindExecutorTest {
ConnectionSession result = mock(ConnectionSession.class);
when(result.getConnectionContext()).thenReturn(new ConnectionContext());
when(result.getDatabaseName()).thenReturn("foo_db");
- BackendConnection backendConnection = mock(BackendConnection.class);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getURL()).thenReturn("jdbc:opengauss://127.0.0.1/foo_db");
- when(backendConnection.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
+ when(databaseConnectionManager.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
PreparedStatement preparedStatement = mock(PreparedStatement.class);
when(preparedStatement.getConnection()).thenReturn(connection);
JDBCBackendStatement backendStatement = mock(JDBCBackendStatement.class);
when(backendStatement.createStorageResource(any(ExecutionUnit.class), any(Connection.class), any(ConnectionMode.class), any(StatementOption.class), nullable(DatabaseType.class)))
.thenReturn(preparedStatement);
when(result.getStatementManager()).thenReturn(backendStatement);
- when(result.getBackendConnection()).thenReturn(backendConnection);
+ when(result.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
when(result.getServerPreparedStatementRegistry()).thenReturn(new ServerPreparedStatementRegistry());
return result;
}
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
index d69f2d39bd6..a0480196fcc 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
@@ -31,7 +31,7 @@ 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.props.ConfigurationPropertyKey;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
@@ -77,29 +77,31 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
@Override
public void writeQueryData(final ChannelHandlerContext context,
- final BackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
+ final ProxyDatabaseConnectionManager databaseConnectionManager, final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount) throws SQLException {
if (ResponseType.QUERY == queryCommandExecutor.getResponseType() && !context.channel().isActive()) {
context.write(new PostgreSQLCommandCompletePacket(PostgreSQLCommand.SELECT.name(), 0));
return;
}
- processSimpleQuery(context, backendConnection, queryCommandExecutor);
+ processSimpleQuery(context, databaseConnectionManager, queryCommandExecutor);
}
- private void processSimpleQuery(final ChannelHandlerContext context, final BackendConnection backendConnection, final QueryCommandExecutor queryExecutor) throws SQLException {
+ private void processSimpleQuery(final ChannelHandlerContext context, final ProxyDatabaseConnectionManager databaseConnectionManager,
+ final QueryCommandExecutor queryExecutor) throws SQLException {
if (ResponseType.UPDATE == queryExecutor.getResponseType()) {
- context.write(backendConnection.getConnectionSession().getTransactionStatus().isInTransaction() ? PostgreSQLReadyForQueryPacket.IN_TRANSACTION
+ context.write(databaseConnectionManager.getConnectionSession().getTransactionStatus().isInTransaction() ? PostgreSQLReadyForQueryPacket.IN_TRANSACTION
: PostgreSQLReadyForQueryPacket.NOT_IN_TRANSACTION);
return;
}
- long dataRows = writeDataPackets(context, backendConnection, queryExecutor);
+ long dataRows = writeDataPackets(context, databaseConnectionManager, queryExecutor);
if (ResponseType.QUERY == queryExecutor.getResponseType()) {
context.write(new PostgreSQLCommandCompletePacket(PostgreSQLCommand.SELECT.name(), dataRows));
}
- context.write(backendConnection.getConnectionSession().getTransactionStatus().isInTransaction() ? PostgreSQLReadyForQueryPacket.IN_TRANSACTION
+ context.write(databaseConnectionManager.getConnectionSession().getTransactionStatus().isInTransaction() ? PostgreSQLReadyForQueryPacket.IN_TRANSACTION
: PostgreSQLReadyForQueryPacket.NOT_IN_TRANSACTION);
}
- private long writeDataPackets(final ChannelHandlerContext context, final BackendConnection backendConnection, final QueryCommandExecutor queryCommandExecutor) throws SQLException {
+ private long writeDataPackets(final ChannelHandlerContext context, final ProxyDatabaseConnectionManager databaseConnectionManager,
+ final QueryCommandExecutor queryCommandExecutor) throws SQLException {
long dataRows = 0;
int flushCount = 0;
int proxyFrontendFlushThreshold = ProxyContext.getInstance()
@@ -108,7 +110,7 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
flushCount++;
while (!context.channel().isWritable() && context.channel().isActive()) {
context.flush();
- backendConnection.getResourceLock().doAwait();
+ databaseConnectionManager.getResourceLock().doAwait();
}
DatabasePacket<?> resultValue = queryCommandExecutor.getQueryRowPacket();
context.write(resultValue);
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java
index 964ecdc998e..2dfe7f27377 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/Portal.java
@@ -36,7 +36,7 @@ import org.apache.shardingsphere.infra.binder.aware.ParameterAware;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandlerFactory;
@@ -74,25 +74,25 @@ public final class Portal {
private final ProxyBackendHandler proxyBackendHandler;
- private final BackendConnection backendConnection;
+ private final ProxyDatabaseConnectionManager databaseConnectionManager;
private ResponseHeader responseHeader;
public Portal(final String name, final PostgreSQLServerPreparedStatement preparedStatement, final List<Object> params, final List<PostgreSQLValueFormat> resultFormats,
- final BackendConnection backendConnection) throws SQLException {
+ final ProxyDatabaseConnectionManager databaseConnectionManager) throws SQLException {
this.name = name;
this.sqlStatement = preparedStatement.getSqlStatementContext().getSqlStatement();
this.resultFormats = resultFormats;
- this.backendConnection = backendConnection;
- String databaseName = backendConnection.getConnectionSession().getDefaultDatabaseName();
+ this.databaseConnectionManager = databaseConnectionManager;
+ String databaseName = databaseConnectionManager.getConnectionSession().getDefaultDatabaseName();
SQLStatementContext<?> sqlStatementContext = preparedStatement.getSqlStatementContext();
if (sqlStatementContext instanceof ParameterAware) {
((ParameterAware) sqlStatementContext).setUpParameters(params);
}
DatabaseType protocolType = ProxyContext.getInstance().getDatabase(databaseName).getProtocolType();
QueryContext queryContext = new QueryContext(sqlStatementContext, preparedStatement.getSql(), params, new HintValueContext(), true);
- backendConnection.getConnectionSession().setQueryContext(queryContext);
- proxyBackendHandler = ProxyBackendHandlerFactory.newInstance(protocolType, queryContext, backendConnection.getConnectionSession(), true);
+ databaseConnectionManager.getConnectionSession().setQueryContext(queryContext);
+ proxyBackendHandler = ProxyBackendHandlerFactory.newInstance(protocolType, queryContext, databaseConnectionManager.getConnectionSession(), true);
}
/**
@@ -204,7 +204,7 @@ public final class Portal {
}
private void suspendPortal() {
- backendConnection.markResourceInUse(proxyBackendHandler);
+ databaseConnectionManager.markResourceInUse(proxyBackendHandler);
}
private long getUpdateCount() {
@@ -217,7 +217,7 @@ public final class Portal {
* @throws SQLException SQL exception
*/
public void close() throws SQLException {
- backendConnection.unmarkResourceInUse(proxyBackendHandler);
+ databaseConnectionManager.unmarkResourceInUse(proxyBackendHandler);
proxyBackendHandler.close();
}
}
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
index 0adc7ccc5b0..cab56af4d83 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java
@@ -140,7 +140,7 @@ public final class PostgreSQLBatchedStatementsExecutor {
* @throws SQLException SQL exception
*/
public int executeBatch() throws SQLException {
- connectionSession.getBackendConnection().handleAutoCommit();
+ connectionSession.getDatabaseConnectionManager().handleAutoCommit();
addBatchedParametersToPreparedStatements();
return executeBatchedPreparedStatements();
}
@@ -149,7 +149,7 @@ public final class PostgreSQLBatchedStatementsExecutor {
Collection<ShardingSphereRule> rules = metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getRuleMetaData().getRules();
DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine = new DriverExecutionPrepareEngine<>(JDBCDriverType.PREPARED_STATEMENT,
metaDataContexts.getMetaData().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY),
- connectionSession.getBackendConnection(), (JDBCBackendStatement) connectionSession.getStatementManager(),
+ connectionSession.getDatabaseConnectionManager(), (JDBCBackendStatement) connectionSession.getStatementManager(),
new StatementOption(false), rules, metaDataContexts.getMetaData().getDatabase(connectionSession.getDatabaseName()).getResourceMetaData().getStorageTypes());
executionGroupContext = prepareEngine.prepare(anyExecutionContext.getRouteContext(), executionUnitParams.keySet(),
new ExecutionGroupReportContext(connectionSession.getProcessId(), connectionSession.getDatabaseName(), connectionSession.getGrantee()));
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java
index b61f7141b69..4a308774cfe 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutor.java
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.proxy.frontend.postgresql.command.query.extended.PostgreSQLServerPreparedStatement;
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.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
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.PortalContext;
@@ -47,8 +47,8 @@ public final class PostgreSQLComBindExecutor implements CommandExecutor {
@Override
public Collection<DatabasePacket<?>> execute() throws SQLException {
PostgreSQLServerPreparedStatement preparedStatement = connectionSession.getServerPreparedStatementRegistry().getPreparedStatement(packet.getStatementId());
- BackendConnection backendConnection = connectionSession.getBackendConnection();
- Portal portal = new Portal(packet.getPortal(), preparedStatement, packet.readParameters(preparedStatement.getParameterTypes()), packet.readResultFormats(), backendConnection);
+ ProxyDatabaseConnectionManager databaseConnectionManager = connectionSession.getDatabaseConnectionManager();
+ Portal portal = new Portal(packet.getPortal(), preparedStatement, packet.readParameters(preparedStatement.getParameterTypes()), packet.readResultFormats(), databaseConnectionManager);
portalContext.add(portal);
portal.bind();
return Collections.singletonList(PostgreSQLBindCompletePacket.getInstance());
diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
index 819cc047260..c594ba6f2e3 100644
--- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
+++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutor.java
@@ -40,7 +40,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSp
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
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;
@@ -245,8 +245,8 @@ public final class PostgreSQLComDescribeExecutor implements CommandExecutor {
ExecutionContext executionContext = new KernelProcessor().generateExecutionContext(
queryContext, database, metaDataContexts.getMetaData().getGlobalRuleMetaData(), metaDataContexts.getMetaData().getProps(), connectionSession.getConnectionContext());
ExecutionUnit executionUnitSample = executionContext.getExecutionUnits().iterator().next();
- BackendConnection backendConnection = connectionSession.getBackendConnection();
- Connection connection = backendConnection.getConnections(executionUnitSample.getDataSourceName(), 1, ConnectionMode.CONNECTION_STRICTLY).iterator().next();
+ ProxyDatabaseConnectionManager databaseConnectionManager = connectionSession.getDatabaseConnectionManager();
+ Connection connection = databaseConnectionManager.getConnections(executionUnitSample.getDataSourceName(), 1, ConnectionMode.CONNECTION_STRICTLY).iterator().next();
try (PreparedStatement actualPreparedStatement = connection.prepareStatement(executionUnitSample.getSqlUnit().getSql())) {
populateParameterTypes(logicPreparedStatement, actualPreparedStatement);
populateColumnTypes(logicPreparedStatement, actualPreparedStatement);
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
index 47b38a6efcb..c835b3d34b0 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.metadata.persist.MetaDataPersistService;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.connection.ResourceLock;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -81,9 +81,9 @@ class PostgreSQLCommandExecuteEngineTest {
PostgreSQLComQueryExecutor comQueryExecutor = mock(PostgreSQLComQueryExecutor.class);
when(comQueryExecutor.getResponseType()).thenReturn(ResponseType.UPDATE);
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
- commandExecuteEngine.writeQueryData(channelHandlerContext, backendConnection, comQueryExecutor, 0);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
+ commandExecuteEngine.writeQueryData(channelHandlerContext, databaseConnectionManager, comQueryExecutor, 0);
verify(channelHandlerContext).write(any(PostgreSQLReadyForQueryPacket.class));
}
@@ -91,9 +91,9 @@ class PostgreSQLCommandExecuteEngineTest {
void assertWriteQueryDataWithUpdate() throws SQLException {
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
when(queryCommandExecutor.getResponseType()).thenReturn(ResponseType.UPDATE);
- BackendConnection backendConnection = mock(BackendConnection.class, RETURNS_DEEP_STUBS);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
- commandExecuteEngine.writeQueryData(channelHandlerContext, backendConnection, queryCommandExecutor, 0);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class, RETURNS_DEEP_STUBS);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
+ commandExecuteEngine.writeQueryData(channelHandlerContext, databaseConnectionManager, queryCommandExecutor, 0);
verify(channelHandlerContext).write(PostgreSQLReadyForQueryPacket.NOT_IN_TRANSACTION);
}
@@ -102,7 +102,7 @@ class PostgreSQLCommandExecuteEngineTest {
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
when(queryCommandExecutor.getResponseType()).thenReturn(ResponseType.QUERY);
when(channel.isActive()).thenReturn(false);
- commandExecuteEngine.writeQueryData(channelHandlerContext, mock(BackendConnection.class), queryCommandExecutor, 0);
+ commandExecuteEngine.writeQueryData(channelHandlerContext, mock(ProxyDatabaseConnectionManager.class), queryCommandExecutor, 0);
verify(channelHandlerContext).write(isA(PostgreSQLCommandCompletePacket.class));
}
@@ -114,15 +114,15 @@ class PostgreSQLCommandExecuteEngineTest {
when(queryCommandExecutor.next()).thenReturn(true, false);
when(channel.isWritable()).thenReturn(false, true);
ResourceLock resourceLock = mock(ResourceLock.class);
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(backendConnection.getResourceLock()).thenReturn(resourceLock);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(databaseConnectionManager.getResourceLock()).thenReturn(resourceLock);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
PostgreSQLPacket packet = mock(PostgreSQLPacket.class);
when(queryCommandExecutor.getQueryRowPacket()).thenReturn(packet);
PostgreSQLCommandExecuteEngine commandExecuteEngine = new PostgreSQLCommandExecuteEngine();
ContextManager contextManager = new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class), new ShardingSphereMetaData()), mock(InstanceContext.class));
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
- commandExecuteEngine.writeQueryData(channelHandlerContext, backendConnection, queryCommandExecutor, 0);
+ commandExecuteEngine.writeQueryData(channelHandlerContext, databaseConnectionManager, queryCommandExecutor, 0);
verify(resourceLock).doAwait();
verify(channelHandlerContext).write(packet);
verify(channelHandlerContext).write(isA(PostgreSQLCommandCompletePacket.class));
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
index 76e32ac8b05..fe507abccf8 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
@@ -38,7 +38,7 @@ import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.reflection.ReflectionUtils;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandlerFactory;
@@ -98,7 +98,7 @@ class PortalTest {
private ProxyBackendHandler proxyBackendHandler;
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@BeforeEach
void setup() throws SQLException {
@@ -111,7 +111,7 @@ class PortalTest {
when(ProxyBackendHandlerFactory.newInstance(any(PostgreSQLDatabaseType.class), anyString(), any(SQLStatement.class), eq(connectionSession), any(HintValueContext.class)))
.thenReturn(proxyBackendHandler);
when(ProxyBackendHandlerFactory.newInstance(any(PostgreSQLDatabaseType.class), any(QueryContext.class), eq(connectionSession), anyBoolean())).thenReturn(proxyBackendHandler);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
}
private ContextManager mockContextManager() {
@@ -130,7 +130,7 @@ class PortalTest {
@Test
void assertGetName() throws SQLException {
Portal portal = new Portal("", new PostgreSQLServerPreparedStatement("",
- new CommonSQLStatementContext<>(new PostgreSQLEmptyStatement()), Collections.emptyList()), Collections.emptyList(), Collections.emptyList(), backendConnection);
+ new CommonSQLStatementContext<>(new PostgreSQLEmptyStatement()), Collections.emptyList()), Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
assertThat(portal.getName(), is(""));
}
@@ -149,7 +149,7 @@ class PortalTest {
PostgreSQLServerPreparedStatement preparedStatement =
new PostgreSQLServerPreparedStatement("", sqlStatementContext, Collections.emptyList());
List<PostgreSQLValueFormat> resultFormats = new ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT, PostgreSQLValueFormat.BINARY));
- Portal portal = new Portal("", preparedStatement, Collections.emptyList(), resultFormats, backendConnection);
+ Portal portal = new Portal("", preparedStatement, Collections.emptyList(), resultFormats, databaseConnectionManager);
portal.bind();
PostgreSQLPacket portalDescription = portal.describe();
assertThat(portalDescription, instanceOf(PostgreSQLRowDescriptionPacket.class));
@@ -182,7 +182,7 @@ class PortalTest {
when(selectStatementContext.getSqlStatement()).thenReturn(new PostgreSQLSelectStatement());
PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", selectStatementContext, Collections.emptyList());
List<PostgreSQLValueFormat> resultFormats = new ArrayList<>(Arrays.asList(PostgreSQLValueFormat.TEXT, PostgreSQLValueFormat.BINARY));
- Portal portal = new Portal("", preparedStatement, Collections.emptyList(), resultFormats, backendConnection);
+ Portal portal = new Portal("", preparedStatement, Collections.emptyList(), resultFormats, databaseConnectionManager);
portal.bind();
assertThat(portal.describe(), instanceOf(PostgreSQLRowDescriptionPacket.class));
List<PostgreSQLPacket> actualPackets = portal.execute(2);
@@ -200,7 +200,7 @@ class PortalTest {
InsertStatementContext insertStatementContext = mock(InsertStatementContext.class, RETURNS_DEEP_STUBS);
when(insertStatementContext.getSqlStatement()).thenReturn(new PostgreSQLInsertStatement());
PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", insertStatementContext, Collections.emptyList());
- Portal portal = new Portal("insert into t values (1)", preparedStatement, Collections.emptyList(), Collections.emptyList(), backendConnection);
+ Portal portal = new Portal("insert into t values (1)", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
portal.bind();
assertThat(portal.describe(), is(PostgreSQLNoDataPacket.getInstance()));
List<PostgreSQLPacket> actualPackets = portal.execute(0);
@@ -212,7 +212,7 @@ class PortalTest {
when(proxyBackendHandler.execute()).thenReturn(mock(UpdateResponseHeader.class));
when(proxyBackendHandler.next()).thenReturn(false);
PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", new CommonSQLStatementContext<>(new PostgreSQLEmptyStatement()), Collections.emptyList());
- Portal portal = new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), backendConnection);
+ Portal portal = new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
portal.bind();
assertThat(portal.describe(), is(PostgreSQLNoDataPacket.getInstance()));
List<PostgreSQLPacket> actualPackets = portal.execute(0);
@@ -229,7 +229,7 @@ class PortalTest {
variableAssignSegment.setVariable(new VariableSegment(0, 0, "client_encoding"));
setStatement.getVariableAssigns().add(variableAssignSegment);
PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement(sql, new CommonSQLStatementContext<>(setStatement), Collections.emptyList());
- Portal portal = new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), backendConnection);
+ Portal portal = new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager);
portal.bind();
List<PostgreSQLPacket> actualPackets = portal.execute(0);
assertThat(actualPackets.size(), is(2));
@@ -242,14 +242,14 @@ class PortalTest {
void assertDescribeBeforeBind() {
PostgreSQLServerPreparedStatement preparedStatement = mock(PostgreSQLServerPreparedStatement.class);
when(preparedStatement.getSqlStatementContext()).thenReturn(mock(SQLStatementContext.class));
- assertThrows(IllegalStateException.class, () -> new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), backendConnection).describe());
+ assertThrows(IllegalStateException.class, () -> new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager).describe());
}
@Test
void assertClose() throws SQLException {
PostgreSQLServerPreparedStatement preparedStatement = new PostgreSQLServerPreparedStatement("", new CommonSQLStatementContext<>(new PostgreSQLEmptyStatement()), Collections.emptyList());
- new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), backendConnection).close();
- verify(backendConnection).unmarkResourceInUse(proxyBackendHandler);
+ new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager).close();
+ verify(databaseConnectionManager).unmarkResourceInUse(proxyBackendHandler);
verify(proxyBackendHandler).close();
}
}
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
index 2c77ad18144..68c883fe0b7 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
@@ -41,7 +41,7 @@ import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -115,17 +115,17 @@ class PostgreSQLAggregatedBatchedStatementsCommandExecutorTest {
result.getServerPreparedStatementRegistry().addPreparedStatement(STATEMENT_ID,
new PostgreSQLServerPreparedStatement(SQL, sqlStatementContext, Collections.singletonList(PostgreSQLColumnType.POSTGRESQL_TYPE_INT4)));
when(result.getConnectionId()).thenReturn(CONNECTION_ID);
- BackendConnection backendConnection = mock(BackendConnection.class);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getURL()).thenReturn("jdbc:postgresql://127.0.0.1/db");
- when(backendConnection.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
+ when(databaseConnectionManager.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
PreparedStatement preparedStatement = mock(PreparedStatement.class);
when(preparedStatement.getConnection()).thenReturn(connection);
JDBCBackendStatement backendStatement = mock(JDBCBackendStatement.class);
when(backendStatement.createStorageResource(any(ExecutionUnit.class), any(Connection.class), any(ConnectionMode.class), any(StatementOption.class), nullable(DatabaseType.class)))
.thenReturn(preparedStatement);
when(result.getStatementManager()).thenReturn(backendStatement);
- when(result.getBackendConnection()).thenReturn(backendConnection);
+ when(result.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
return result;
}
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java
index 090e8287302..d99662b2552 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java
@@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRule
import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.connector.jdbc.statement.JDBCBackendStatement;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -75,7 +75,7 @@ import static org.mockito.Mockito.when;
class PostgreSQLBatchedStatementsExecutorTest {
@Mock
- private BackendConnection backendConnection;
+ private ProxyDatabaseConnectionManager databaseConnectionManager;
@Mock
private JDBCBackendStatement backendStatement;
@@ -84,7 +84,7 @@ class PostgreSQLBatchedStatementsExecutorTest {
void assertExecuteBatch() throws SQLException {
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
when(connection.getMetaData().getURL()).thenReturn("jdbc:postgresql://127.0.0.1/db");
- when(backendConnection.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
+ when(databaseConnectionManager.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
PreparedStatement preparedStatement = mock(PreparedStatement.class);
when(preparedStatement.getConnection()).thenReturn(connection);
when(preparedStatement.executeBatch()).thenReturn(new int[]{1, 1, 1});
@@ -136,7 +136,7 @@ class PostgreSQLBatchedStatementsExecutorTest {
private ConnectionSession mockConnectionSession() {
ConnectionSession result = mock(ConnectionSession.class);
when(result.getDatabaseName()).thenReturn("db");
- when(result.getBackendConnection()).thenReturn(backendConnection);
+ when(result.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
when(result.getStatementManager()).thenReturn(backendStatement);
when(result.getConnectionContext()).thenReturn(new ConnectionContext());
return result;
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
index e3b32887293..392a57e4d3a 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/bind/PostgreSQLComBindExecutorTest.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContex
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
@@ -75,10 +75,10 @@ class PostgreSQLComBindExecutorTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
when(database.getProtocolType()).thenReturn(new PostgreSQLDatabaseType());
when(connectionSession.getServerPreparedStatementRegistry()).thenReturn(new ServerPreparedStatementRegistry());
- BackendConnection backendConnection = mock(BackendConnection.class);
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
when(connectionSession.getDefaultDatabaseName()).thenReturn(databaseName);
- when(backendConnection.getConnectionSession()).thenReturn(connectionSession);
+ when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
String statementId = "S_1";
connectionSession.getServerPreparedStatementRegistry().addPreparedStatement(statementId,
new PostgreSQLServerPreparedStatement("", new CommonSQLStatementContext<>(new PostgreSQLEmptyStatement()), Collections.emptyList()));
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
index 1b7baa7f31b..1914e020f22 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/describe/PostgreSQLComDescribeExecutorTest.java
@@ -43,7 +43,7 @@ import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.
import org.apache.shardingsphere.logging.rule.LoggingRule;
import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.connector.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.session.ServerPreparedStatementRegistry;
@@ -390,15 +390,15 @@ class PostgreSQLComDescribeExecutorTest {
}
private void prepareJDBCBackendConnection(final String sql) throws SQLException {
- BackendConnection backendConnection = mock(BackendConnection.class);
+ ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class);
Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
ParameterMetaData parameterMetaData = mock(ParameterMetaData.class);
when(parameterMetaData.getParameterType(1)).thenReturn(Types.INTEGER);
when(connection.prepareStatement(sql).getParameterMetaData()).thenReturn(parameterMetaData);
ResultSetMetaData resultSetMetaData = prepareResultSetMetaData();
when(connection.prepareStatement(sql).getMetaData()).thenReturn(resultSetMetaData);
- when(backendConnection.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
- when(connectionSession.getBackendConnection()).thenReturn(backendConnection);
+ when(databaseConnectionManager.getConnections(nullable(String.class), anyInt(), any(ConnectionMode.class))).thenReturn(Collections.singletonList(connection));
+ when(connectionSession.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager);
}
private ResultSetMetaData prepareResultSetMetaData() throws SQLException {