From 525e0f0741e7b863e8367569f98b691a6f661a1f Mon Sep 17 00:00:00 2001 From: zhangliang Date: Fri, 31 May 2024 20:54:39 +0800 Subject: [PATCH] Move execute to DriverExecutor --- .../shardingsphere/driver/executor/DriverExecutor.java | 10 +++++----- .../statement/ShardingSpherePreparedStatement.java | 2 +- .../jdbc/core/statement/ShardingSphereStatement.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java index f2d5c361b1094..a593f2594c4d9 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverExecutor.java @@ -365,14 +365,15 @@ private int accumulate(final Collection results) { * @param isNeedImplicitCommitTransaction is need implicit commit transaction * @param executeCallback execute callback * @param statementReplayCallback statement replay callback + * @param executionContext execution context * @return execute result * @throws SQLException SQL exception */ @SuppressWarnings("rawtypes") public boolean executeAdvance(final ShardingSphereMetaData metaData, final ShardingSphereDatabase database, - final QueryContext queryContext, final DriverExecutionPrepareEngine prepareEngine, - final TrafficExecutorCallback trafficCallback, final boolean isNeedImplicitCommitTransaction, - final ExecuteCallback executeCallback, final StatementReplayCallback statementReplayCallback) throws SQLException { + final QueryContext queryContext, final DriverExecutionPrepareEngine prepareEngine, + final TrafficExecutorCallback trafficCallback, final boolean isNeedImplicitCommitTransaction, + final ExecuteCallback executeCallback, final StatementReplayCallback statementReplayCallback, final ExecutionContext executionContext) throws SQLException { Optional trafficInstanceId = connection.getTrafficInstanceId(metaData.getGlobalRuleMetaData().getSingleRule(TrafficRule.class), queryContext); if (trafficInstanceId.isPresent()) { executeType = ExecuteType.TRAFFIC; @@ -384,7 +385,6 @@ public boolean executeAdvance(final ShardingSphereMetaData metaData, final Shard prepareEngine, getExecuteQueryCallback(database, queryContext, prepareEngine.getType()), new SQLFederationContext(false, queryContext, metaData, connection.getProcessId())); return null != resultSet; } - ExecutionContext executionContext = createExecutionContext(metaData, database, queryContext); if (!database.getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { Collection results = rawExecutor.execute(createRawExecutionGroupContext(metaData, database, executionContext), queryContext, new RawSQLExecutorCallback()); return results.iterator().next() instanceof QueryResult; @@ -398,7 +398,7 @@ private boolean executeWithExecutionContext(final ShardingSphereDatabase databas final boolean isNeedImplicitCommitTransaction, final StatementReplayCallback statementReplayCallback) throws SQLException { return isNeedImplicitCommitTransaction ? executeWithImplicitCommitTransaction(() -> useDriverToExecute(database, executeCallback, executionContext, prepareEngine, statementReplayCallback), connection, - database.getProtocolType()) + database.getProtocolType()) : useDriverToExecute(database, executeCallback, executionContext, prepareEngine, statementReplayCallback); } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java index 10f5c0bb3e9a8..0df4edd2b90a0 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java @@ -294,7 +294,7 @@ public boolean execute() throws SQLException { boolean isNeedImplicitCommitTransaction = isNeedImplicitCommitTransaction(connection, sqlStatementContext.getSqlStatement(), executionContext.getExecutionUnits().size() > 1); boolean result = executor.executeAdvance( metaDataContexts.getMetaData(), database, queryContext, createDriverExecutionPrepareEngine(database), (statement, sql) -> ((PreparedStatement) statement).execute(), - isNeedImplicitCommitTransaction, null, (StatementReplayCallback) this::replay); + isNeedImplicitCommitTransaction, null, (StatementReplayCallback) this::replay, executionContext); for (Statement each : executor.getStatements()) { statements.add((PreparedStatement) each); } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java index 88e9bfdaecc10..9fa5644fa45d9 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java @@ -298,7 +298,7 @@ private boolean execute0(final String sql, final ExecuteCallback executeCallback ExecutionContext executionContext = createExecutionContext(queryContext); boolean isNeedImplicitCommitTransaction = isNeedImplicitCommitTransaction(connection, sqlStatementContext.getSqlStatement(), executionContext.getExecutionUnits().size() > 1); boolean result = executor.executeAdvance(metaDataContexts.getMetaData(), database, queryContext, createDriverExecutionPrepareEngine(database), trafficCallback, - isNeedImplicitCommitTransaction, executeCallback, (StatementReplayCallback) (statements, parameterSets) -> replay(statements)); + isNeedImplicitCommitTransaction, executeCallback, (StatementReplayCallback) (statements, parameterSets) -> replay(statements), executionContext); statements.addAll(executor.getStatements()); return result; }