Skip to content

Commit

Permalink
for #1205, refactor constructor of SQLExecutePrepareTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 23, 2018
1 parent dd46bb9 commit 320c370
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -61,7 +61,7 @@ public final class SQLExecutePrepareTemplate {
* @throws SQLException SQL exception
*/
public Collection<ShardingExecuteGroup<StatementExecuteUnit>> getExecuteUnitGroups(final Collection<RouteUnit> 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<ShardingExecuteGroup<StatementExecuteUnit>> getSynchronizedExecuteUnitGroups(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 320c370

Please sign in to comment.