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 a89475fbdd2 Refactor DatabaseCommunicationEngineFactory (#19435)
a89475fbdd2 is described below

commit a89475fbdd2206a8b11525fad5d1309f0dc72593
Author: 吴伟杰 <[email protected]>
AuthorDate: Thu Jul 21 19:32:07 2022 +0800

    Refactor DatabaseCommunicationEngineFactory (#19435)
    
    * Refactor DatabaseCommunicationEngineFactory
    
    * Rename methods in DatabaseCommunicationEngineFactoryTest
---
 .../DatabaseCommunicationEngineFactory.java        | 33 ++++++++++------------
 .../executor/UnicastResourceShowExecutor.java      |  2 +-
 .../impl/SchemaAssignedDatabaseBackendHandler.java |  2 +-
 .../data/impl/UnicastDatabaseBackendHandler.java   |  4 +--
 .../DatabaseCommunicationEngineFactoryTest.java    |  8 +++---
 .../jdbc/JDBCDatabaseCommunicationEngineTest.java  | 10 +++----
 .../SchemaAssignedDatabaseBackendHandlerTest.java  |  3 +-
 .../impl/UnicastDatabaseBackendHandlerTest.java    |  3 +-
 .../execute/MySQLComStmtExecuteExecutor.java       |  2 +-
 .../fieldlist/MySQLComFieldListPacketExecutor.java |  2 +-
 .../execute/MySQLComStmtExecuteExecutorTest.java   |  4 +--
 .../command/query/extended/JDBCPortal.java         |  2 +-
 .../ReactiveMySQLComStmtExecuteExecutor.java       |  2 +-
 .../ReactiveMySQLComFieldListPacketExecutor.java   |  2 +-
 14 files changed, 39 insertions(+), 40 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
index 164a3e8f03f..03146953bf7 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
@@ -51,31 +51,22 @@ public final class DatabaseCommunicationEngineFactory {
     }
     
     /**
-     * Create new instance of text protocol backend handler.
+     * Create new instance of {@link DatabaseCommunicationEngine} without 
parameter.
      *
      * @param <T> type of DatabaseCommunicationEngine
      * @param sqlStatementContext SQL statement context
      * @param sql SQL to be executed
      * @param backendConnection backend connection
+     * @param preferPreparedStatement use prepared statement as possible
      * @return created instance
      */
-    public <T extends DatabaseCommunicationEngine> T 
newTextProtocolInstance(final SQLStatementContext<?> sqlStatementContext, final 
String sql, final BackendConnection<?> backendConnection) {
-        ShardingSphereDatabase database = 
ProxyContext.getInstance().getDatabase(backendConnection.getConnectionSession().getDatabaseName());
-        LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, 
Collections.emptyList());
-        T result;
-        if (backendConnection instanceof JDBCBackendConnection) {
-            JDBCBackendConnection jdbcBackendConnection = 
(JDBCBackendConnection) backendConnection;
-            result = (T) new 
JDBCDatabaseCommunicationEngine(JDBCDriverType.STATEMENT, database, logicSQL, 
jdbcBackendConnection);
-            jdbcBackendConnection.add((JDBCDatabaseCommunicationEngine) 
result);
-        } else {
-            VertxBackendConnection vertxBackendConnection = 
(VertxBackendConnection) backendConnection;
-            result = (T) new VertxDatabaseCommunicationEngine(database, 
logicSQL, vertxBackendConnection);
-        }
-        return result;
+    public <T extends DatabaseCommunicationEngine> T 
newDatabaseCommunicationEngine(final SQLStatementContext<?> sqlStatementContext,
+                                                                               
     final String sql, final BackendConnection<?> backendConnection, final 
boolean preferPreparedStatement) {
+        return newInstance(sqlStatementContext, sql, Collections.emptyList(), 
backendConnection, preferPreparedStatement);
     }
     
     /**
-     * Create new instance of binary protocol backend handler.
+     * Create new instance of {@link DatabaseCommunicationEngine}.
      *
      * @param <T> type of DatabaseCommunicationEngine
      * @param sqlStatementContext SQL statement context
@@ -84,14 +75,20 @@ public final class DatabaseCommunicationEngineFactory {
      * @param backendConnection backend connection
      * @return created instance
      */
-    public <T extends DatabaseCommunicationEngine> T 
newBinaryProtocolInstance(final SQLStatementContext<?> sqlStatementContext,
-                                                                               
final String sql, final List<Object> parameters, final BackendConnection<?> 
backendConnection) {
+    public <T extends DatabaseCommunicationEngine> T 
newDatabaseCommunicationEngine(final SQLStatementContext<?> sqlStatementContext,
+                                                                               
     final String sql, final List<Object> parameters, final 
BackendConnection<?> backendConnection) {
+        return newInstance(sqlStatementContext, sql, parameters, 
backendConnection, true);
+    }
+    
+    private <T extends DatabaseCommunicationEngine> T newInstance(final 
SQLStatementContext<?> sqlStatementContext, final String sql, final 
List<Object> parameters,
+                                                                  final 
BackendConnection<?> backendConnection, final boolean preferPreparedStatement) {
         ShardingSphereDatabase database = 
ProxyContext.getInstance().getDatabase(backendConnection.getConnectionSession().getDatabaseName());
         LogicSQL logicSQL = new LogicSQL(sqlStatementContext, sql, parameters);
         T result;
         if (backendConnection instanceof JDBCBackendConnection) {
             JDBCBackendConnection jdbcBackendConnection = 
(JDBCBackendConnection) backendConnection;
-            result = (T) new 
JDBCDatabaseCommunicationEngine(JDBCDriverType.PREPARED_STATEMENT, database, 
logicSQL, jdbcBackendConnection);
+            String driverType = preferPreparedStatement ? 
JDBCDriverType.PREPARED_STATEMENT : JDBCDriverType.STATEMENT;
+            result = (T) new JDBCDatabaseCommunicationEngine(driverType, 
database, logicSQL, jdbcBackendConnection);
             jdbcBackendConnection.add((JDBCDatabaseCommunicationEngine) 
result);
         } else {
             VertxBackendConnection vertxBackendConnection = 
(VertxBackendConnection) backendConnection;
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java
index aa29c269b92..dad3c756fb2 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/UnicastResourceShowExecutor.java
@@ -79,7 +79,7 @@ public final class UnicastResourceShowExecutor implements 
DatabaseAdminQueryExec
             connectionSession.setCurrentDatabase(databaseName);
             SQLStatementContext<?> sqlStatementContext = 
SQLStatementContextFactory.newInstance(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabases(),
                     sqlStatement, connectionSession.getDefaultDatabaseName());
-            databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, 
sql, connectionSession.getBackendConnection());
+            databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newDatabaseCommunicationEngine(sqlStatementContext,
 sql, connectionSession.getBackendConnection(), false);
             responseHeader = databaseCommunicationEngine.execute();
             mergedResult = new TransparentMergedResult(createQueryResult());
         } finally {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
index fa5188696c8..d19956213c7 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandler.java
@@ -87,7 +87,7 @@ public final class SchemaAssignedDatabaseBackendHandler 
implements DatabaseBacke
         if (sqlStatementContext instanceof CursorAvailable) {
             prepareCursorStatementContext((CursorAvailable) 
sqlStatementContext, connectionSession);
         }
-        databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, 
sql, connectionSession.getBackendConnection());
+        databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newDatabaseCommunicationEngine(sqlStatementContext,
 sql, connectionSession.getBackendConnection(), false);
     }
     
     private void prepareCursorStatementContext(final CursorAvailable 
statementContext, final ConnectionSession connectionSession) {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
index d8399db07ad..d99ed210592 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
@@ -59,7 +59,7 @@ public final class UnicastDatabaseBackendHandler implements 
DatabaseBackendHandl
             throw new RuleNotExistedException();
         }
         connectionSession.setCurrentDatabase(databaseName);
-        databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, 
sql, connectionSession.getBackendConnection());
+        databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newDatabaseCommunicationEngine(sqlStatementContext,
 sql, connectionSession.getBackendConnection(), false);
         return ((Future<ResponseHeader>) 
databaseCommunicationEngine.execute()).eventually(unused -> {
             connectionSession.setCurrentDatabase(databaseName);
             return Future.succeededFuture();
@@ -75,7 +75,7 @@ public final class UnicastDatabaseBackendHandler implements 
DatabaseBackendHandl
         }
         try {
             connectionSession.setCurrentDatabase(databaseName);
-            databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, 
sql, connectionSession.getBackendConnection());
+            databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newDatabaseCommunicationEngine(sqlStatementContext,
 sql, connectionSession.getBackendConnection(), false);
             return (ResponseHeader) databaseCommunicationEngine.execute();
         } finally {
             connectionSession.setCurrentDatabase(databaseName);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
index c6afc732b3f..6738f19d334 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactoryTest.java
@@ -62,22 +62,22 @@ public final class DatabaseCommunicationEngineFactoryTest 
extends ProxyContextRe
     }
     
     @Test
-    public void assertNewTextProtocolInstance() {
+    public void assertNewDatabaseCommunicationEngineWithoutParameter() {
         JDBCBackendConnection backendConnection = 
mock(JDBCBackendConnection.class, RETURNS_DEEP_STUBS);
         
when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("db");
         SQLStatementContext<?> sqlStatementContext = 
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
         
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
-        DatabaseCommunicationEngine<?> engine = 
DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext,
 "schemaName", backendConnection);
+        DatabaseCommunicationEngine<?> engine = 
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 "schemaName", backendConnection, false);
         assertThat(engine, instanceOf(DatabaseCommunicationEngine.class));
     }
     
     @Test
-    public void assertNewBinaryProtocolInstance() {
+    public void assertNewDatabaseCommunicationEngineWithParameters() {
         JDBCBackendConnection backendConnection = 
mock(JDBCBackendConnection.class, RETURNS_DEEP_STUBS);
         
when(backendConnection.getConnectionSession().getDatabaseName()).thenReturn("db");
         SQLStatementContext<?> sqlStatementContext = 
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
         
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
-        
assertThat(DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection),
+        
assertThat(DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection),
                 instanceOf(DatabaseCommunicationEngine.class));
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
index 9e38e0a418c..116d0bd2acb 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngineTest.java
@@ -113,7 +113,7 @@ public final class JDBCDatabaseCommunicationEngineTest 
extends ProxyContextResto
         SQLStatementContext<?> sqlStatementContext = 
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
         
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
         JDBCDatabaseCommunicationEngine engine =
-                
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
+                
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
         assertNotNull(engine);
         assertThat(engine, instanceOf(DatabaseCommunicationEngine.class));
         Field queryHeadersField = 
DatabaseCommunicationEngine.class.getDeclaredField("queryHeaders");
@@ -169,7 +169,7 @@ public final class JDBCDatabaseCommunicationEngineTest 
extends ProxyContextResto
         SQLStatementContext<?> sqlStatementContext = 
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
         
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
         JDBCDatabaseCommunicationEngine engine =
-                
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
+                
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
         engine.add(statement);
         Collection<?> actual = getField(engine, "cachedStatements");
         assertThat(actual.size(), is(1));
@@ -181,7 +181,7 @@ public final class JDBCDatabaseCommunicationEngineTest 
extends ProxyContextResto
         SQLStatementContext<?> sqlStatementContext = 
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
         
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
         JDBCDatabaseCommunicationEngine engine =
-                
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
+                
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
         engine.add(resultSet);
         Collection<?> actual = getField(engine, "cachedResultSets");
         assertThat(actual.size(), is(1));
@@ -193,7 +193,7 @@ public final class JDBCDatabaseCommunicationEngineTest 
extends ProxyContextResto
         SQLStatementContext<?> sqlStatementContext = 
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
         
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
         JDBCDatabaseCommunicationEngine engine =
-                
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
+                
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
         Collection<ResultSet> cachedResultSets = getField(engine, 
"cachedResultSets");
         cachedResultSets.add(resultSet);
         Collection<Statement> cachedStatements = getField(engine, 
"cachedStatements");
@@ -211,7 +211,7 @@ public final class JDBCDatabaseCommunicationEngineTest 
extends ProxyContextResto
         SQLStatementContext<?> sqlStatementContext = 
mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
         
when(sqlStatementContext.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
         JDBCDatabaseCommunicationEngine engine =
-                
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
+                
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 "schemaName", Collections.emptyList(), backendConnection);
         Collection<ResultSet> cachedResultSets = getField(engine, 
"cachedResultSets");
         SQLException sqlExceptionByResultSet = new SQLException("ResultSet");
         doThrow(sqlExceptionByResultSet).when(resultSet).close();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
index a2208f89610..61e4652c921 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/SchemaAssignedDatabaseBackendHandlerTest.java
@@ -56,6 +56,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -108,7 +109,7 @@ public final class SchemaAssignedDatabaseBackendHandlerTest 
extends ProxyContext
     
     private void mockDatabaseCommunicationEngine(final ResponseHeader 
responseHeader) {
         when(databaseCommunicationEngine.execute()).thenReturn(responseHeader);
-        when(databaseCommunicationEngineFactory.newTextProtocolInstance(any(), 
anyString(), any())).thenReturn(databaseCommunicationEngine);
+        
when(databaseCommunicationEngineFactory.newDatabaseCommunicationEngine(any(), 
anyString(), any(), eq(false))).thenReturn(databaseCommunicationEngine);
     }
     
     @SneakyThrows(ReflectiveOperationException.class)
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
index 6974bcdfd74..f4d661f498f 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandlerTest.java
@@ -54,6 +54,7 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -102,7 +103,7 @@ public final class UnicastDatabaseBackendHandlerTest 
extends ProxyContextRestore
     
     private void mockDatabaseCommunicationEngine(final ResponseHeader 
responseHeader) {
         when(databaseCommunicationEngine.execute()).thenReturn(responseHeader);
-        when(databaseCommunicationEngineFactory.newTextProtocolInstance(any(), 
anyString(), any())).thenReturn(databaseCommunicationEngine);
+        
when(databaseCommunicationEngineFactory.newDatabaseCommunicationEngine(any(), 
anyString(), any(), eq(false))).thenReturn(databaseCommunicationEngine);
     }
     
     @SneakyThrows(ReflectiveOperationException.class)
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
index 353058408a2..802039deeff 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
@@ -108,7 +108,7 @@ public final class MySQLComStmtExecuteExecutor implements 
QueryCommandExecutor {
             textProtocolBackendHandler =
                     
TextProtocolBackendHandlerFactory.newInstance(DatabaseTypeFactory.getInstance("MySQL"),
 preparedStatement.getSql(), () -> Optional.of(sqlStatement), 
connectionSession);
         } else {
-            databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 preparedStatement.getSql(), parameters,
+            databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 preparedStatement.getSql(), parameters,
                     connectionSession.getBackendConnection());
         }
         ResponseHeader responseHeader = null != databaseCommunicationEngine ? 
databaseCommunicationEngine.execute() : textProtocolBackendHandler.execute();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
index cb3db369f5a..e5b0530919c 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
@@ -71,7 +71,7 @@ public final class MySQLComFieldListPacketExecutor implements 
CommandExecutor {
                 
DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType())).parse(sql,
 false);
         SQLStatementContext<?> sqlStatementContext = 
SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(),
 sqlStatement, databaseName);
         JDBCBackendConnection backendConnection = (JDBCBackendConnection) 
connectionSession.getBackendConnection();
-        databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext,
 sql, backendConnection);
+        databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 sql, backendConnection, false);
         characterSet = 
connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
index 1aca60bc315..061053fd882 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
@@ -169,7 +169,7 @@ public final class MySQLComStmtExecuteExecutorTest extends 
ProxyContextRestorer
         when(databaseCommunicationEngine.getQueryResponseRow()).thenReturn(new 
QueryResponseRow(Collections.singletonList(new QueryResponseCell(Types.INTEGER, 
1))));
         Iterator<DatabasePacket<?>> actual;
         try (MockedStatic<DatabaseCommunicationEngineFactory> mockedStatic = 
mockStatic(DatabaseCommunicationEngineFactory.class, RETURNS_DEEP_STUBS)) {
-            mockedStatic.when(() -> 
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(any(SQLStatementContext.class),
 anyString(), anyList(), eq(backendConnection)))
+            mockedStatic.when(() -> 
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(any(SQLStatementContext.class),
 anyString(), anyList(), eq(backendConnection)))
                     .thenReturn(databaseCommunicationEngine);
             actual = mysqlComStmtExecuteExecutor.execute().iterator();
         }
@@ -195,7 +195,7 @@ public final class MySQLComStmtExecuteExecutorTest extends 
ProxyContextRestorer
         when(databaseCommunicationEngine.execute()).thenReturn(new 
UpdateResponseHeader(new MySQLUpdateStatement()));
         Iterator<DatabasePacket<?>> actual;
         try (MockedStatic<DatabaseCommunicationEngineFactory> mockedStatic = 
mockStatic(DatabaseCommunicationEngineFactory.class, RETURNS_DEEP_STUBS)) {
-            mockedStatic.when(() -> 
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(any(SQLStatementContext.class),
 anyString(), anyList(), eq(backendConnection)))
+            mockedStatic.when(() -> 
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(any(SQLStatementContext.class),
 anyString(), anyList(), eq(backendConnection)))
                     .thenReturn(databaseCommunicationEngine);
             actual = mysqlComStmtExecuteExecutor.execute().iterator();
         }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java
index 178c9c4ae51..fa86a73ccee 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortal.java
@@ -109,7 +109,7 @@ public final class JDBCPortal implements Portal<Void> {
                     preparedStatement.getSql(), () -> 
Optional.of(sqlStatement), backendConnection.getConnectionSession());
             return;
         }
-        databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatementContext,
 preparedStatement.getSql(), parameters, backendConnection);
+        databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 preparedStatement.getSql(), parameters, backendConnection);
         textProtocolBackendHandler = null;
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
index 501a6e25f63..0829c203b78 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/binary/execute/ReactiveMySQLComStmtExecuteExecutor.java
@@ -109,7 +109,7 @@ public final class ReactiveMySQLComStmtExecuteExecutor 
implements ReactiveComman
                     
TextProtocolBackendHandlerFactory.newInstance(DatabaseTypeFactory.getInstance("MySQL"),
 preparedStatement.getSql(), () -> Optional.of(sqlStatement), 
connectionSession);
         } else {
             databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance()
-                    .newBinaryProtocolInstance(sqlStatementContext, 
preparedStatement.getSql(), parameters, 
connectionSession.getBackendConnection());
+                    .newDatabaseCommunicationEngine(sqlStatementContext, 
preparedStatement.getSql(), parameters, 
connectionSession.getBackendConnection());
         }
         return (null != databaseCommunicationEngine ? 
databaseCommunicationEngine.execute() : 
textProtocolBackendHandler.executeFuture()).compose(responseHeader -> {
             Collection<DatabasePacket<?>> headerPackets = responseHeader 
instanceof QueryResponseHeader ? processQuery((QueryResponseHeader) 
responseHeader, characterSet)
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
index ad620165c48..768aa4255e7 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/reactive/mysql/command/query/text/fieldlist/ReactiveMySQLComFieldListPacketExecutor.java
@@ -70,7 +70,7 @@ public final class ReactiveMySQLComFieldListPacketExecutor 
implements ReactiveCo
         SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(
                 
DatabaseTypeEngine.getTrunkDatabaseTypeName(metaDataContexts.getMetaData().getDatabase(databaseName).getProtocolType())).parse(sql,
 false);
         SQLStatementContext<?> sqlStatementContext = 
SQLStatementContextFactory.newInstance(metaDataContexts.getMetaData().getDatabases(),
 sqlStatement, databaseName);
-        databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newTextProtocolInstance(sqlStatementContext,
 sql, connectionSession.getBackendConnection());
+        databaseCommunicationEngine = 
DatabaseCommunicationEngineFactory.getInstance().newDatabaseCommunicationEngine(sqlStatementContext,
 sql, connectionSession.getBackendConnection(), false);
         characterSet = 
connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
     }
     

Reply via email to