You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/09/23 03:57:35 UTC

[shardingsphere] branch master updated: Remove useless props copy with OriginalFederationExecutor (#12640)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 39d4a5c  Remove useless props copy with OriginalFederationExecutor (#12640)
39d4a5c is described below

commit 39d4a5c604c2705e84e2c82e4cf916a7c1ace852
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Sep 23 11:56:59 2021 +0800

    Remove useless props copy with OriginalFederationExecutor (#12640)
---
 .../execute/original/OriginalFederationExecutor.java     | 11 +----------
 .../jdbc/core/statement/ShardingSphereStatement.java     | 16 +++++++---------
 2 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/federate/execute/original/OriginalFederationExecutor.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/federate/execute/original/OriginalFederationExecutor.java
index 9500bb1..bc0cdd2 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/federate/execute/original/OriginalFederationExecutor.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/federate/execute/original/OriginalFederationExecutor.java
@@ -43,7 +43,6 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collections;
 import java.util.List;
-import java.util.Properties;
 
 /**
  * Original federation executor.
@@ -91,20 +90,12 @@ public final class OriginalFederationExecutor implements FederationExecutor {
     
     private Connection createConnection(final ExecutionContext executionContext, final JDBCExecutorCallback<? extends ExecuteResult> callback,
                                         final DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine) throws SQLException {
-        Connection result = DriverManager.getConnection(CONNECTION_URL, createProperties());
+        Connection result = DriverManager.getConnection(CONNECTION_URL, optimizerContext.getProps());
         CalciteConnection calciteConnection = result.unwrap(CalciteConnection.class);
         addSchema(calciteConnection, executionContext, callback, prepareEngine);
         return result;
     }
     
-    private Properties createProperties() {
-        Properties result = new Properties();
-        for (String each : optimizerContext.getProps().stringPropertyNames()) {
-            result.setProperty(each, optimizerContext.getProps().getProperty(each));
-        }
-        return result;
-    }
-    
     private void addSchema(final CalciteConnection calciteConnection, final ExecutionContext executionContext, final JDBCExecutorCallback<? extends ExecuteResult> callback, 
                            final DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> prepareEngine) throws SQLException {
         FederateRowExecutor executor = new FederateRowExecutor(props, jdbcExecutor, executionContext, callback, prepareEngine, optimizerContext.getDatabaseType().getQuoteCharacter());
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index 2d5ff68..f819c2b 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -146,7 +146,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
             executionContext = createExecutionContext(sql);
             List<QueryResult> queryResults = executeQuery0();
             MergedResult mergedResult = mergeQuery(queryResults);
-            result = new ShardingSphereResultSet(getResultSetsForShardingSphereResultSet(), mergedResult, this, executionContext);
+            result = new ShardingSphereResultSet(getShardingSphereResultSets(), mergedResult, this, executionContext);
         } finally {
             currentResultSet = null;
         }
@@ -154,11 +154,9 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
         return result;
     }
     
-    private List<ResultSet> getResultSetsForShardingSphereResultSet() throws SQLException {
-        if (executionContext.getRouteContext().isFederated()) {
-            return Collections.singletonList(federationExecutor.getResultSet());
-        }
-        return statements.stream().map(this::getResultSet).collect(Collectors.toList());
+    private List<ResultSet> getShardingSphereResultSets() throws SQLException {
+        return executionContext.getRouteContext().isFederated()
+                ? Collections.singletonList(federationExecutor.getResultSet()) : statements.stream().map(this::getResultSet).collect(Collectors.toList());
     }
     
     private List<QueryResult> executeQuery0() throws SQLException {
@@ -167,7 +165,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
                     new RawSQLExecutorCallback()).stream().map(each -> (QueryResult) each).collect(Collectors.toList());
         }
         if (executionContext.getRouteContext().isFederated()) {
-            return executeFederatedQuery();
+            return executeFederationQuery();
         }
         ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = createExecutionContext();
         cacheStatements(executionGroupContext.getInputGroups());
@@ -176,7 +174,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
         return driverJDBCExecutor.executeQuery(executionGroupContext, executionContext.getLogicSQL(), callback);
     }
     
-    private List<QueryResult> executeFederatedQuery() throws SQLException {
+    private List<QueryResult> executeFederationQuery() throws SQLException {
         if (executionContext.getExecutionUnits().isEmpty()) {
             return Collections.emptyList();
         }
@@ -340,7 +338,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
                 return results.iterator().next() instanceof QueryResult;
             }
             if (executionContext.getRouteContext().isFederated()) {
-                List<QueryResult> queryResults = executeFederatedQuery();
+                List<QueryResult> queryResults = executeFederationQuery();
                 return !queryResults.isEmpty();
             }
             ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = createExecutionContext();