From 320c370bd00e005d7b33ddae88c63701a82c68b6 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 23 Sep 2018 15:17:05 +0800 Subject: [PATCH] for #1205, refactor constructor of SQLExecutePrepareTemplate --- .../executor/sql/prepare/SQLExecutePrepareTemplate.java | 8 ++++---- .../core/executor/AbstractStatementExecutor.java | 4 ++-- .../proxy/backend/jdbc/execute/JDBCExecuteEngine.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/executor/sql/prepare/SQLExecutePrepareTemplate.java b/sharding-core/src/main/java/io/shardingsphere/core/executor/sql/prepare/SQLExecutePrepareTemplate.java index 2ae26810b69a9..57a6cd3779be1 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/executor/sql/prepare/SQLExecutePrepareTemplate.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/executor/sql/prepare/SQLExecutePrepareTemplate.java @@ -25,6 +25,7 @@ import io.shardingsphere.core.executor.StatementExecuteUnit; import io.shardingsphere.core.routing.RouteUnit; import io.shardingsphere.core.routing.SQLUnit; +import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import java.sql.Connection; @@ -44,13 +45,12 @@ * @author panjuan */ @RequiredArgsConstructor +@AllArgsConstructor public final class SQLExecutePrepareTemplate { private final int maxConnectionsSizePerQuery; - private final boolean synchronizedExecute; - - private final ShardingExecuteEngine shardingExecuteEngine; + private ShardingExecuteEngine shardingExecuteEngine; /** * Get execute unit groups. @@ -61,7 +61,7 @@ public final class SQLExecutePrepareTemplate { * @throws SQLException SQL exception */ public Collection> getExecuteUnitGroups(final Collection routeUnits, final SQLExecutePrepareCallback callback) throws SQLException { - return synchronizedExecute ? getSynchronizedExecuteUnitGroups(routeUnits, callback) : getAsynchronizedExecuteUnitGroups(routeUnits, callback); + return null == shardingExecuteEngine ? getSynchronizedExecuteUnitGroups(routeUnits, callback) : getAsynchronizedExecuteUnitGroups(routeUnits, callback); } private Collection> getSynchronizedExecuteUnitGroups( diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java index 4560a3e23fb2c..c0614e7065f57 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java @@ -88,8 +88,8 @@ public AbstractStatementExecutor(final int resultSetType, final int resultSetCon this.resultSetConcurrency = resultSetConcurrency; this.resultSetHoldability = resultSetHoldability; this.connection = shardingConnection; - sqlExecutePrepareTemplate = new SQLExecutePrepareTemplate( - connection.getShardingContext().getMaxConnectionsSizePerQuery(), TransactionType.XA == TransactionTypeHolder.get(), connection.getShardingContext().getExecuteEngine()); + sqlExecutePrepareTemplate = TransactionType.XA == TransactionTypeHolder.get() ? new SQLExecutePrepareTemplate(connection.getShardingContext().getMaxConnectionsSizePerQuery()) + : new SQLExecutePrepareTemplate(connection.getShardingContext().getMaxConnectionsSizePerQuery(), connection.getShardingContext().getExecuteEngine()); sqlExecuteTemplate = new SQLExecuteTemplate(connection.getShardingContext().getExecuteEngine()); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java index 9f68c072540c4..f820e4784b914 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java @@ -97,8 +97,8 @@ public final class JDBCExecuteEngine implements SQLExecuteEngine { public JDBCExecuteEngine(final BackendConnection backendConnection, final JDBCExecutorWrapper jdbcExecutorWrapper) { this.backendConnection = backendConnection; this.jdbcExecutorWrapper = jdbcExecutorWrapper; - sqlExecutePrepareTemplate = new SQLExecutePrepareTemplate(ProxyContext.getInstance().getMaxConnectionsSizePerQuery(), - TransactionType.XA == ProxyContext.getInstance().getTransactionType(), BackendExecutorContext.getInstance().getExecuteEngine()); + sqlExecutePrepareTemplate = TransactionType.XA == ProxyContext.getInstance().getTransactionType() ? new SQLExecutePrepareTemplate(ProxyContext.getInstance().getMaxConnectionsSizePerQuery()) + : new SQLExecutePrepareTemplate(ProxyContext.getInstance().getMaxConnectionsSizePerQuery(), BackendExecutorContext.getInstance().getExecuteEngine()); sqlExecuteTemplate = new SQLExecuteTemplate(BackendExecutorContext.getInstance().getExecuteEngine()); }