From e9b1ca38e8f42cf32784e21203145a1c493d288a Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 26 May 2024 11:32:24 +0800 Subject: [PATCH] Refactor AbstractUnsupportedOperationStatement --- .../statement/ShardingSphereStatement.java | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) 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 b20796d7a1e7a..58905a7565a09 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 @@ -180,8 +180,6 @@ public ResultSet executeQuery(final String sql) throws SQLException { // CHECKSTYLE:ON handleExceptionInTransaction(connection, metaDataContexts); throw SQLExceptionTransformEngine.toSQLException(ex, metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType()); - } finally { - currentResultSet = null; } currentResultSet = result; return result; @@ -420,32 +418,29 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE } private boolean execute0(final String sql, final ExecuteCallback executeCallback, final TrafficExecutorCallback trafficCallback) throws SQLException { - try { - QueryContext queryContext = createQueryContext(sql); - handleAutoCommit(queryContext); - databaseName = queryContext.getDatabaseNameFromSQLStatement().orElse(connection.getDatabaseName()); - connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName); - String trafficInstanceId = getInstanceIdAndSet(queryContext).orElse(null); - if (null != trafficInstanceId) { - JDBCExecutionUnit executionUnit = createTrafficExecutionUnit(trafficInstanceId, queryContext); - boolean result = executor.getTrafficExecutor().execute(executionUnit, trafficCallback); - currentResultSet = executor.getTrafficExecutor().getResultSet(); - return result; - } - if (decide(queryContext, metaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getGlobalRuleMetaData())) { - ResultSet resultSet = executeFederationQuery(queryContext); - currentResultSet = resultSet; - return null != resultSet; - } - executionContext = createExecutionContext(queryContext); - if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { - Collection results = executor.getRawExecutor().execute(createRawExecutionContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); - return results.iterator().next() instanceof QueryResult; - } - return executeWithExecutionContext(executeCallback, executionContext); - } finally { - currentResultSet = null; + QueryContext queryContext = createQueryContext(sql); + handleAutoCommit(queryContext); + databaseName = queryContext.getDatabaseNameFromSQLStatement().orElse(connection.getDatabaseName()); + connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabase(databaseName); + String trafficInstanceId = getInstanceIdAndSet(queryContext).orElse(null); + if (null != trafficInstanceId) { + JDBCExecutionUnit executionUnit = createTrafficExecutionUnit(trafficInstanceId, queryContext); + boolean result = executor.getTrafficExecutor().execute(executionUnit, trafficCallback); + currentResultSet = executor.getTrafficExecutor().getResultSet(); + return result; + } + if (decide(queryContext, metaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.getMetaData().getGlobalRuleMetaData())) { + ResultSet resultSet = executeFederationQuery(queryContext); + currentResultSet = resultSet; + return null != resultSet; + } + currentResultSet = null; + executionContext = createExecutionContext(queryContext); + if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { + Collection results = executor.getRawExecutor().execute(createRawExecutionContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); + return results.iterator().next() instanceof QueryResult; } + return executeWithExecutionContext(executeCallback, executionContext); } private void handleAutoCommit(final QueryContext queryContext) throws SQLException {