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

panjuan 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 b198e6a  Use callback instead of execute query (#8519)
b198e6a is described below

commit b198e6a99b80bc95e8322012bfbae9a45f26c787
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Dec 7 16:31:33 2020 +0800

    Use callback instead of execute query (#8519)
    
    * Refactor ProxyJDBCExecutorCallback
    
    * Refactor AbstractStatementExecutor
    
    * Add DriverJDBCExecutorCallback
    
    * Adjust param sequence for ProxyJDBCExecutorCallback
    
    * Adjust param sequence for Updater
    
    * Adjust param sequence for Executor
    
    * Add DriverStatementExecutorCallback and 
DriverPreparedStatementExecutorCallback
    
    * Rename JDBCExecuteQueryCallback
    
    * Use callback instead of execute query
---
 .../driver/executor/AbstractStatementExecutor.java | 58 +++++++---------
 .../driver/executor/PreparedStatementExecutor.java | 29 +-------
 .../driver/executor/StatementExecutor.java         | 48 ++++---------
 .../callback/JDBCExecuteQueryCallback.java         | 47 +++++++++++++
 .../PreparedStatementExecuteQueryCallback.java     | 41 +++++++++++
 .../impl/StatementExecuteQueryCallback.java        | 40 +++++++++++
 .../statement/ShardingSpherePreparedStatement.java | 17 +++--
 .../core/statement/ShardingSphereStatement.java    | 13 +++-
 .../executor/PreparedStatementExecutorTest.java    | 76 +--------------------
 .../driver/executor/StatementExecutorTest.java     | 79 +---------------------
 .../callback/ProxyJDBCExecutorCallback.java        | 12 ++--
 .../ProxyPreparedStatementExecutorCallback.java    |  2 +-
 .../impl/ProxyStatementExecutorCallback.java       |  2 +-
 13 files changed, 199 insertions(+), 265 deletions(-)

diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java
index 1257be2..8108498 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/AbstractStatementExecutor.java
@@ -26,7 +26,6 @@ import 
org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.schema.builder.SchemaBuilderMaterials;
@@ -52,8 +51,8 @@ import java.util.stream.Collectors;
 /**
  * Abstract statement executor.
  */
-@Getter
 @RequiredArgsConstructor
+@Getter
 public abstract class AbstractStatementExecutor {
     
     static {
@@ -66,6 +65,29 @@ public abstract class AbstractStatementExecutor {
     
     private final JDBCExecutor jdbcExecutor;
     
+    /**
+     * Execute update.
+     *
+     * @param executionGroups execution groups
+     * @param sqlStatementContext SQL statement context
+     * @param routeUnits route units
+     * @return effected records count
+     * @throws SQLException SQL exception
+     */
+    public abstract int 
executeUpdate(Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, 
+                                      SQLStatementContext<?> 
sqlStatementContext, Collection<RouteUnit> routeUnits) throws SQLException;
+    
+    /**
+     * Execute SQL.
+     *
+     * @param executionGroups execution groups
+     * @param sqlStatement SQL statement
+     * @param routeUnits route units
+     * @return return true if is DQL, false if is DML
+     * @throws SQLException SQL exception
+     */
+    public abstract boolean 
execute(Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, 
SQLStatement sqlStatement, Collection<RouteUnit> routeUnits) throws 
SQLException;
+    
     protected final boolean isNeedAccumulate(final 
Collection<ShardingSphereRule> rules, final SQLStatementContext<?> 
sqlStatementContext) {
         return rules.stream().anyMatch(each -> ((DataNodeContainedRule) 
each).isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()));
     }
@@ -98,36 +120,4 @@ public abstract class AbstractStatementExecutor {
         refreshSchema(metaDataContexts.getDefaultMetaData(), sqlStatement, 
routeUnits);
         return null != result && !result.isEmpty() && null != result.get(0) && 
result.get(0);
     }
-    
-    /**
-     * Execute SQL.
-     *
-     * @param executionGroups execution groups
-     * @param sqlStatement SQL statement
-     * @param routeUnits route units
-     * @return return true if is DQL, false if is DML
-     * @throws SQLException SQL exception
-     */
-    public abstract boolean 
execute(Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, 
SQLStatement sqlStatement, Collection<RouteUnit> routeUnits) throws 
SQLException;
-    
-    /**
-     * Execute query.
-     *
-     * @param executionGroups execution groups
-     * @return query results
-     * @throws SQLException SQL exception
-     */
-    public abstract List<QueryResult> 
executeQuery(Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups) 
throws SQLException;
-    
-    /**
-     * Execute update.
-     *
-     * @param executionGroups execution groups
-     * @param sqlStatementContext SQL statement context
-     * @param routeUnits route units
-     * @return effected records count
-     * @throws SQLException SQL exception
-     */
-    public abstract int 
executeUpdate(Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, 
-                                      SQLStatementContext<?> 
sqlStatementContext, Collection<RouteUnit> routeUnits) throws SQLException;
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutor.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutor.java
index 447c7cc..f3d791d 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutor.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutor.java
@@ -25,16 +25,12 @@ import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorEx
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.memory.JDBCMemoryQueryResult;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
 import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 
 import javax.sql.DataSource;
 import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collection;
@@ -52,29 +48,6 @@ public final class PreparedStatementExecutor extends 
AbstractStatementExecutor {
     }
     
     @Override
-    public List<QueryResult> executeQuery(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups) throws 
SQLException {
-        boolean isExceptionThrown = 
SQLExecutorExceptionHandler.isExceptionThrown();
-        JDBCExecutorCallback<QueryResult> callback = 
createJDBCExecutorCallbackWithQueryResult(isExceptionThrown);
-        return getJdbcExecutor().execute(executionGroups, callback);
-    }
-    
-    private JDBCExecutorCallback<QueryResult> 
createJDBCExecutorCallbackWithQueryResult(final boolean isExceptionThrown) {
-        return new 
JDBCExecutorCallback<QueryResult>(getMetaDataContexts().getDatabaseType(), 
isExceptionThrown) {
-            
-            @Override
-            protected QueryResult executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode) throws SQLException { 
-                return createQueryResult(statement, connectionMode);
-            }
-            
-            private QueryResult createQueryResult(final Statement statement, 
final ConnectionMode connectionMode) throws SQLException {
-                PreparedStatement preparedStatement = (PreparedStatement) 
statement;
-                ResultSet resultSet = preparedStatement.executeQuery();
-                return ConnectionMode.MEMORY_STRICTLY == connectionMode ? new 
JDBCStreamQueryResult(resultSet) : new JDBCMemoryQueryResult(resultSet);
-            }
-        };
-    }
-    
-    @Override
     public int executeUpdate(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, 
                              final SQLStatementContext<?> sqlStatementContext, 
final Collection<RouteUnit> routeUnits) throws SQLException {
         boolean isExceptionThrown = 
SQLExecutorExceptionHandler.isExceptionThrown();
@@ -104,7 +77,7 @@ public final class PreparedStatementExecutor extends 
AbstractStatementExecutor {
     
     private JDBCExecutorCallback<Boolean> 
createJDBCExecutorCallbackWithBoolean(final boolean isExceptionThrown) {
         return new 
JDBCExecutorCallback<Boolean>(getMetaDataContexts().getDatabaseType(), 
isExceptionThrown) {
-                    
+            
             @Override
             protected Boolean executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode) throws SQLException {
                 return ((PreparedStatement) statement).execute();
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/StatementExecutor.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/StatementExecutor.java
index 760378a..47b8f45 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/StatementExecutor.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/StatementExecutor.java
@@ -25,15 +25,11 @@ import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorEx
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.memory.JDBCMemoryQueryResult;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
 import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 
 import javax.sql.DataSource;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collection;
@@ -51,27 +47,9 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
     }
     
     @Override
-    public List<QueryResult> executeQuery(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups) throws 
SQLException {
-        boolean isExceptionThrown = 
SQLExecutorExceptionHandler.isExceptionThrown();
-        JDBCExecutorCallback<QueryResult> jdbcExecutorCallback = new 
JDBCExecutorCallback<QueryResult>(getMetaDataContexts().getDatabaseType(), 
isExceptionThrown) {
-            
-            @Override
-            protected QueryResult executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode) throws SQLException {
-                return createQueryResult(sql, statement, connectionMode);
-            }
-            
-            private QueryResult createQueryResult(final String sql, final 
Statement statement, final ConnectionMode connectionMode) throws SQLException {
-                ResultSet resultSet = statement.executeQuery(sql);
-                return ConnectionMode.MEMORY_STRICTLY == connectionMode ? new 
JDBCStreamQueryResult(resultSet) : new JDBCMemoryQueryResult(resultSet);
-            }
-        };
-        return getJdbcExecutor().execute(executionGroups, 
jdbcExecutorCallback);
-    }
-    
-    @Override
     public int executeUpdate(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, 
                              final SQLStatementContext<?> sqlStatementContext, 
final Collection<RouteUnit> routeUnits) throws SQLException {
-        return executeUpdate(executionGroups, Statement::executeUpdate, 
sqlStatementContext, routeUnits);
+        return executeUpdate(executionGroups, (sql, statement) -> 
statement.executeUpdate(sql), sqlStatementContext, routeUnits);
     }
     
     /**
@@ -86,7 +64,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
      */
     public int executeUpdate(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, final 
SQLStatementContext<?> sqlStatementContext,
                              final Collection<RouteUnit> routeUnits, final int 
autoGeneratedKeys) throws SQLException {
-        return executeUpdate(executionGroups, (statement, sql) -> 
statement.executeUpdate(sql, autoGeneratedKeys), sqlStatementContext, 
routeUnits);
+        return executeUpdate(executionGroups, (sql, statement) -> 
statement.executeUpdate(sql, autoGeneratedKeys), sqlStatementContext, 
routeUnits);
     }
     
     /**
@@ -101,7 +79,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
      */
     public int executeUpdate(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, final 
SQLStatementContext<?> sqlStatementContext,
                              final Collection<RouteUnit> routeUnits, final 
int[] columnIndexes) throws SQLException {
-        return executeUpdate(executionGroups, (statement, sql) -> 
statement.executeUpdate(sql, columnIndexes), sqlStatementContext, routeUnits);
+        return executeUpdate(executionGroups, (sql, statement) -> 
statement.executeUpdate(sql, columnIndexes), sqlStatementContext, routeUnits);
     }
     
     /**
@@ -116,7 +94,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
      */
     public int executeUpdate(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, final 
SQLStatementContext<?> sqlStatementContext,
                              final Collection<RouteUnit> routeUnits, final 
String[] columnNames) throws SQLException {
-        return executeUpdate(executionGroups, (statement, sql) -> 
statement.executeUpdate(sql, columnNames), sqlStatementContext, routeUnits);
+        return executeUpdate(executionGroups, (sql, statement) -> 
statement.executeUpdate(sql, columnNames), sqlStatementContext, routeUnits);
     }
     
     @SuppressWarnings({"unchecked", "rawtypes"})
@@ -127,7 +105,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
             
             @Override
             protected Integer executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode) throws SQLException {
-                return updater.executeUpdate(statement, sql);
+                return updater.executeUpdate(sql, statement);
             }
         };
         List<Integer> results = getJdbcExecutor().execute(executionGroups, 
jdbcExecutorCallback);
@@ -141,7 +119,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
     
     @Override
     public boolean execute(final Collection<ExecutionGroup<JDBCExecutionUnit>> 
executionGroups, final SQLStatement sqlStatement, final Collection<RouteUnit> 
routeUnits) throws SQLException {
-        return execute(executionGroups, Statement::execute, sqlStatement, 
routeUnits);
+        return execute(executionGroups, (sql, statement) -> 
statement.execute(sql), sqlStatement, routeUnits);
     }
     
     /**
@@ -156,7 +134,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
      */
     public boolean execute(final Collection<ExecutionGroup<JDBCExecutionUnit>> 
executionGroups, final SQLStatement sqlStatement,
                            final Collection<RouteUnit> routeUnits, final int 
autoGeneratedKeys) throws SQLException {
-        return execute(executionGroups, (statement, sql) -> 
statement.execute(sql, autoGeneratedKeys), sqlStatement, routeUnits);
+        return execute(executionGroups, (sql, statement) -> 
statement.execute(sql, autoGeneratedKeys), sqlStatement, routeUnits);
     }
     
     /**
@@ -171,7 +149,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
      */
     public boolean execute(final Collection<ExecutionGroup<JDBCExecutionUnit>> 
executionGroups, final SQLStatement sqlStatement,
                            final Collection<RouteUnit> routeUnits, final int[] 
columnIndexes) throws SQLException {
-        return execute(executionGroups, (statement, sql) -> 
statement.execute(sql, columnIndexes), sqlStatement, routeUnits);
+        return execute(executionGroups, (sql, statement) -> 
statement.execute(sql, columnIndexes), sqlStatement, routeUnits);
     }
     
     /**
@@ -186,10 +164,10 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
      */
     public boolean execute(final Collection<ExecutionGroup<JDBCExecutionUnit>> 
executionGroups, final SQLStatement sqlStatement,
                            final Collection<RouteUnit> routeUnits, final 
String[] columnNames) throws SQLException {
-        return execute(executionGroups, (statement, sql) -> 
statement.execute(sql, columnNames), sqlStatement, routeUnits);
+        return execute(executionGroups, (sql, statement) -> 
statement.execute(sql, columnNames), sqlStatement, routeUnits);
     }
     
-    @SuppressWarnings("rawtypes")
+    @SuppressWarnings({"rawtypes", "unchecked"})
     private boolean execute(final 
Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, final Executor 
executor,
                             final SQLStatement sqlStatement, final 
Collection<RouteUnit> routeUnits) throws SQLException {
         boolean isExceptionThrown = 
SQLExecutorExceptionHandler.isExceptionThrown();
@@ -197,7 +175,7 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
             
             @Override
             protected Boolean executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode) throws SQLException {
-                return executor.execute(statement, sql);
+                return executor.execute(sql, statement);
             }
         };
         return executeAndRefreshMetaData(executionGroups, sqlStatement, 
routeUnits, jdbcExecutorCallback);
@@ -205,11 +183,11 @@ public final class StatementExecutor extends 
AbstractStatementExecutor {
     
     private interface Updater {
         
-        int executeUpdate(Statement statement, String sql) throws SQLException;
+        int executeUpdate(String sql, Statement statement) throws SQLException;
     }
     
     private interface Executor {
         
-        boolean execute(Statement statement, String sql) throws SQLException;
+        boolean execute(String sql, Statement statement) throws SQLException;
     }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/JDBCExecuteQueryCallback.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/JDBCExecuteQueryCallback.java
new file mode 100644
index 0000000..c3216b3
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/JDBCExecuteQueryCallback.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.driver.executor.callback;
+
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.memory.JDBCMemoryQueryResult;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * JDBC execute query callback.
+ */
+public abstract class JDBCExecuteQueryCallback extends 
JDBCExecutorCallback<QueryResult> {
+    
+    public JDBCExecuteQueryCallback(final DatabaseType databaseType, final 
boolean isExceptionThrown) {
+        super(databaseType, isExceptionThrown);
+    }
+    
+    @Override
+    protected final QueryResult executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode) throws SQLException {
+        ResultSet resultSet = executeQuery(sql, statement);
+        return ConnectionMode.MEMORY_STRICTLY == connectionMode ? new 
JDBCStreamQueryResult(resultSet) : new JDBCMemoryQueryResult(resultSet);
+    }
+    
+    protected abstract ResultSet executeQuery(String sql, Statement statement) 
throws SQLException;
+}
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/impl/PreparedStatementExecuteQueryCallback.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/impl/PreparedStatementExecuteQueryCallback.java
new file mode 100644
index 0000000..e3bd2ea
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/impl/PreparedStatementExecuteQueryCallback.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.driver.executor.callback.impl;
+
+import 
org.apache.shardingsphere.driver.executor.callback.JDBCExecuteQueryCallback;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * Prepared statement execute query callback.
+ */
+public final class PreparedStatementExecuteQueryCallback extends 
JDBCExecuteQueryCallback {
+    
+    public PreparedStatementExecuteQueryCallback(final DatabaseType 
databaseType, final boolean isExceptionThrown) {
+        super(databaseType, isExceptionThrown);
+    }
+    
+    @Override
+    protected ResultSet executeQuery(final String sql, final Statement 
statement) throws SQLException {
+        return ((PreparedStatement) statement).executeQuery();
+    }
+}
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/impl/StatementExecuteQueryCallback.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/impl/StatementExecuteQueryCallback.java
new file mode 100644
index 0000000..82de1f0
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/executor/callback/impl/StatementExecuteQueryCallback.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.driver.executor.callback.impl;
+
+import 
org.apache.shardingsphere.driver.executor.callback.JDBCExecuteQueryCallback;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * Statement execute query callback.
+ */
+public final class StatementExecuteQueryCallback extends 
JDBCExecuteQueryCallback {
+    
+    public StatementExecuteQueryCallback(final DatabaseType databaseType, 
final boolean isExceptionThrown) {
+        super(databaseType, isExceptionThrown);
+    }
+    
+    @Override
+    protected ResultSet executeQuery(final String sql, final Statement 
statement) throws SQLException {
+        return statement.executeQuery(sql);
+    }
+}
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index 098861b..00d4626 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -22,6 +22,7 @@ import lombok.Getter;
 import org.apache.shardingsphere.driver.executor.PreparedStatementExecutor;
 import org.apache.shardingsphere.driver.executor.batch.BatchExecutionUnit;
 import 
org.apache.shardingsphere.driver.executor.batch.BatchPreparedStatementExecutor;
+import 
org.apache.shardingsphere.driver.executor.callback.impl.PreparedStatementExecuteQueryCallback;
 import 
org.apache.shardingsphere.driver.jdbc.adapter.AbstractPreparedStatementAdapter;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import 
org.apache.shardingsphere.driver.jdbc.core.constant.SQLExceptionConstant;
@@ -41,8 +42,10 @@ import 
org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorExceptionHandler;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawExecutor;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawSQLExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.callback.RawSQLExecutorCallback;
@@ -50,8 +53,8 @@ import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult;
 import org.apache.shardingsphere.infra.executor.sql.log.SQLLogger;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine;
-import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType;
+import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.raw.RawExecutionPrepareEngine;
 import org.apache.shardingsphere.infra.merge.MergeEngine;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -99,10 +102,12 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
     @Getter
     private final ParameterMetaData parameterMetaData;
     
-    private final PreparedStatementExecutor preparedStatementExecutor;
+    private final JDBCExecutor jdbcExecutor;
     
     private final RawExecutor rawExecutor;
     
+    private final PreparedStatementExecutor preparedStatementExecutor;
+    
     private final BatchPreparedStatementExecutor 
batchPreparedStatementExecutor;
     
     private final Collection<Comparable<?>> generatedValues = new 
LinkedList<>();
@@ -144,9 +149,9 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
         sqlStatement = sqlStatementParserEngine.parse(sql, true);
         parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement);
         statementOption = returnGeneratedKeys ? new StatementOption(true) : 
new StatementOption(resultSetType, resultSetConcurrency, resultSetHoldability);
-        JDBCExecutor jdbcExecutor = new 
JDBCExecutor(metaDataContexts.getExecutorEngine(), 
connection.isHoldTransaction());
-        preparedStatementExecutor = new 
PreparedStatementExecutor(connection.getDataSourceMap(), metaDataContexts, 
jdbcExecutor);
+        jdbcExecutor = new JDBCExecutor(metaDataContexts.getExecutorEngine(), 
connection.isHoldTransaction());
         rawExecutor = new RawExecutor(metaDataContexts.getExecutorEngine(), 
connection.isHoldTransaction());
+        preparedStatementExecutor = new 
PreparedStatementExecutor(connection.getDataSourceMap(), metaDataContexts, 
jdbcExecutor);
         batchPreparedStatementExecutor = new 
BatchPreparedStatementExecutor(metaDataContexts, jdbcExecutor);
         kernelProcessor = new KernelProcessor();
     }
@@ -164,7 +169,9 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
                 Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups 
= createExecutionGroups();
                 cacheStatements(executionGroups);
                 reply();
-                queryResults = 
preparedStatementExecutor.executeQuery(executionGroups);
+                JDBCExecutorCallback<QueryResult> callback = new 
PreparedStatementExecuteQueryCallback(metaDataContexts.getDatabaseType(), 
SQLExecutorExceptionHandler.isExceptionThrown());
+                queryResults = jdbcExecutor.execute(executionGroups, callback);
+                
             }
             MergedResult mergedResult = mergeQuery(queryResults);
             result = new 
ShardingSphereResultSet(statements.stream().map(this::getResultSet).collect(Collectors.toList()),
 mergedResult, this, executionContext);
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 c56c698..0138efd 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
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.driver.jdbc.core.statement;
 import com.google.common.base.Strings;
 import lombok.Getter;
 import org.apache.shardingsphere.driver.executor.StatementExecutor;
+import 
org.apache.shardingsphere.driver.executor.callback.impl.StatementExecuteQueryCallback;
 import org.apache.shardingsphere.driver.jdbc.adapter.AbstractStatementAdapter;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import 
org.apache.shardingsphere.driver.jdbc.core.constant.SQLExceptionConstant;
@@ -39,8 +40,10 @@ import 
org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorExceptionHandler;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawExecutor;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawSQLExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.callback.RawSQLExecutorCallback;
@@ -48,8 +51,8 @@ import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult;
 import org.apache.shardingsphere.infra.executor.sql.log.SQLLogger;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine;
-import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType;
+import 
org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption;
 import 
org.apache.shardingsphere.infra.executor.sql.prepare.raw.RawExecutionPrepareEngine;
 import org.apache.shardingsphere.infra.merge.MergeEngine;
 import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -89,6 +92,8 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
     
     private final StatementExecutor statementExecutor;
     
+    private final JDBCExecutor jdbcExecutor;
+    
     private final RawExecutor rawExecutor;
     
     private final KernelProcessor kernelProcessor;
@@ -113,7 +118,8 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         metaDataContexts = connection.getMetaDataContexts();
         statements = new LinkedList<>();
         statementOption = new StatementOption(resultSetType, 
resultSetConcurrency, resultSetHoldability);
-        statementExecutor = new 
StatementExecutor(connection.getDataSourceMap(), metaDataContexts, new 
JDBCExecutor(metaDataContexts.getExecutorEngine(), 
connection.isHoldTransaction()));
+        jdbcExecutor = new JDBCExecutor(metaDataContexts.getExecutorEngine(), 
connection.isHoldTransaction());
+        statementExecutor = new 
StatementExecutor(connection.getDataSourceMap(), metaDataContexts, 
jdbcExecutor);
         rawExecutor = new RawExecutor(metaDataContexts.getExecutorEngine(), 
connection.isHoldTransaction());
         kernelProcessor = new KernelProcessor();
     }
@@ -132,7 +138,8 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
             } else {
                 Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups 
= createExecutionGroups();
                 cacheStatements(executionGroups);
-                queryResults = statementExecutor.executeQuery(executionGroups);
+                JDBCExecutorCallback<QueryResult> callback = new 
StatementExecuteQueryCallback(metaDataContexts.getDatabaseType(), 
SQLExecutorExceptionHandler.isExceptionThrown());
+                queryResults = jdbcExecutor.execute(executionGroups, callback);
             }
             MergedResult mergedResult = mergeQuery(queryResults);
             result = new 
ShardingSphereResultSet(statements.stream().map(this::getResultSet).collect(Collectors.toList()),
 mergedResult, this, executionContext);
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutorTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutorTest.java
index 7e87716..54e7d77 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutorTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/PreparedStatementExecutorTest.java
@@ -19,10 +19,9 @@ package org.apache.shardingsphere.driver.executor;
 
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
 import org.apache.shardingsphere.infra.executor.sql.context.SQLUnit;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -30,10 +29,7 @@ import org.junit.Test;
 
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
-import java.sql.Types;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -65,76 +61,6 @@ public final class PreparedStatementExecutorTest extends 
AbstractBaseExecutorTes
     }
     
     @Test
-    public void assertNoStatement() throws SQLException {
-        assertFalse(actual.execute(Collections.emptyList(), 
mock(SQLStatement.class), null));
-        assertThat(actual.executeUpdate(Collections.emptyList(), 
createSQLStatementContext(), null), is(0));
-        assertThat(actual.executeQuery(Collections.emptyList()).size(), is(0));
-    }
-    
-    @Test
-    public void assertExecuteQueryForSinglePreparedStatementSuccess() throws 
SQLException {
-        PreparedStatement preparedStatement = getPreparedStatement();
-        ResultSet resultSet = mock(ResultSet.class);
-        ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
-        when(resultSetMetaData.getColumnName(1)).thenReturn("column");
-        when(resultSetMetaData.getColumnLabel(1)).thenReturn("column");
-        when(resultSetMetaData.getTableName(1)).thenReturn("table_x");
-        when(resultSetMetaData.getColumnCount()).thenReturn(1);
-        when(resultSetMetaData.getColumnType(1)).thenReturn(Types.VARCHAR);
-        when(resultSet.getString(1)).thenReturn("value");
-        when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
-        when(preparedStatement.executeQuery()).thenReturn(resultSet);
-        
assertThat(actual.executeQuery(getExecutionGroups(Collections.singletonList(preparedStatement),
 true)).iterator().next().getValue(1, String.class), is("value"));
-    }
-    
-    @Test
-    public void assertExecuteQueryForMultiplePreparedStatementsSuccess() 
throws SQLException {
-        PreparedStatement preparedStatement1 = getPreparedStatement();
-        PreparedStatement preparedStatement2 = getPreparedStatement();
-        ResultSet resultSet1 = mock(ResultSet.class);
-        ResultSet resultSet2 = mock(ResultSet.class);
-        ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
-        when(resultSetMetaData.getColumnName(1)).thenReturn("column");
-        when(resultSetMetaData.getColumnLabel(1)).thenReturn("column");
-        when(resultSetMetaData.getTableName(1)).thenReturn("table_x");
-        when(resultSetMetaData.getColumnCount()).thenReturn(1);
-        when(resultSetMetaData.getColumnType(1)).thenReturn(Types.INTEGER);
-        when(resultSet1.getMetaData()).thenReturn(resultSetMetaData);
-        when(resultSet2.getMetaData()).thenReturn(resultSetMetaData);
-        when(resultSet1.getInt(1)).thenReturn(1);
-        when(resultSet2.getInt(1)).thenReturn(2);
-        when(preparedStatement1.executeQuery()).thenReturn(resultSet1);
-        when(preparedStatement2.executeQuery()).thenReturn(resultSet2);
-        List<QueryResult> result = 
actual.executeQuery(getExecutionGroups(Arrays.asList(preparedStatement1, 
preparedStatement2), true));
-        assertThat(String.valueOf(result.get(0).getValue(1, int.class)), 
is("1"));
-        assertThat(String.valueOf(result.get(1).getValue(1, int.class)), 
is("2"));
-        verify(preparedStatement1).executeQuery();
-        verify(preparedStatement2).executeQuery();
-    }
-    
-    @Test
-    public void assertExecuteQueryForSinglePreparedStatementFailure() throws 
SQLException {
-        PreparedStatement preparedStatement = getPreparedStatement();
-        SQLException ex = new SQLException("");
-        when(preparedStatement.executeQuery()).thenThrow(ex);
-        
assertThat(actual.executeQuery(getExecutionGroups(Collections.singletonList(preparedStatement),
 true)), is(Collections.singletonList((QueryResult) null)));
-        verify(preparedStatement).executeQuery();
-    }
-    
-    @Test
-    public void assertExecuteQueryForMultiplePreparedStatementsFailure() 
throws SQLException {
-        PreparedStatement preparedStatement1 = getPreparedStatement();
-        PreparedStatement preparedStatement2 = getPreparedStatement();
-        SQLException ex = new SQLException("");
-        when(preparedStatement1.executeQuery()).thenThrow(ex);
-        when(preparedStatement2.executeQuery()).thenThrow(ex);
-        List<QueryResult> actualQueryResults = 
actual.executeQuery(getExecutionGroups(Arrays.asList(preparedStatement1, 
preparedStatement2), true));
-        assertThat(actualQueryResults, is(Arrays.asList((QueryResult) null, 
null)));
-        verify(preparedStatement1).executeQuery();
-        verify(preparedStatement2).executeQuery();
-    }
-    
-    @Test
     public void assertExecuteUpdateForSinglePreparedStatementSuccess() throws 
SQLException {
         PreparedStatement preparedStatement = getPreparedStatement();
         when(preparedStatement.executeUpdate()).thenReturn(10);
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java
index d20f55b..0e8ab9f 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java
@@ -19,23 +19,19 @@ package org.apache.shardingsphere.driver.executor;
 
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
 import org.apache.shardingsphere.infra.executor.sql.context.SQLUnit;
-import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutorExceptionHandler;
+import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import org.junit.Test;
 
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.sql.Types;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -67,77 +63,6 @@ public final class StatementExecutorTest extends 
AbstractBaseExecutorTest {
     }
     
     @Test
-    public void assertNoStatement() throws SQLException {
-        assertFalse(actual.execute(Collections.emptyList(), 
mock(SQLStatement.class), null));
-        assertThat(actual.executeUpdate(Collections.emptyList(), 
createSQLStatementContext(), null), is(0));
-        assertThat(actual.executeQuery(Collections.emptyList()).size(), is(0));
-    }
-    
-    @Test
-    public void assertExecuteQueryForSingleStatementSuccess() throws 
SQLException {
-        Statement statement = getStatement();
-        ResultSet resultSet = mock(ResultSet.class);
-        ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
-        when(resultSetMetaData.getColumnName(1)).thenReturn("column");
-        when(resultSetMetaData.getColumnLabel(1)).thenReturn("column");
-        when(resultSetMetaData.getTableName(1)).thenReturn("table_x");
-        when(resultSetMetaData.getColumnCount()).thenReturn(1);
-        when(resultSetMetaData.getColumnType(1)).thenReturn(Types.VARCHAR);
-        when(resultSet.getString(1)).thenReturn("value");
-        when(resultSet.getMetaData()).thenReturn(resultSetMetaData);
-        when(statement.executeQuery(DQL_SQL)).thenReturn(resultSet);
-        
assertThat(actual.executeQuery(createExecutionGroups(Collections.singletonList(statement),
 true)).iterator().next().getValue(1, String.class), is("value"));
-        verify(statement).executeQuery(DQL_SQL);
-    }
-    
-    @Test
-    public void assertExecuteQueryForMultipleStatementsSuccess() throws 
SQLException {
-        Statement statement1 = getStatement();
-        Statement statement2 = getStatement();
-        ResultSet resultSet1 = mock(ResultSet.class);
-        ResultSet resultSet2 = mock(ResultSet.class);
-        ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
-        when(resultSetMetaData.getColumnName(1)).thenReturn("column");
-        when(resultSetMetaData.getColumnLabel(1)).thenReturn("column");
-        when(resultSetMetaData.getTableName(1)).thenReturn("table_x");
-        when(resultSetMetaData.getColumnCount()).thenReturn(1);
-        when(resultSetMetaData.getColumnType(1)).thenReturn(Types.INTEGER);
-        when(resultSet1.getMetaData()).thenReturn(resultSetMetaData);
-        when(resultSet2.getMetaData()).thenReturn(resultSetMetaData);
-        when(resultSet1.getInt(1)).thenReturn(1);
-        when(resultSet2.getInt(1)).thenReturn(2);
-        when(statement1.executeQuery(DQL_SQL)).thenReturn(resultSet1);
-        when(statement2.executeQuery(DQL_SQL)).thenReturn(resultSet2);
-        List<QueryResult> result = 
actual.executeQuery(createExecutionGroups(Arrays.asList(statement1, 
statement2), true));
-        assertThat(String.valueOf(result.get(0).getValue(1, int.class)), 
is("1"));
-        assertThat(String.valueOf(result.get(1).getValue(1, int.class)), 
is("2"));
-        verify(statement1).executeQuery(DQL_SQL);
-        verify(statement2).executeQuery(DQL_SQL);
-    }
-    
-    @Test
-    public void assertExecuteQueryForSingleStatementFailure() throws 
SQLException {
-        Statement statement = getStatement();
-        SQLException ex = new SQLException("");
-        when(statement.executeQuery(DQL_SQL)).thenThrow(ex);
-        
assertThat(actual.executeQuery(createExecutionGroups(Collections.singletonList(statement),
 true)), is(Collections.singletonList((QueryResult) null)));
-        verify(statement).executeQuery(DQL_SQL);
-    }
-    
-    @Test
-    public void assertExecuteQueryForMultipleStatementsFailure() throws 
SQLException {
-        Statement statement1 = getStatement();
-        Statement statement2 = getStatement();
-        SQLException ex = new SQLException("");
-        when(statement1.executeQuery(DQL_SQL)).thenThrow(ex);
-        when(statement2.executeQuery(DQL_SQL)).thenThrow(ex);
-        List<QueryResult> actualQueryResults = 
actual.executeQuery(createExecutionGroups(Arrays.asList(statement1, 
statement2), true));
-        assertThat(actualQueryResults, is(Arrays.asList((QueryResult) null, 
null)));
-        verify(statement1).executeQuery(DQL_SQL);
-        verify(statement2).executeQuery(DQL_SQL);
-    }
-    
-    @Test
     public void assertExecuteUpdateForSingleStatementSuccess() throws 
SQLException {
         Statement statement = getStatement();
         when(statement.executeUpdate(DML_SQL)).thenReturn(10);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
index 787b069..5858747 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/ProxyJDBCExecutorCallback.java
@@ -56,14 +56,14 @@ public abstract class ProxyJDBCExecutorCallback extends 
JDBCExecutorCallback<Exe
     public ExecuteResult executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode) throws SQLException {
         if (fetchMetaData && !hasMetaData) {
             hasMetaData = true;
-            return executeSQL(statement, sql, connectionMode, true);
+            return executeSQL(sql, statement, connectionMode, true);
         }
-        return executeSQL(statement, sql, connectionMode, false);
+        return executeSQL(sql, statement, connectionMode, false);
     }
     
-    private ExecuteResult executeSQL(final Statement statement, final String 
sql, final ConnectionMode connectionMode, final boolean withMetadata) throws 
SQLException {
+    private ExecuteResult executeSQL(final String sql, final Statement 
statement, final ConnectionMode connectionMode, final boolean withMetadata) 
throws SQLException {
         backendConnection.add(statement);
-        if (execute(statement, sql, isReturnGeneratedKeys)) {
+        if (execute(sql, statement, isReturnGeneratedKeys)) {
             ResultSet resultSet = statement.getResultSet();
             backendConnection.add(resultSet);
             return createQueryResult(resultSet, connectionMode);
@@ -71,10 +71,10 @@ public abstract class ProxyJDBCExecutorCallback extends 
JDBCExecutorCallback<Exe
         return new UpdateResult(statement.getUpdateCount(), 
isReturnGeneratedKeys ? getGeneratedKey(statement) : 0L);
     }
     
-    protected abstract boolean execute(Statement statement, String sql, 
boolean isReturnGeneratedKeys) throws SQLException;
+    protected abstract boolean execute(String sql, Statement statement, 
boolean isReturnGeneratedKeys) throws SQLException;
     
     private QueryResult createQueryResult(final ResultSet resultSet, final 
ConnectionMode connectionMode) throws SQLException {
-        return connectionMode == ConnectionMode.MEMORY_STRICTLY ? new 
JDBCStreamQueryResult(resultSet) : new JDBCMemoryQueryResult(resultSet);
+        return ConnectionMode.MEMORY_STRICTLY == connectionMode ? new 
JDBCStreamQueryResult(resultSet) : new JDBCMemoryQueryResult(resultSet);
     }
     
     private long getGeneratedKey(final Statement statement) throws 
SQLException {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyPreparedStatementExecutorCallback.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyPreparedStatementExecutorCallback.java
index 09199f9..3e92af5 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyPreparedStatementExecutorCallback.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyPreparedStatementExecutorCallback.java
@@ -36,7 +36,7 @@ public final class ProxyPreparedStatementExecutorCallback 
extends ProxyJDBCExecu
     }
     
     @Override
-    protected boolean execute(final Statement statement, final String sql, 
final boolean isReturnGeneratedKeys) throws SQLException {
+    protected boolean execute(final String sql, final Statement statement, 
final boolean isReturnGeneratedKeys) throws SQLException {
         return ((PreparedStatement) statement).execute();
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyStatementExecutorCallback.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyStatementExecutorCallback.java
index d247f18..089dd0d 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyStatementExecutorCallback.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/executor/callback/impl/ProxyStatementExecutorCallback.java
@@ -35,7 +35,7 @@ public final class ProxyStatementExecutorCallback extends 
ProxyJDBCExecutorCallb
     }
     
     @Override
-    protected boolean execute(final Statement statement, final String sql, 
final boolean isReturnGeneratedKeys) throws SQLException {
+    protected boolean execute(final String sql, final Statement statement, 
final boolean isReturnGeneratedKeys) throws SQLException {
         return statement.execute(sql, isReturnGeneratedKeys ? 
Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
     }
 }

Reply via email to