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 d29bd3c66042f..2326ca199fdce 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 @@ -229,7 +229,7 @@ public ResultSet executeQuery() throws SQLException { currentResultSet = advancedResultSet.get(); return currentResultSet; } - executionContext = createExecutionContext(queryContext); + ExecutionContext executionContext = createExecutionContext(queryContext); currentResultSet = doExecuteQuery(executionContext); return currentResultSet; // CHECKSTYLE:OFF @@ -245,12 +245,12 @@ public ResultSet executeQuery() throws SQLException { private ShardingSphereResultSet doExecuteQuery(final ExecutionContext executionContext) throws SQLException { List queryResults = executeQuery0(executionContext); - MergedResult mergedResult = mergeQuery(queryResults, executionContext.getSqlStatementContext()); + MergedResult mergedResult = mergeQuery(queryResults, sqlStatementContext); List resultSets = getResultSets(); if (null == columnLabelAndIndexMap) { columnLabelAndIndexMap = ShardingSphereResultSetUtils.createColumnLabelAndIndexMap(sqlStatementContext, selectContainsEnhancedTable, resultSets.get(0).getMetaData()); } - return new ShardingSphereResultSet(resultSets, mergedResult, this, selectContainsEnhancedTable, executionContext.getSqlStatementContext(), columnLabelAndIndexMap); + return new ShardingSphereResultSet(resultSets, mergedResult, this, selectContainsEnhancedTable, sqlStatementContext, columnLabelAndIndexMap); } private List executeQuery0(final ExecutionContext executionContext) throws SQLException { @@ -303,7 +303,7 @@ public int executeUpdate() throws SQLException { if (updatedCount.isPresent()) { return updatedCount.get(); } - executionContext = createExecutionContext(queryContext); + ExecutionContext executionContext = createExecutionContext(queryContext); if (hasRawExecutionRule()) { Collection results = executor.getRawExecutor().execute(createRawExecutionGroupContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); @@ -368,7 +368,7 @@ public boolean execute() throws SQLException { if (advancedResult.isPresent()) { return advancedResult.get(); } - executionContext = createExecutionContext(queryContext); + ExecutionContext executionContext = createExecutionContext(queryContext); if (hasRawExecutionRule()) { Collection results = executor.getRawExecutor().execute(createRawExecutionGroupContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); @@ -386,13 +386,13 @@ public boolean execute() throws SQLException { } private boolean executeWithExecutionContext(final ExecutionContext executionContext) throws SQLException { - return isNeedImplicitCommitTransaction(connection, executionContext.getSqlStatementContext().getSqlStatement(), executionContext.getExecutionUnits().size() > 1) + return isNeedImplicitCommitTransaction(connection, sqlStatementContext.getSqlStatement(), executionContext.getExecutionUnits().size() > 1) ? executeWithImplicitCommitTransaction(() -> useDriverToExecute(executionContext), connection, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()) : useDriverToExecute(executionContext); } private int executeUpdateWithExecutionContext(final ExecutionContext executionContext) throws SQLException { - return isNeedImplicitCommitTransaction(connection, executionContext.getSqlStatementContext().getSqlStatement(), executionContext.getExecutionUnits().size() > 1) + return isNeedImplicitCommitTransaction(connection, sqlStatementContext.getSqlStatement(), executionContext.getExecutionUnits().size() > 1) ? executeWithImplicitCommitTransaction(() -> useDriverToExecuteUpdate(executionContext), connection, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()) : useDriverToExecuteUpdate(executionContext); } @@ -437,12 +437,11 @@ public ResultSet getResultSet() throws SQLException { if (advancedResultSet.isPresent()) { return advancedResultSet.get(); } - if (executionContext.getSqlStatementContext() instanceof SelectStatementContext || executionContext.getSqlStatementContext().getSqlStatement() instanceof DALStatement) { + if (sqlStatementContext instanceof SelectStatementContext || sqlStatementContext.getSqlStatement() instanceof DALStatement) { List resultSets = getResultSets(); if (resultSets.isEmpty()) { return currentResultSet; } - SQLStatementContext sqlStatementContext = executionContext.getSqlStatementContext(); MergedResult mergedResult = mergeQuery(getQueryResults(resultSets), sqlStatementContext); if (null == columnLabelAndIndexMap) { columnLabelAndIndexMap = ShardingSphereResultSetUtils.createColumnLabelAndIndexMap(sqlStatementContext, selectContainsEnhancedTable, resultSets.get(0).getMetaData()); @@ -478,7 +477,7 @@ private ExecutionContext createExecutionContext(final QueryContext queryContext) SQLAuditEngine.audit(queryContext.getSqlStatementContext(), queryContext.getParameters(), globalRuleMetaData, currentDatabase, null, queryContext.getHintValueContext()); ExecutionContext result = kernelProcessor.generateExecutionContext( queryContext, currentDatabase, globalRuleMetaData, metaDataContexts.getMetaData().getProps(), connection.getDatabaseConnectionManager().getConnectionContext()); - findGeneratedKey(result).ifPresent(optional -> generatedValues.addAll(optional.getGeneratedValues())); + findGeneratedKey().ifPresent(optional -> generatedValues.addAll(optional.getGeneratedValues())); return result; } @@ -537,10 +536,8 @@ private void clearPrevious() { generatedValues.clear(); } - private Optional findGeneratedKey(final ExecutionContext executionContext) { - return executionContext.getSqlStatementContext() instanceof InsertStatementContext - ? ((InsertStatementContext) executionContext.getSqlStatementContext()).getGeneratedKeyContext() - : Optional.empty(); + private Optional findGeneratedKey() { + return sqlStatementContext instanceof InsertStatementContext ? ((InsertStatementContext) sqlStatementContext).getGeneratedKeyContext() : Optional.empty(); } @Override @@ -548,7 +545,7 @@ public ResultSet getGeneratedKeys() throws SQLException { if (null != currentBatchGeneratedKeysResultSet) { return currentBatchGeneratedKeysResultSet; } - Optional generatedKey = findGeneratedKey(executionContext); + Optional generatedKey = findGeneratedKey(); if (generatedKey.isPresent() && statementOption.isReturnGeneratedKeys() && !generatedValues.isEmpty()) { return new GeneratedKeysResultSet(getGeneratedKeysColumnName(generatedKey.get().getColumnName()), generatedValues.iterator(), this); } @@ -599,7 +596,7 @@ public int[] executeBatch() throws SQLException { private int[] doExecuteBatch(final BatchPreparedStatementExecutor batchExecutor) throws SQLException { initBatchPreparedStatementExecutor(batchExecutor); - int[] result = batchExecutor.executeBatch(executionContext.getSqlStatementContext()); + int[] result = batchExecutor.executeBatch(sqlStatementContext); if (statementOption.isReturnGeneratedKeys() && generatedValues.isEmpty()) { List batchPreparedStatementExecutorStatements = batchExecutor.getStatements(); for (Statement statement : batchPreparedStatementExecutorStatements) { @@ -662,7 +659,7 @@ public int getResultSetHoldability() { @Override public boolean isAccumulate() { for (DataNodeRuleAttribute each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) { - if (each.isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames())) { + if (each.isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) { return true; } } 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 97f2d415b90fb..af0cbc3844598 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 @@ -116,9 +116,9 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter { private String databaseName; - private boolean returnGeneratedKeys; + private SQLStatementContext sqlStatementContext; - private ExecutionContext executionContext; + private boolean returnGeneratedKeys; private ResultSet currentResultSet; @@ -151,12 +151,13 @@ public ResultSet executeQuery(final String sql) throws SQLException { databaseName = queryContext.getDatabaseNameFromSQLStatement().orElse(connection.getDatabaseName()); connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName); ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(databaseName); + sqlStatementContext = queryContext.getSqlStatementContext(); Optional advancedResultSet = executor.executeAdvanceQuery(metaDataContexts.getMetaData(), database, queryContext, createDriverExecutionPrepareEngine(database)); if (advancedResultSet.isPresent()) { currentResultSet = advancedResultSet.get(); return currentResultSet; } - executionContext = createExecutionContext(queryContext); + ExecutionContext executionContext = createExecutionContext(queryContext); currentResultSet = doExecuteQuery(executionContext); return currentResultSet; // CHECKSTYLE:OFF @@ -170,10 +171,9 @@ public ResultSet executeQuery(final String sql) throws SQLException { private ShardingSphereResultSet doExecuteQuery(final ExecutionContext executionContext) throws SQLException { List queryResults = executeQuery0(executionContext); - MergedResult mergedResult = mergeQuery(queryResults, executionContext.getSqlStatementContext()); - boolean selectContainsEnhancedTable = - executionContext.getSqlStatementContext() instanceof SelectStatementContext && ((SelectStatementContext) executionContext.getSqlStatementContext()).isContainsEnhancedTable(); - return new ShardingSphereResultSet(getResultSets(), mergedResult, this, selectContainsEnhancedTable, executionContext.getSqlStatementContext()); + MergedResult mergedResult = mergeQuery(queryResults, sqlStatementContext); + boolean selectContainsEnhancedTable = sqlStatementContext instanceof SelectStatementContext && ((SelectStatementContext) sqlStatementContext).isContainsEnhancedTable(); + return new ShardingSphereResultSet(getResultSets(), mergedResult, this, selectContainsEnhancedTable, sqlStatementContext); } private List executeQuery0(final ExecutionContext executionContext) throws SQLException { @@ -184,7 +184,7 @@ private List executeQuery0(final ExecutionContext executionContext) ExecutionGroupContext executionGroupContext = createExecutionGroupContext(executionContext); cacheStatements(executionGroupContext.getInputGroups()); StatementExecuteQueryCallback callback = new StatementExecuteQueryCallback(metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType(), - metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData(), executionContext.getSqlStatementContext().getSqlStatement(), + metaDataContexts.getMetaData().getDatabase(databaseName).getResourceMetaData(), sqlStatementContext.getSqlStatement(), SQLExecutorExceptionHandler.isExceptionThrown()); return executor.getRegularExecutor().executeQuery(executionGroupContext, executionContext.getQueryContext(), callback); } @@ -262,7 +262,7 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ } private int executeUpdate(final ExecuteUpdateCallback updateCallback, final SQLStatementContext sqlStatementContext, final ExecutionContext executionContext) throws SQLException { - return isNeedImplicitCommitTransaction(connection, executionContext.getSqlStatementContext().getSqlStatement(), executionContext.getExecutionUnits().size() > 1) + return isNeedImplicitCommitTransaction(connection, sqlStatementContext.getSqlStatement(), executionContext.getExecutionUnits().size() > 1) ? executeWithImplicitCommitTransaction(() -> useDriverToExecuteUpdate(updateCallback, sqlStatementContext, executionContext), connection, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()) : useDriverToExecuteUpdate(updateCallback, sqlStatementContext, executionContext); @@ -274,25 +274,24 @@ private int executeUpdate0(final String sql, final ExecuteUpdateCallback updateC databaseName = queryContext.getDatabaseNameFromSQLStatement().orElse(connection.getDatabaseName()); connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName); ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(databaseName); + sqlStatementContext = queryContext.getSqlStatementContext(); Optional updatedCount = executor.executeAdvanceUpdate(metaDataContexts.getMetaData(), database, queryContext, createDriverExecutionPrepareEngine(database), trafficCallback); if (updatedCount.isPresent()) { return updatedCount.get(); } - executionContext = createExecutionContext(queryContext); + ExecutionContext executionContext = createExecutionContext(queryContext); if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { - Collection results = executor.getRawExecutor().execute(createRawExecutionGroupContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); + Collection results = executor.getRawExecutor().execute(createRawExecutionGroupContext(executionContext), queryContext, new RawSQLExecutorCallback()); return accumulate(results); } return executeUpdate(updateCallback, queryContext.getSqlStatementContext(), executionContext); } - private int useDriverToExecuteUpdate(final ExecuteUpdateCallback updateCallback, final SQLStatementContext sqlStatementContext, - final ExecutionContext executionContext) throws SQLException { + private int useDriverToExecuteUpdate(final ExecuteUpdateCallback updateCallback, final SQLStatementContext sqlStatementContext, final ExecutionContext executionContext) throws SQLException { ExecutionGroupContext executionGroupContext = createExecutionGroupContext(executionContext); cacheStatements(executionGroupContext.getInputGroups()); JDBCExecutorCallback callback = createExecuteUpdateCallback(updateCallback, sqlStatementContext); - return executor.getRegularExecutor().executeUpdate(executionGroupContext, - executionContext.getQueryContext(), executionContext.getRouteContext().getRouteUnits(), callback); + return executor.getRegularExecutor().executeUpdate(executionGroupContext, executionContext.getQueryContext(), executionContext.getRouteContext().getRouteUnits(), callback); } private JDBCExecutorCallback createExecuteUpdateCallback(final ExecuteUpdateCallback updateCallback, final SQLStatementContext sqlStatementContext) { @@ -380,13 +379,14 @@ private boolean execute0(final String sql, final ExecuteCallback executeCallback databaseName = queryContext.getDatabaseNameFromSQLStatement().orElse(connection.getDatabaseName()); connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName); ShardingSphereDatabase database = metaDataContexts.getMetaData().getDatabase(databaseName); + sqlStatementContext = queryContext.getSqlStatementContext(); Optional advancedResult = executor.executeAdvance(metaDataContexts.getMetaData(), database, queryContext, createDriverExecutionPrepareEngine(database), trafficCallback); if (advancedResult.isPresent()) { return advancedResult.get(); } - executionContext = createExecutionContext(queryContext); + ExecutionContext executionContext = createExecutionContext(queryContext); if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { - Collection results = executor.getRawExecutor().execute(createRawExecutionGroupContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); + Collection results = executor.getRawExecutor().execute(createRawExecutionGroupContext(executionContext), queryContext, new RawSQLExecutorCallback()); return results.iterator().next() instanceof QueryResult; } return executeWithExecutionContext(executeCallback, executionContext); @@ -452,7 +452,7 @@ private ExecutionGroupContext createRawExecutionGroupContex } private boolean executeWithExecutionContext(final ExecuteCallback executeCallback, final ExecutionContext executionContext) throws SQLException { - return isNeedImplicitCommitTransaction(connection, executionContext.getSqlStatementContext().getSqlStatement(), executionContext.getExecutionUnits().size() > 1) + return isNeedImplicitCommitTransaction(connection, sqlStatementContext.getSqlStatement(), executionContext.getExecutionUnits().size() > 1) ? executeWithImplicitCommitTransaction(() -> useDriverToExecute(executeCallback, executionContext), connection, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()) : useDriverToExecute(executeCallback, executionContext); @@ -461,7 +461,7 @@ private boolean executeWithExecutionContext(final ExecuteCallback executeCallbac private boolean useDriverToExecute(final ExecuteCallback callback, final ExecutionContext executionContext) throws SQLException { ExecutionGroupContext executionGroupContext = createExecutionGroupContext(executionContext); cacheStatements(executionGroupContext.getInputGroups()); - JDBCExecutorCallback jdbcExecutorCallback = createExecuteCallback(callback, executionContext.getSqlStatementContext().getSqlStatement()); + JDBCExecutorCallback jdbcExecutorCallback = createExecuteCallback(callback, sqlStatementContext.getSqlStatement()); return executor.getRegularExecutor().execute(executionGroupContext, executionContext.getQueryContext(), executionContext.getRouteContext().getRouteUnits(), jdbcExecutorCallback); } @@ -505,15 +505,14 @@ public ResultSet getResultSet() throws SQLException { if (advancedResultSet.isPresent()) { return advancedResultSet.get(); } - if (executionContext.getSqlStatementContext() instanceof SelectStatementContext || executionContext.getSqlStatementContext().getSqlStatement() instanceof DALStatement) { + if (sqlStatementContext instanceof SelectStatementContext || sqlStatementContext.getSqlStatement() instanceof DALStatement) { List resultSets = getResultSets(); if (resultSets.isEmpty()) { return currentResultSet; } - SQLStatementContext sqlStatementContext = executionContext.getSqlStatementContext(); MergedResult mergedResult = mergeQuery(getQueryResults(resultSets), sqlStatementContext); boolean selectContainsEnhancedTable = sqlStatementContext instanceof SelectStatementContext && ((SelectStatementContext) sqlStatementContext).isContainsEnhancedTable(); - currentResultSet = new ShardingSphereResultSet(resultSets, mergedResult, this, selectContainsEnhancedTable, executionContext.getSqlStatementContext()); + currentResultSet = new ShardingSphereResultSet(resultSets, mergedResult, this, selectContainsEnhancedTable, sqlStatementContext); } return currentResultSet; } @@ -564,7 +563,7 @@ public int getResultSetHoldability() { @Override public boolean isAccumulate() { for (DataNodeRuleAttribute each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) { - if (each.isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames())) { + if (each.isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) { return true; } } @@ -594,9 +593,7 @@ public ResultSet getGeneratedKeys() throws SQLException { } private Optional findGeneratedKey() { - return executionContext.getSqlStatementContext() instanceof InsertStatementContext - ? ((InsertStatementContext) executionContext.getSqlStatementContext()).getGeneratedKeyContext() - : Optional.empty(); + return sqlStatementContext instanceof InsertStatementContext ? ((InsertStatementContext) sqlStatementContext).getGeneratedKeyContext() : Optional.empty(); } private String getGeneratedKeysColumnName(final String columnName) { diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java index 4cdb3fa62e5d7..08f83bb98b800 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java @@ -20,10 +20,10 @@ import lombok.SneakyThrows; import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement; +import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; @@ -266,13 +266,12 @@ private ShardingSphereStatement mockShardingSphereStatementWithNeedAccumulate(fi when(connection.getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(new Properties())); ShardingSphereStatement result = new ShardingSphereStatement(connection); result.getRoutedStatements().addAll(Arrays.asList(statements)); - ExecutionContext executionContext = mock(ExecutionContext.class, RETURNS_DEEP_STUBS); - setExecutionContext(result, executionContext); + setExecutionContext(result); return result; } @SneakyThrows(ReflectiveOperationException.class) - private void setExecutionContext(final ShardingSphereStatement statement, final ExecutionContext executionContext) { - Plugins.getMemberAccessor().set(statement.getClass().getDeclaredField("executionContext"), statement, executionContext); + private void setExecutionContext(final ShardingSphereStatement statement) { + Plugins.getMemberAccessor().set(statement.getClass().getDeclaredField("sqlStatementContext"), statement, mock(SQLStatementContext.class)); } } 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 32dc87430d75d..eb5f97e7dbed0 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 @@ -169,7 +169,7 @@ public ResponseHeader execute() throws SQLException { return processExecuteFederation(resultSet, metaDataContexts); } ExecutionContext executionContext = generateExecutionContext(); - return isNeedImplicitCommitTransaction(executionContext.getSqlStatementContext().getSqlStatement(), executionContext.getExecutionUnits().size() > 1) + return isNeedImplicitCommitTransaction(queryContext.getSqlStatementContext().getSqlStatement(), executionContext.getExecutionUnits().size() > 1) ? doExecuteWithImplicitCommitTransaction(() -> doExecute(executionContext)) : doExecute(executionContext); } @@ -216,14 +216,13 @@ private T doExecuteWithImplicitCommitTransaction(final ImplicitTransactionCa @SuppressWarnings({"unchecked", "rawtypes"}) private ResponseHeader doExecute(final ExecutionContext executionContext) throws SQLException { if (executionContext.getExecutionUnits().isEmpty()) { - return new UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement()); + return new UpdateResponseHeader(queryContext.getSqlStatementContext().getSqlStatement()); } proxySQLExecutor.checkExecutePrerequisites(executionContext); List result = proxySQLExecutor.execute(executionContext); refreshMetaData(executionContext); Object executeResultSample = result.iterator().next(); - return executeResultSample instanceof QueryResult ? processExecuteQuery(queryContext.getSqlStatementContext(), result, (QueryResult) executeResultSample) - : processExecuteUpdate(executionContext, result); + return executeResultSample instanceof QueryResult ? processExecuteQuery(queryContext.getSqlStatementContext(), result, (QueryResult) executeResultSample) : processExecuteUpdate(result); } private ResultSet doExecuteFederation(final QueryContext queryContext, final MetaDataContexts metaDataContexts) { @@ -284,7 +283,7 @@ private void prepareCursorStatementContext(final CursorAvailable statementContex private void refreshMetaData(final ExecutionContext executionContext) throws SQLException { ContextManager contextManager = ProxyContext.getInstance().getContextManager(); new MetaDataRefreshEngine(contextManager.getPersistServiceFacade().getMetaDataManagerPersistService(), database, - contextManager.getMetaDataContexts().getMetaData().getProps()).refresh(executionContext.getSqlStatementContext(), executionContext.getRouteContext().getRouteUnits()); + contextManager.getMetaDataContexts().getMetaData().getProps()).refresh(queryContext.getSqlStatementContext(), executionContext.getRouteContext().getRouteUnits()); } private QueryResponseHeader processExecuteQuery(final SQLStatementContext sqlStatementContext, final List queryResults, final QueryResult queryResultSample) throws SQLException { @@ -326,14 +325,14 @@ private MergedResult mergeQuery(final SQLStatementContext sqlStatementContext, f return mergeEngine.merge(queryResults, sqlStatementContext); } - private UpdateResponseHeader processExecuteUpdate(final ExecutionContext executionContext, final Collection updateResults) { - Optional generatedKeyContext = executionContext.getSqlStatementContext() instanceof InsertStatementContext - ? ((InsertStatementContext) executionContext.getSqlStatementContext()).getGeneratedKeyContext() + private UpdateResponseHeader processExecuteUpdate(final Collection updateResults) { + Optional generatedKeyContext = queryContext.getSqlStatementContext() instanceof InsertStatementContext + ? ((InsertStatementContext) queryContext.getSqlStatementContext()).getGeneratedKeyContext() : Optional.empty(); Collection> autoIncrementGeneratedValues = generatedKeyContext.filter(GeneratedKeyContext::isSupportAutoIncrement).map(GeneratedKeyContext::getGeneratedValues).orElseGet(Collections::emptyList); - UpdateResponseHeader result = new UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement(), updateResults, autoIncrementGeneratedValues); - mergeUpdateCount(executionContext.getSqlStatementContext(), result); + UpdateResponseHeader result = new UpdateResponseHeader(queryContext.getSqlStatementContext().getSqlStatement(), updateResults, autoIncrementGeneratedValues); + mergeUpdateCount(queryContext.getSqlStatementContext(), result); return result; }