Loading sharding-jdbc/src/main/java/io/shardingsphere/core/executor/SQLExecuteCallback.java +3 −3 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ import java.util.Map; * @param <T> class type of return value */ @RequiredArgsConstructor public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<BaseStatementUnit, T> { public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<StatementExecuteUnit, T> { private final SQLType sqlType; Loading @@ -51,7 +51,7 @@ public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<B private final EventBus shardingEventBus = ShardingEventBusInstance.getInstance(); @Override public final T execute(final BaseStatementUnit input) throws Exception { public final T execute(final StatementExecuteUnit input) throws Exception { ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); ExecutorDataMap.setDataMap(dataMap); List<SQLExecutionEvent> events = new LinkedList<>(); Loading @@ -77,5 +77,5 @@ public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<B } } protected abstract T executeSQL(BaseStatementUnit baseStatementUnit) throws SQLException; protected abstract T executeSQL(StatementExecuteUnit executeUnit) throws SQLException; } sharding-jdbc/src/main/java/io/shardingsphere/core/executor/SQLExecutorEngine.java +10 −10 Original line number Diff line number Diff line Loading @@ -54,18 +54,18 @@ public final class SQLExecutorEngine implements AutoCloseable { /** * Execute. * * @param baseStatementUnits statement execute units * @param executeCallback prepared statement execute callback * @param executeUnits execute units * @param executeCallback execute callback * @param <T> class type of return value * @return execute result * @throws SQLException SQL exception */ public <T> List<T> execute(final Collection<? extends BaseStatementUnit> baseStatementUnits, final SQLExecuteCallback<T> executeCallback) throws SQLException { OverallExecutionEvent event = new OverallExecutionEvent(baseStatementUnits.size() > 1); public <T> List<T> execute(final Collection<? extends StatementExecuteUnit> executeUnits, final SQLExecuteCallback<T> executeCallback) throws SQLException { OverallExecutionEvent event = new OverallExecutionEvent(executeUnits.size() > 1); ShardingEventBusInstance.getInstance().post(event); try { List<T> result = ConnectionMode.MEMORY_STRICTLY == connectionMode ? shardingExecuteEngine.execute(new LinkedList<>(baseStatementUnits), executeCallback) : shardingExecuteEngine.groupExecute(getBaseStatementUnitGroups(baseStatementUnits), executeCallback); List<T> result = ConnectionMode.MEMORY_STRICTLY == connectionMode ? shardingExecuteEngine.execute(new LinkedList<>(executeUnits), executeCallback) : shardingExecuteEngine.groupExecute(getExecuteUnitGroups(executeUnits), executeCallback); event.setExecuteSuccess(); return result; // CHECKSTYLE:OFF Loading @@ -79,12 +79,12 @@ public final class SQLExecutorEngine implements AutoCloseable { } } private Map<String, Collection<BaseStatementUnit>> getBaseStatementUnitGroups(final Collection<? extends BaseStatementUnit> baseStatementUnits) { Map<String, Collection<BaseStatementUnit>> result = new LinkedHashMap<>(baseStatementUnits.size(), 1); for (BaseStatementUnit each : baseStatementUnits) { private Map<String, Collection<StatementExecuteUnit>> getExecuteUnitGroups(final Collection<? extends StatementExecuteUnit> executeUnits) { Map<String, Collection<StatementExecuteUnit>> result = new LinkedHashMap<>(executeUnits.size(), 1); for (StatementExecuteUnit each : executeUnits) { String dataSourceName = each.getSqlExecutionUnit().getDataSource(); if (!result.keySet().contains(dataSourceName)) { result.put(dataSourceName, new LinkedList<BaseStatementUnit>()); result.put(dataSourceName, new LinkedList<StatementExecuteUnit>()); } result.get(dataSourceName).add(each); } Loading sharding-jdbc/src/main/java/io/shardingsphere/core/executor/BaseStatementUnit.java→sharding-jdbc/src/main/java/io/shardingsphere/core/executor/StatementExecuteUnit.java +2 −2 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import io.shardingsphere.core.routing.SQLExecutionUnit; import java.sql.Statement; /** * Statement execute unit interface. * Statement execute unit. * * @author zhangliang */ public interface BaseStatementUnit { public interface StatementExecuteUnit { /** * Get SQL execute unit. Loading sharding-jdbc/src/main/java/io/shardingsphere/core/executor/event/sql/SQLExecutionEventFactory.java +6 −6 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package io.shardingsphere.core.executor.event.sql; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.BaseStatementUnit; import io.shardingsphere.core.executor.StatementExecuteUnit; import lombok.AccessLevel; import lombok.NoArgsConstructor; Loading @@ -37,17 +37,17 @@ public final class SQLExecutionEventFactory { * Create SQL execution event. * * @param sqlType SQL type * @param baseStatementUnit statement unit * @param executeUnit execute unit * @param parameters parameters * @return SQL execution event */ public static SQLExecutionEvent createEvent(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final List<Object> parameters) { public static SQLExecutionEvent createEvent(final SQLType sqlType, final StatementExecuteUnit executeUnit, final List<Object> parameters) { if (SQLType.DQL == sqlType) { return new DQLExecutionEvent(baseStatementUnit.getSqlExecutionUnit().getDataSource(), baseStatementUnit.getSqlExecutionUnit().getSqlUnit(), parameters); return new DQLExecutionEvent(executeUnit.getSqlExecutionUnit().getDataSource(), executeUnit.getSqlExecutionUnit().getSqlUnit(), parameters); } if (SQLType.DML == sqlType) { return new DMLExecutionEvent(baseStatementUnit.getSqlExecutionUnit().getDataSource(), baseStatementUnit.getSqlExecutionUnit().getSqlUnit(), parameters); return new DMLExecutionEvent(executeUnit.getSqlExecutionUnit().getDataSource(), executeUnit.getSqlExecutionUnit().getSqlUnit(), parameters); } return new SQLExecutionEvent(baseStatementUnit.getSqlExecutionUnit().getDataSource(), baseStatementUnit.getSqlExecutionUnit().getSqlUnit(), parameters); return new SQLExecutionEvent(executeUnit.getSqlExecutionUnit().getDataSource(), executeUnit.getSqlExecutionUnit().getSqlUnit(), parameters); } } sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/batch/BatchPreparedStatementExecutor.java +3 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package io.shardingsphere.core.executor.type.batch; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.BaseStatementUnit; import io.shardingsphere.core.executor.StatementExecuteUnit; import io.shardingsphere.core.executor.SQLExecuteCallback; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap; Loading Loading @@ -62,8 +62,8 @@ public final class BatchPreparedStatementExecutor { SQLExecuteCallback<int[]> callback = new SQLExecuteCallback<int[]>(sqlType, isExceptionThrown, dataMap) { @Override protected int[] executeSQL(final BaseStatementUnit baseStatementUnit) throws SQLException { return baseStatementUnit.getStatement().executeBatch(); protected int[] executeSQL(final StatementExecuteUnit executeUnit) throws SQLException { return executeUnit.getStatement().executeBatch(); } }; return accumulate(executorEngine.execute(batchPreparedStatementUnits, callback)); Loading Loading
sharding-jdbc/src/main/java/io/shardingsphere/core/executor/SQLExecuteCallback.java +3 −3 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ import java.util.Map; * @param <T> class type of return value */ @RequiredArgsConstructor public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<BaseStatementUnit, T> { public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<StatementExecuteUnit, T> { private final SQLType sqlType; Loading @@ -51,7 +51,7 @@ public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<B private final EventBus shardingEventBus = ShardingEventBusInstance.getInstance(); @Override public final T execute(final BaseStatementUnit input) throws Exception { public final T execute(final StatementExecuteUnit input) throws Exception { ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); ExecutorDataMap.setDataMap(dataMap); List<SQLExecutionEvent> events = new LinkedList<>(); Loading @@ -77,5 +77,5 @@ public abstract class SQLExecuteCallback<T> implements ShardingExecuteCallback<B } } protected abstract T executeSQL(BaseStatementUnit baseStatementUnit) throws SQLException; protected abstract T executeSQL(StatementExecuteUnit executeUnit) throws SQLException; }
sharding-jdbc/src/main/java/io/shardingsphere/core/executor/SQLExecutorEngine.java +10 −10 Original line number Diff line number Diff line Loading @@ -54,18 +54,18 @@ public final class SQLExecutorEngine implements AutoCloseable { /** * Execute. * * @param baseStatementUnits statement execute units * @param executeCallback prepared statement execute callback * @param executeUnits execute units * @param executeCallback execute callback * @param <T> class type of return value * @return execute result * @throws SQLException SQL exception */ public <T> List<T> execute(final Collection<? extends BaseStatementUnit> baseStatementUnits, final SQLExecuteCallback<T> executeCallback) throws SQLException { OverallExecutionEvent event = new OverallExecutionEvent(baseStatementUnits.size() > 1); public <T> List<T> execute(final Collection<? extends StatementExecuteUnit> executeUnits, final SQLExecuteCallback<T> executeCallback) throws SQLException { OverallExecutionEvent event = new OverallExecutionEvent(executeUnits.size() > 1); ShardingEventBusInstance.getInstance().post(event); try { List<T> result = ConnectionMode.MEMORY_STRICTLY == connectionMode ? shardingExecuteEngine.execute(new LinkedList<>(baseStatementUnits), executeCallback) : shardingExecuteEngine.groupExecute(getBaseStatementUnitGroups(baseStatementUnits), executeCallback); List<T> result = ConnectionMode.MEMORY_STRICTLY == connectionMode ? shardingExecuteEngine.execute(new LinkedList<>(executeUnits), executeCallback) : shardingExecuteEngine.groupExecute(getExecuteUnitGroups(executeUnits), executeCallback); event.setExecuteSuccess(); return result; // CHECKSTYLE:OFF Loading @@ -79,12 +79,12 @@ public final class SQLExecutorEngine implements AutoCloseable { } } private Map<String, Collection<BaseStatementUnit>> getBaseStatementUnitGroups(final Collection<? extends BaseStatementUnit> baseStatementUnits) { Map<String, Collection<BaseStatementUnit>> result = new LinkedHashMap<>(baseStatementUnits.size(), 1); for (BaseStatementUnit each : baseStatementUnits) { private Map<String, Collection<StatementExecuteUnit>> getExecuteUnitGroups(final Collection<? extends StatementExecuteUnit> executeUnits) { Map<String, Collection<StatementExecuteUnit>> result = new LinkedHashMap<>(executeUnits.size(), 1); for (StatementExecuteUnit each : executeUnits) { String dataSourceName = each.getSqlExecutionUnit().getDataSource(); if (!result.keySet().contains(dataSourceName)) { result.put(dataSourceName, new LinkedList<BaseStatementUnit>()); result.put(dataSourceName, new LinkedList<StatementExecuteUnit>()); } result.get(dataSourceName).add(each); } Loading
sharding-jdbc/src/main/java/io/shardingsphere/core/executor/BaseStatementUnit.java→sharding-jdbc/src/main/java/io/shardingsphere/core/executor/StatementExecuteUnit.java +2 −2 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import io.shardingsphere.core.routing.SQLExecutionUnit; import java.sql.Statement; /** * Statement execute unit interface. * Statement execute unit. * * @author zhangliang */ public interface BaseStatementUnit { public interface StatementExecuteUnit { /** * Get SQL execute unit. Loading
sharding-jdbc/src/main/java/io/shardingsphere/core/executor/event/sql/SQLExecutionEventFactory.java +6 −6 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ package io.shardingsphere.core.executor.event.sql; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.BaseStatementUnit; import io.shardingsphere.core.executor.StatementExecuteUnit; import lombok.AccessLevel; import lombok.NoArgsConstructor; Loading @@ -37,17 +37,17 @@ public final class SQLExecutionEventFactory { * Create SQL execution event. * * @param sqlType SQL type * @param baseStatementUnit statement unit * @param executeUnit execute unit * @param parameters parameters * @return SQL execution event */ public static SQLExecutionEvent createEvent(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final List<Object> parameters) { public static SQLExecutionEvent createEvent(final SQLType sqlType, final StatementExecuteUnit executeUnit, final List<Object> parameters) { if (SQLType.DQL == sqlType) { return new DQLExecutionEvent(baseStatementUnit.getSqlExecutionUnit().getDataSource(), baseStatementUnit.getSqlExecutionUnit().getSqlUnit(), parameters); return new DQLExecutionEvent(executeUnit.getSqlExecutionUnit().getDataSource(), executeUnit.getSqlExecutionUnit().getSqlUnit(), parameters); } if (SQLType.DML == sqlType) { return new DMLExecutionEvent(baseStatementUnit.getSqlExecutionUnit().getDataSource(), baseStatementUnit.getSqlExecutionUnit().getSqlUnit(), parameters); return new DMLExecutionEvent(executeUnit.getSqlExecutionUnit().getDataSource(), executeUnit.getSqlExecutionUnit().getSqlUnit(), parameters); } return new SQLExecutionEvent(baseStatementUnit.getSqlExecutionUnit().getDataSource(), baseStatementUnit.getSqlExecutionUnit().getSqlUnit(), parameters); return new SQLExecutionEvent(executeUnit.getSqlExecutionUnit().getDataSource(), executeUnit.getSqlExecutionUnit().getSqlUnit(), parameters); } }
sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/batch/BatchPreparedStatementExecutor.java +3 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package io.shardingsphere.core.executor.type.batch; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.BaseStatementUnit; import io.shardingsphere.core.executor.StatementExecuteUnit; import io.shardingsphere.core.executor.SQLExecuteCallback; import io.shardingsphere.core.executor.SQLExecutorEngine; import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap; Loading Loading @@ -62,8 +62,8 @@ public final class BatchPreparedStatementExecutor { SQLExecuteCallback<int[]> callback = new SQLExecuteCallback<int[]>(sqlType, isExceptionThrown, dataMap) { @Override protected int[] executeSQL(final BaseStatementUnit baseStatementUnit) throws SQLException { return baseStatementUnit.getStatement().executeBatch(); protected int[] executeSQL(final StatementExecuteUnit executeUnit) throws SQLException { return executeUnit.getStatement().executeBatch(); } }; return accumulate(executorEngine.execute(batchPreparedStatementUnits, callback)); Loading