This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 674d598 Minor change for DatabaseCommunicationEngineFactory (#8163)
674d598 is described below
commit 674d5980ac904cb6622adc6c668905b48d65c7d6
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Nov 15 14:04:20 2020 +0800
Minor change for DatabaseCommunicationEngineFactory (#8163)
* Refactor DatabaseCommunicationEngineFactory
* revise javadoc
---
.../communication/DatabaseCommunicationEngine.java | 2 +-
.../DatabaseCommunicationEngineFactory.java | 24 ++++++++++++++--------
2 files changed, 17 insertions(+), 9 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 a396b34..10ad767 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
@@ -28,7 +28,7 @@ import java.sql.SQLException;
public interface DatabaseCommunicationEngine {
/**
- * Execute command.
+ * Execute to database.
*
* @return backend response
* @throws SQLException SQL exception
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 5a7d62a..89897b8 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
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.proxy.backend.communication;
+import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.LogicSQL;
@@ -61,9 +62,10 @@ public final class DatabaseCommunicationEngineFactory {
* @return text protocol backend handler
*/
public DatabaseCommunicationEngine newTextProtocolInstance(final
SQLStatement sqlStatement, final String sql, final BackendConnection
backendConnection) {
- LogicSQL logicSQL = createLogicSQL(sqlStatement, sql,
Collections.emptyList(), backendConnection);
- return new JDBCDatabaseCommunicationEngine(
- logicSQL,
ProxyContext.getInstance().getMetaData(backendConnection.getSchemaName()), new
JDBCExecuteEngine(backendConnection, new StatementAccessor()));
+ ShardingSphereMetaData metaData = getMetaData(backendConnection);
+ LogicSQL logicSQL = createLogicSQL(sqlStatement, sql,
Collections.emptyList(), metaData);
+ JDBCExecuteEngine jdbcExecuteEngine = new
JDBCExecuteEngine(backendConnection, new StatementAccessor());
+ return new JDBCDatabaseCommunicationEngine(logicSQL, metaData,
jdbcExecuteEngine);
}
/**
@@ -76,13 +78,19 @@ public final class DatabaseCommunicationEngineFactory {
* @return binary protocol backend handler
*/
public DatabaseCommunicationEngine newBinaryProtocolInstance(final
SQLStatement sqlStatement, final String sql, final List<Object> parameters,
final BackendConnection backendConnection) {
- LogicSQL logicSQL = createLogicSQL(sqlStatement, sql, new
ArrayList<>(parameters), backendConnection);
- return new JDBCDatabaseCommunicationEngine(
- logicSQL,
ProxyContext.getInstance().getMetaData(backendConnection.getSchemaName()), new
JDBCExecuteEngine(backendConnection, new PreparedStatementAccessor()));
+ ShardingSphereMetaData metaData = getMetaData(backendConnection);
+ LogicSQL logicSQL = createLogicSQL(sqlStatement, sql, new
ArrayList<>(parameters), metaData);
+ JDBCExecuteEngine jdbcExecuteEngine = new
JDBCExecuteEngine(backendConnection, new PreparedStatementAccessor());
+ return new JDBCDatabaseCommunicationEngine(logicSQL, metaData,
jdbcExecuteEngine);
}
- private LogicSQL createLogicSQL(final SQLStatement sqlStatement, final
String sql, final List<Object> parameters, final BackendConnection
backendConnection) {
- ShardingSphereMetaData metaData =
ProxyContext.getInstance().getMetaData(backendConnection.getSchemaName());
+ private ShardingSphereMetaData getMetaData(final BackendConnection
backendConnection) {
+ ShardingSphereMetaData result =
ProxyContext.getInstance().getMetaData(backendConnection.getSchemaName());
+ Preconditions.checkNotNull(result);
+ return result;
+ }
+
+ private LogicSQL createLogicSQL(final SQLStatement sqlStatement, final
String sql, final List<Object> parameters, final ShardingSphereMetaData
metaData) {
SQLStatementContext<?> sqlStatementContext =
SQLStatementContextFactory.newInstance(metaData.getSchema(), parameters,
sqlStatement);
return new LogicSQL(sqlStatementContext, sql, parameters);
}