This is an automated email from the ASF dual-hosted git repository.
xiaoyu 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 3a1ba2d Refactor DatabaseCommunicationEngine (#8456)
3a1ba2d is described below
commit 3a1ba2d67aac17be5f2a2ba1636e8812164eff09
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Dec 1 20:30:36 2020 +0800
Refactor DatabaseCommunicationEngine (#8456)
---
.../backend/communication/DatabaseCommunicationEngine.java | 14 +++++++++++---
.../communication/DatabaseCommunicationEngineFactory.java | 6 ++----
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 9d52c60..e0ef45e 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -38,6 +38,7 @@ import
org.apache.shardingsphere.infra.metadata.schema.refresher.SchemaRefresher
import
org.apache.shardingsphere.infra.metadata.schema.refresher.spi.SchemaChangedNotifier;
import org.apache.shardingsphere.infra.rule.type.DataNodeContainedRule;
import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
+import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseData;
import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
@@ -61,18 +62,25 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public final class DatabaseCommunicationEngine {
- private final LogicSQL logicSQL;
-
private final ShardingSphereMetaData metaData;
+ private final LogicSQL logicSQL;
+
private final ProxySQLExecutor proxySQLExecutor;
- private final KernelProcessor kernelProcessor = new KernelProcessor();
+ private final KernelProcessor kernelProcessor;
private List<QueryHeader> queryHeaders;
private MergedResult mergedResult;
+ public DatabaseCommunicationEngine(final String type, final
ShardingSphereMetaData metaData, final LogicSQL logicSQL, final
BackendConnection backendConnection) {
+ this.metaData = metaData;
+ this.logicSQL = logicSQL;
+ proxySQLExecutor = new ProxySQLExecutor(type, backendConnection);
+ kernelProcessor = new KernelProcessor();
+ }
+
/**
* Execute to database.
*
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 5756251..0401216 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
@@ -60,8 +60,7 @@ public final class DatabaseCommunicationEngineFactory {
public DatabaseCommunicationEngine newTextProtocolInstance(final
SQLStatement sqlStatement, final String sql, final BackendConnection
backendConnection) {
ShardingSphereMetaData metaData =
ProxyContext.getInstance().getMetaData(backendConnection.getSchemaName());
LogicSQL logicSQL = createLogicSQL(sqlStatement, sql,
Collections.emptyList(), metaData);
- ProxySQLExecutor proxySQLExecutor = new
ProxySQLExecutor(JDBCExecutionUnitBuilderType.STATEMENT, backendConnection);
- return new DatabaseCommunicationEngine(logicSQL, metaData,
proxySQLExecutor);
+ return new
DatabaseCommunicationEngine(JDBCExecutionUnitBuilderType.STATEMENT, metaData,
logicSQL, backendConnection);
}
/**
@@ -76,8 +75,7 @@ public final class DatabaseCommunicationEngineFactory {
public DatabaseCommunicationEngine newBinaryProtocolInstance(final
SQLStatement sqlStatement, final String sql, final List<Object> parameters,
final BackendConnection backendConnection) {
ShardingSphereMetaData metaData =
ProxyContext.getInstance().getMetaData(backendConnection.getSchemaName());
LogicSQL logicSQL = createLogicSQL(sqlStatement, sql, new
ArrayList<>(parameters), metaData);
- ProxySQLExecutor proxySQLExecutor = new
ProxySQLExecutor(JDBCExecutionUnitBuilderType.PREPARED_STATEMENT,
backendConnection);
- return new DatabaseCommunicationEngine(logicSQL, metaData,
proxySQLExecutor);
+ return new
DatabaseCommunicationEngine(JDBCExecutionUnitBuilderType.PREPARED_STATEMENT,
metaData, logicSQL, backendConnection);
}
private LogicSQL createLogicSQL(final SQLStatement sqlStatement, final
String sql, final List<Object> parameters, final ShardingSphereMetaData
metaData) {