提交 e2f40943 编写于 作者: T terrymanu

simplify AbstractExecutorWrapper 4rd version

上级 8aef60d4
...@@ -22,17 +22,17 @@ import com.dangdang.ddframe.rdb.sharding.constant.SQLType; ...@@ -22,17 +22,17 @@ import com.dangdang.ddframe.rdb.sharding.constant.SQLType;
import com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEvent; import com.dangdang.ddframe.rdb.sharding.executor.event.DMLExecutionEvent;
import com.dangdang.ddframe.rdb.sharding.executor.event.DQLExecutionEvent; import com.dangdang.ddframe.rdb.sharding.executor.event.DQLExecutionEvent;
import com.dangdang.ddframe.rdb.sharding.executor.event.ExecutionEvent; import com.dangdang.ddframe.rdb.sharding.executor.event.ExecutionEvent;
import com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper;
import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext; import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext;
import com.dangdang.ddframe.rdb.sharding.routing.SQLExecutionUnit;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
/** /**
* 多线程执行静态语句对象请求的执行器. * 多线程执行静态语句对象请求的执行器.
...@@ -48,7 +48,7 @@ public final class StatementExecutor { ...@@ -48,7 +48,7 @@ public final class StatementExecutor {
private final SQLType sqlType; private final SQLType sqlType;
private final Collection<StatementExecutorWrapper> statementExecutorWrappers; private final Map<SQLExecutionUnit, Statement> statements;
private final EventPostman eventPostman = new EventPostman(); private final EventPostman eventPostman = new EventPostman();
...@@ -63,15 +63,16 @@ public final class StatementExecutor { ...@@ -63,15 +63,16 @@ public final class StatementExecutor {
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap(); final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
List<ResultSet> result; List<ResultSet> result;
try { try {
if (1 == statementExecutorWrappers.size()) { if (1 == statements.size()) {
return Collections.singletonList(executeQueryInternal(statementExecutorWrappers.iterator().next(), isExceptionThrown, dataMap)); Entry<SQLExecutionUnit, Statement> entry = statements.entrySet().iterator().next();
return Collections.singletonList(executeQueryInternal(entry.getKey(), entry.getValue(), isExceptionThrown, dataMap));
} }
result = executorEngine.execute(statementExecutorWrappers, new ExecuteUnit<StatementExecutorWrapper, ResultSet>() { result = executorEngine.execute(statements.entrySet(), new ExecuteUnit<Entry<SQLExecutionUnit, Statement>, ResultSet>() {
@Override @Override
public ResultSet execute(final StatementExecutorWrapper input) throws Exception { public ResultSet execute(final Entry<SQLExecutionUnit, Statement> input) throws Exception {
synchronized (input.getStatement().getConnection()) { synchronized (input.getValue().getConnection()) {
return executeQueryInternal(input, isExceptionThrown, dataMap); return executeQueryInternal(input.getKey(), input.getValue(), isExceptionThrown, dataMap);
} }
} }
}); });
...@@ -81,14 +82,14 @@ public final class StatementExecutor { ...@@ -81,14 +82,14 @@ public final class StatementExecutor {
return result; return result;
} }
private ResultSet executeQueryInternal(final StatementExecutorWrapper statementExecutorWrapper, final boolean isExceptionThrown, final Map<String, Object> dataMap) { private ResultSet executeQueryInternal(final SQLExecutionUnit sqlExecutionUnit, final Statement statement, final boolean isExceptionThrown, final Map<String, Object> dataMap) {
ResultSet result; ResultSet result;
ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown);
ExecutorDataMap.setDataMap(dataMap); ExecutorDataMap.setDataMap(dataMap);
ExecutionEvent event = getExecutionEvent(statementExecutorWrapper); ExecutionEvent event = getExecutionEvent(sqlExecutionUnit);
eventPostman.post(event); eventPostman.post(event);
try { try {
result = statementExecutorWrapper.getStatement().executeQuery(statementExecutorWrapper.getSqlExecutionUnit().getSql()); result = statement.executeQuery(sqlExecutionUnit.getSql());
} catch (final SQLException ex) { } catch (final SQLException ex) {
eventPostman.postForExecuteFailure(event, ex); eventPostman.postForExecuteFailure(event, ex);
ExecutorExceptionHandler.handleException(ex); ExecutorExceptionHandler.handleException(ex);
...@@ -148,15 +149,16 @@ public final class StatementExecutor { ...@@ -148,15 +149,16 @@ public final class StatementExecutor {
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap(); final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
try { try {
if (1 == statementExecutorWrappers.size()) { if (1 == statements.size()) {
return executeUpdateInternal(updater, statementExecutorWrappers.iterator().next(), isExceptionThrown, dataMap); Entry<SQLExecutionUnit, Statement> entry = statements.entrySet().iterator().next();
return executeUpdateInternal(updater, entry.getKey(), entry.getValue(), isExceptionThrown, dataMap);
} }
return executorEngine.execute(statementExecutorWrappers, new ExecuteUnit<StatementExecutorWrapper, Integer>() { return executorEngine.execute(statements.entrySet(), new ExecuteUnit<Entry<SQLExecutionUnit, Statement>, Integer>() {
@Override @Override
public Integer execute(final StatementExecutorWrapper input) throws Exception { public Integer execute(final Entry<SQLExecutionUnit, Statement> input) throws Exception {
synchronized (input.getStatement().getConnection()) { synchronized (input.getValue().getConnection()) {
return executeUpdateInternal(updater, input, isExceptionThrown, dataMap); return executeUpdateInternal(updater, input.getKey(), input.getValue(), isExceptionThrown, dataMap);
} }
} }
}, new MergeUnit<Integer, Integer>() { }, new MergeUnit<Integer, Integer>() {
...@@ -178,14 +180,14 @@ public final class StatementExecutor { ...@@ -178,14 +180,14 @@ public final class StatementExecutor {
} }
} }
private int executeUpdateInternal(final Updater updater, final StatementExecutorWrapper statementExecutorWrapper, final boolean isExceptionThrown, final Map<String, Object> dataMap) { private int executeUpdateInternal(final Updater updater, final SQLExecutionUnit sqlExecutionUnit, final Statement statement, final boolean isExceptionThrown, final Map<String, Object> dataMap) {
int result; int result;
ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown);
ExecutorDataMap.setDataMap(dataMap); ExecutorDataMap.setDataMap(dataMap);
ExecutionEvent event = getExecutionEvent(statementExecutorWrapper); ExecutionEvent event = getExecutionEvent(sqlExecutionUnit);
eventPostman.post(event); eventPostman.post(event);
try { try {
result = updater.executeUpdate(statementExecutorWrapper.getStatement(), statementExecutorWrapper.getSqlExecutionUnit().getSql()); result = updater.executeUpdate(statement, sqlExecutionUnit.getSql());
} catch (final SQLException ex) { } catch (final SQLException ex) {
eventPostman.postForExecuteFailure(event, ex); eventPostman.postForExecuteFailure(event, ex);
ExecutorExceptionHandler.handleException(ex); ExecutorExceptionHandler.handleException(ex);
...@@ -245,15 +247,16 @@ public final class StatementExecutor { ...@@ -245,15 +247,16 @@ public final class StatementExecutor {
final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
final Map<String, Object> dataMap = ExecutorDataMap.getDataMap(); final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
try { try {
if (1 == statementExecutorWrappers.size()) { if (1 == statements.size()) {
return executeInternal(executor, statementExecutorWrappers.iterator().next(), isExceptionThrown, dataMap); Entry<SQLExecutionUnit, Statement> entry = statements.entrySet().iterator().next();
return executeInternal(executor, entry.getKey(), entry.getValue(), isExceptionThrown, dataMap);
} }
List<Boolean> result = executorEngine.execute(statementExecutorWrappers, new ExecuteUnit<StatementExecutorWrapper, Boolean>() { List<Boolean> result = executorEngine.execute(statements.entrySet(), new ExecuteUnit<Entry<SQLExecutionUnit, Statement>, Boolean>() {
@Override @Override
public Boolean execute(final StatementExecutorWrapper input) throws Exception { public Boolean execute(final Entry<SQLExecutionUnit, Statement> input) throws Exception {
synchronized (input.getStatement().getConnection()) { synchronized (input.getValue().getConnection()) {
return executeInternal(executor, input, isExceptionThrown, dataMap); return executeInternal(executor, input.getKey(), input.getValue(), isExceptionThrown, dataMap);
} }
} }
}); });
...@@ -263,14 +266,14 @@ public final class StatementExecutor { ...@@ -263,14 +266,14 @@ public final class StatementExecutor {
} }
} }
private boolean executeInternal(final Executor executor, final StatementExecutorWrapper statementExecutorWrapper, final boolean isExceptionThrown, final Map<String, Object> dataMap) { private boolean executeInternal(final Executor executor, final SQLExecutionUnit sqlExecutionUnit, final Statement statement, final boolean isExceptionThrown, final Map<String, Object> dataMap) {
boolean result; boolean result;
ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown);
ExecutorDataMap.setDataMap(dataMap); ExecutorDataMap.setDataMap(dataMap);
ExecutionEvent event = getExecutionEvent(statementExecutorWrapper); ExecutionEvent event = getExecutionEvent(sqlExecutionUnit);
eventPostman.post(event); eventPostman.post(event);
try { try {
result = executor.execute(statementExecutorWrapper.getStatement(), statementExecutorWrapper.getSqlExecutionUnit().getSql()); result = executor.execute(statement, sqlExecutionUnit.getSql());
} catch (final SQLException ex) { } catch (final SQLException ex) {
eventPostman.postForExecuteFailure(event, ex); eventPostman.postForExecuteFailure(event, ex);
ExecutorExceptionHandler.handleException(ex); ExecutorExceptionHandler.handleException(ex);
...@@ -280,12 +283,12 @@ public final class StatementExecutor { ...@@ -280,12 +283,12 @@ public final class StatementExecutor {
return result; return result;
} }
private ExecutionEvent getExecutionEvent(final StatementExecutorWrapper statementExecutorWrapper) { private ExecutionEvent getExecutionEvent(final SQLExecutionUnit sqlExecutionUnit) {
ExecutionEvent event; ExecutionEvent event;
if (SQLType.SELECT == sqlType) { if (SQLType.SELECT == sqlType) {
event = new DQLExecutionEvent(statementExecutorWrapper.getSqlExecutionUnit().getDataSource(), statementExecutorWrapper.getSqlExecutionUnit().getSql()); event = new DQLExecutionEvent(sqlExecutionUnit.getDataSource(), sqlExecutionUnit.getSql());
} else { } else {
event = new DMLExecutionEvent(statementExecutorWrapper.getSqlExecutionUnit().getDataSource(), statementExecutorWrapper.getSqlExecutionUnit().getSql()); event = new DMLExecutionEvent(sqlExecutionUnit.getDataSource(), sqlExecutionUnit.getSql());
} }
return event; return event;
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package com.dangdang.ddframe.rdb.sharding.jdbc.core.statement; package com.dangdang.ddframe.rdb.sharding.jdbc.core.statement;
import com.dangdang.ddframe.rdb.sharding.executor.StatementExecutor; import com.dangdang.ddframe.rdb.sharding.executor.StatementExecutor;
import com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper;
import com.dangdang.ddframe.rdb.sharding.jdbc.adapter.AbstractStatementAdapter; import com.dangdang.ddframe.rdb.sharding.jdbc.adapter.AbstractStatementAdapter;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.connection.ShardingConnection; import com.dangdang.ddframe.rdb.sharding.jdbc.core.connection.ShardingConnection;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.resultset.GeneratedKeysResultSet; import com.dangdang.ddframe.rdb.sharding.jdbc.core.resultset.GeneratedKeysResultSet;
...@@ -39,8 +38,10 @@ import java.sql.SQLException; ...@@ -39,8 +38,10 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 支持分片的静态语句对象. * 支持分片的静态语句对象.
...@@ -198,15 +199,15 @@ public class ShardingStatement extends AbstractStatementAdapter { ...@@ -198,15 +199,15 @@ public class ShardingStatement extends AbstractStatementAdapter {
private StatementExecutor generateExecutor(final String sql) throws SQLException { private StatementExecutor generateExecutor(final String sql) throws SQLException {
clearPrevious(); clearPrevious();
routeResult = new StatementRoutingEngine(shardingConnection.getShardingContext()).route(sql); routeResult = new StatementRoutingEngine(shardingConnection.getShardingContext()).route(sql);
Collection<StatementExecutorWrapper> statementExecutorWrappers = new LinkedList<>(); Map<SQLExecutionUnit, Statement> statements = new HashMap<>(routeResult.getExecutionUnits().size(), 1);
for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { for (SQLExecutionUnit each : routeResult.getExecutionUnits()) {
Statement statement = shardingConnection.getConnection( Statement statement = shardingConnection.getConnection(
each.getDataSource(), routeResult.getSqlStatement().getType()).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); each.getDataSource(), routeResult.getSqlStatement().getType()).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
replayMethodsInvocation(statement); replayMethodsInvocation(statement);
statementExecutorWrappers.add(new StatementExecutorWrapper(statement, each)); statements.put(each, statement);
routedStatements.add(statement); routedStatements.add(statement);
} }
return new StatementExecutor(shardingConnection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), statementExecutorWrappers); return new StatementExecutor(shardingConnection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), statements);
} }
private void clearPrevious() throws SQLException { private void clearPrevious() throws SQLException {
......
...@@ -195,6 +195,7 @@ public final class ShardingPreparedStatement extends AbstractPreparedStatementAd ...@@ -195,6 +195,7 @@ public final class ShardingPreparedStatement extends AbstractPreparedStatementAd
private PreparedStatementExecutorWrapper wrap(final PreparedStatement preparedStatement, final SQLExecutionUnit sqlExecutionUnit) { private PreparedStatementExecutorWrapper wrap(final PreparedStatement preparedStatement, final SQLExecutionUnit sqlExecutionUnit) {
Optional<PreparedStatementExecutorWrapper> wrapperOptional = Iterators.tryFind(cachedPreparedStatementWrappers.iterator(), new Predicate<PreparedStatementExecutorWrapper>() { Optional<PreparedStatementExecutorWrapper> wrapperOptional = Iterators.tryFind(cachedPreparedStatementWrappers.iterator(), new Predicate<PreparedStatementExecutorWrapper>() {
@Override @Override
public boolean apply(final PreparedStatementExecutorWrapper input) { public boolean apply(final PreparedStatementExecutorWrapper input) {
return Objects.equals(input.getPreparedStatement(), preparedStatement); return Objects.equals(input.getPreparedStatement(), preparedStatement);
......
...@@ -19,7 +19,6 @@ package com.dangdang.ddframe.rdb.sharding.executor; ...@@ -19,7 +19,6 @@ package com.dangdang.ddframe.rdb.sharding.executor;
import com.dangdang.ddframe.rdb.sharding.constant.SQLType; import com.dangdang.ddframe.rdb.sharding.constant.SQLType;
import com.dangdang.ddframe.rdb.sharding.executor.event.EventExecutionType; import com.dangdang.ddframe.rdb.sharding.executor.event.EventExecutionType;
import com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper;
import com.dangdang.ddframe.rdb.sharding.rewrite.SQLBuilder; import com.dangdang.ddframe.rdb.sharding.rewrite.SQLBuilder;
import com.dangdang.ddframe.rdb.sharding.routing.SQLExecutionUnit; import com.dangdang.ddframe.rdb.sharding.routing.SQLExecutionUnit;
import org.junit.Test; import org.junit.Test;
...@@ -30,7 +29,9 @@ import java.sql.SQLException; ...@@ -30,7 +29,9 @@ import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsCollectionContaining.hasItem; import static org.hamcrest.core.IsCollectionContaining.hasItem;
...@@ -50,7 +51,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -50,7 +51,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
@Test @Test
public void assertNoStatement() throws SQLException { public void assertNoStatement() throws SQLException {
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, Collections.<StatementExecutorWrapper>emptyList()); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, Collections.<SQLExecutionUnit, Statement>emptyMap());
assertFalse(actual.execute()); assertFalse(actual.execute());
assertThat(actual.executeUpdate(), is(0)); assertThat(actual.executeUpdate(), is(0));
assertThat(actual.executeQuery().size(), is(0)); assertThat(actual.executeQuery().size(), is(0));
...@@ -61,7 +62,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -61,7 +62,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
ResultSet resultSet = mock(ResultSet.class); ResultSet resultSet = mock(ResultSet.class);
when(statement.executeQuery(SELECT_FROM_DUAL)).thenReturn(resultSet); when(statement.executeQuery(SELECT_FROM_DUAL)).thenReturn(resultSet);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, Collections.singletonList(createStatementExecutorWrapperForDQL(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, createStatementMap(SELECT_FROM_DUAL, statement, "ds_0"));
assertThat(actual.executeQuery(), is(Collections.singletonList(resultSet))); assertThat(actual.executeQuery(), is(Collections.singletonList(resultSet)));
verify(statement).executeQuery(SELECT_FROM_DUAL); verify(statement).executeQuery(SELECT_FROM_DUAL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -82,8 +83,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -82,8 +83,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement1.getConnection()).thenReturn(mock(Connection.class)); when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.executeQuery(SELECT_FROM_DUAL)).thenReturn(resultSet2); when(statement2.executeQuery(SELECT_FROM_DUAL)).thenReturn(resultSet2);
when(statement2.getConnection()).thenReturn(mock(Connection.class)); when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, createStatementMap(SELECT_FROM_DUAL, statement1, "ds_0", statement2, "ds_1"));
Arrays.asList(createStatementExecutorWrapperForDQL(statement1, "ds_0"), createStatementExecutorWrapperForDQL(statement2, "ds_1")));
List<ResultSet> actualResultSets = actual.executeQuery(); List<ResultSet> actualResultSets = actual.executeQuery();
assertThat(actualResultSets, hasItem(resultSet1)); assertThat(actualResultSets, hasItem(resultSet1));
assertThat(actualResultSets, hasItem(resultSet2)); assertThat(actualResultSets, hasItem(resultSet2));
...@@ -105,7 +105,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -105,7 +105,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
SQLException exp = new SQLException(); SQLException exp = new SQLException();
when(statement.executeQuery(SELECT_FROM_DUAL)).thenThrow(exp); when(statement.executeQuery(SELECT_FROM_DUAL)).thenThrow(exp);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, Collections.singletonList(createStatementExecutorWrapperForDQL(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, createStatementMap(SELECT_FROM_DUAL, statement, "ds_0"));
assertThat(actual.executeQuery(), is(Collections.singletonList((ResultSet) null))); assertThat(actual.executeQuery(), is(Collections.singletonList((ResultSet) null)));
verify(statement).executeQuery(SELECT_FROM_DUAL); verify(statement).executeQuery(SELECT_FROM_DUAL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -125,8 +125,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -125,8 +125,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement2.executeQuery(SELECT_FROM_DUAL)).thenThrow(exp); when(statement2.executeQuery(SELECT_FROM_DUAL)).thenThrow(exp);
when(statement1.getConnection()).thenReturn(mock(Connection.class)); when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class)); when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, createStatementMap(SELECT_FROM_DUAL, statement1, "ds_0", statement2, "ds_1"));
Arrays.asList(createStatementExecutorWrapperForDQL(statement1, "ds_0"), createStatementExecutorWrapperForDQL(statement2, "ds_1")));
List<ResultSet> actualResultSets = actual.executeQuery(); List<ResultSet> actualResultSets = actual.executeQuery();
assertThat(actualResultSets, is(Arrays.asList((ResultSet) null, null))); assertThat(actualResultSets, is(Arrays.asList((ResultSet) null, null)));
verify(statement1).executeQuery(SELECT_FROM_DUAL); verify(statement1).executeQuery(SELECT_FROM_DUAL);
...@@ -146,7 +145,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -146,7 +145,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteUpdateForSingleStatementSuccess() throws SQLException { public void assertExecuteUpdateForSingleStatementSuccess() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.executeUpdate(DELETE_FROM_DUAL)).thenReturn(10); when(statement.executeUpdate(DELETE_FROM_DUAL)).thenReturn(10);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertThat(actual.executeUpdate(), is(10)); assertThat(actual.executeUpdate(), is(10));
verify(statement).executeUpdate(DELETE_FROM_DUAL); verify(statement).executeUpdate(DELETE_FROM_DUAL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -165,8 +164,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -165,8 +164,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement2.executeUpdate(DELETE_FROM_DUAL)).thenReturn(20); when(statement2.executeUpdate(DELETE_FROM_DUAL)).thenReturn(20);
when(statement1.getConnection()).thenReturn(mock(Connection.class)); when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class)); when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement1, "ds_0", statement2, "ds_1"));
Arrays.asList(createStatementExecutorWrapperForDML(statement1, "ds_0"), createStatementExecutorWrapperForDML(statement2, "ds_1")));
assertThat(actual.executeUpdate(), is(30)); assertThat(actual.executeUpdate(), is(30));
verify(statement1).executeUpdate(DELETE_FROM_DUAL); verify(statement1).executeUpdate(DELETE_FROM_DUAL);
verify(statement2).executeUpdate(DELETE_FROM_DUAL); verify(statement2).executeUpdate(DELETE_FROM_DUAL);
...@@ -186,7 +184,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -186,7 +184,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
SQLException exp = new SQLException(); SQLException exp = new SQLException();
when(statement.executeUpdate(DELETE_FROM_DUAL)).thenThrow(exp); when(statement.executeUpdate(DELETE_FROM_DUAL)).thenThrow(exp);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertThat(actual.executeUpdate(), is(0)); assertThat(actual.executeUpdate(), is(0));
verify(statement).executeUpdate(DELETE_FROM_DUAL); verify(statement).executeUpdate(DELETE_FROM_DUAL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -206,8 +204,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -206,8 +204,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement2.executeUpdate(DELETE_FROM_DUAL)).thenThrow(exp); when(statement2.executeUpdate(DELETE_FROM_DUAL)).thenThrow(exp);
when(statement1.getConnection()).thenReturn(mock(Connection.class)); when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class)); when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement1, "ds_0", statement2, "ds_1"));
Arrays.asList(createStatementExecutorWrapperForDML(statement1, "ds_0"), createStatementExecutorWrapperForDML(statement2, "ds_1")));
assertThat(actual.executeUpdate(), is(0)); assertThat(actual.executeUpdate(), is(0));
verify(statement1).executeUpdate(DELETE_FROM_DUAL); verify(statement1).executeUpdate(DELETE_FROM_DUAL);
verify(statement2).executeUpdate(DELETE_FROM_DUAL); verify(statement2).executeUpdate(DELETE_FROM_DUAL);
...@@ -226,7 +223,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -226,7 +223,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteUpdateWithAutoGeneratedKeys() throws SQLException { public void assertExecuteUpdateWithAutoGeneratedKeys() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.executeUpdate(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS)).thenReturn(10); when(statement.executeUpdate(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS)).thenReturn(10);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertThat(actual.executeUpdate(Statement.NO_GENERATED_KEYS), is(10)); assertThat(actual.executeUpdate(Statement.NO_GENERATED_KEYS), is(10));
verify(statement).executeUpdate(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS); verify(statement).executeUpdate(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -241,7 +238,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -241,7 +238,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteUpdateWithColumnIndexes() throws SQLException { public void assertExecuteUpdateWithColumnIndexes() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.executeUpdate(DELETE_FROM_DUAL, new int[] {1})).thenReturn(10); when(statement.executeUpdate(DELETE_FROM_DUAL, new int[] {1})).thenReturn(10);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertThat(actual.executeUpdate(new int[] {1}), is(10)); assertThat(actual.executeUpdate(new int[] {1}), is(10));
verify(statement).executeUpdate(DELETE_FROM_DUAL, new int[] {1}); verify(statement).executeUpdate(DELETE_FROM_DUAL, new int[] {1});
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -256,7 +253,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -256,7 +253,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteUpdateWithColumnNames() throws SQLException { public void assertExecuteUpdateWithColumnNames() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.executeUpdate(DELETE_FROM_DUAL, new String[] {"col"})).thenReturn(10); when(statement.executeUpdate(DELETE_FROM_DUAL, new String[] {"col"})).thenReturn(10);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertThat(actual.executeUpdate(new String[] {"col"}), is(10)); assertThat(actual.executeUpdate(new String[] {"col"}), is(10));
verify(statement).executeUpdate(DELETE_FROM_DUAL, new String[] {"col"}); verify(statement).executeUpdate(DELETE_FROM_DUAL, new String[] {"col"});
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -271,7 +268,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -271,7 +268,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteForSingleStatementSuccessWithDML() throws SQLException { public void assertExecuteForSingleStatementSuccessWithDML() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.execute(DELETE_FROM_DUAL)).thenReturn(false); when(statement.execute(DELETE_FROM_DUAL)).thenReturn(false);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertFalse(actual.execute()); assertFalse(actual.execute());
verify(statement).execute(DELETE_FROM_DUAL); verify(statement).execute(DELETE_FROM_DUAL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -290,8 +287,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -290,8 +287,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement2.execute(DELETE_FROM_DUAL)).thenReturn(false); when(statement2.execute(DELETE_FROM_DUAL)).thenReturn(false);
when(statement1.getConnection()).thenReturn(mock(Connection.class)); when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class)); when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement1, "ds_0", statement2, "ds_1"));
Arrays.asList(createStatementExecutorWrapperForDML(statement1, "ds_0"), createStatementExecutorWrapperForDML(statement2, "ds_1")));
assertFalse(actual.execute()); assertFalse(actual.execute());
verify(statement1).execute(DELETE_FROM_DUAL); verify(statement1).execute(DELETE_FROM_DUAL);
verify(statement2).execute(DELETE_FROM_DUAL); verify(statement2).execute(DELETE_FROM_DUAL);
...@@ -311,7 +307,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -311,7 +307,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
SQLException exp = new SQLException(); SQLException exp = new SQLException();
when(statement.execute(DELETE_FROM_DUAL)).thenThrow(exp); when(statement.execute(DELETE_FROM_DUAL)).thenThrow(exp);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertFalse(actual.execute()); assertFalse(actual.execute());
verify(statement).execute(DELETE_FROM_DUAL); verify(statement).execute(DELETE_FROM_DUAL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -331,8 +327,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -331,8 +327,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement2.execute(DELETE_FROM_DUAL)).thenThrow(exp); when(statement2.execute(DELETE_FROM_DUAL)).thenThrow(exp);
when(statement1.getConnection()).thenReturn(mock(Connection.class)); when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class)); when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement1, "ds_0", statement2, "ds_1"));
Arrays.asList(createStatementExecutorWrapperForDML(statement1, "ds_0"), createStatementExecutorWrapperForDML(statement2, "ds_1")));
assertFalse(actual.execute()); assertFalse(actual.execute());
verify(statement1).execute(DELETE_FROM_DUAL); verify(statement1).execute(DELETE_FROM_DUAL);
verify(statement2).execute(DELETE_FROM_DUAL); verify(statement2).execute(DELETE_FROM_DUAL);
...@@ -351,7 +346,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -351,7 +346,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteForSingleStatementWithDQL() throws SQLException { public void assertExecuteForSingleStatementWithDQL() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.execute(SELECT_FROM_DUAL)).thenReturn(true); when(statement.execute(SELECT_FROM_DUAL)).thenReturn(true);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, Collections.singletonList(createStatementExecutorWrapperForDQL(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, createStatementMap(SELECT_FROM_DUAL, statement, "ds_0"));
assertTrue(actual.execute()); assertTrue(actual.execute());
verify(statement).execute(SELECT_FROM_DUAL); verify(statement).execute(SELECT_FROM_DUAL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -370,14 +365,14 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -370,14 +365,14 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement2.execute(SELECT_FROM_DUAL)).thenReturn(true); when(statement2.execute(SELECT_FROM_DUAL)).thenReturn(true);
when(statement1.getConnection()).thenReturn(mock(Connection.class)); when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class)); when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.SELECT, createStatementMap(SELECT_FROM_DUAL, statement1, "ds_0", statement2, "ds_1"));
Arrays.asList(createStatementExecutorWrapperForDQL(statement1, "ds_0"), createStatementExecutorWrapperForDQL(statement2, "ds_0")));
assertTrue(actual.execute()); assertTrue(actual.execute());
verify(statement1).execute(SELECT_FROM_DUAL); verify(statement1).execute(SELECT_FROM_DUAL);
verify(statement2).execute(SELECT_FROM_DUAL); verify(statement2).execute(SELECT_FROM_DUAL);
verify(statement1).getConnection(); verify(statement1).getConnection();
verify(statement2).getConnection(); verify(statement2).getConnection();
verify(getEventCaller(), times(4)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifyDataSource("ds_1");
verify(getEventCaller(), times(4)).verifySQL(SELECT_FROM_DUAL); verify(getEventCaller(), times(4)).verifySQL(SELECT_FROM_DUAL);
verify(getEventCaller(), times(4)).verifyParameters(Collections.emptyList()); verify(getEventCaller(), times(4)).verifyParameters(Collections.emptyList());
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE); verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
...@@ -389,7 +384,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -389,7 +384,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteWithAutoGeneratedKeys() throws SQLException { public void assertExecuteWithAutoGeneratedKeys() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.execute(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS)).thenReturn(false); when(statement.execute(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS)).thenReturn(false);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertFalse(actual.execute(Statement.NO_GENERATED_KEYS)); assertFalse(actual.execute(Statement.NO_GENERATED_KEYS));
verify(statement).execute(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS); verify(statement).execute(DELETE_FROM_DUAL, Statement.NO_GENERATED_KEYS);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -404,7 +399,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -404,7 +399,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteWithColumnIndexes() throws SQLException { public void assertExecuteWithColumnIndexes() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.execute(DELETE_FROM_DUAL, new int[] {1})).thenReturn(false); when(statement.execute(DELETE_FROM_DUAL, new int[] {1})).thenReturn(false);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertFalse(actual.execute(new int[] {1})); assertFalse(actual.execute(new int[] {1}));
verify(statement).execute(DELETE_FROM_DUAL, new int[] {1}); verify(statement).execute(DELETE_FROM_DUAL, new int[] {1});
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -419,7 +414,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -419,7 +414,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
public void assertExecuteWithColumnNames() throws SQLException { public void assertExecuteWithColumnNames() throws SQLException {
Statement statement = mock(Statement.class); Statement statement = mock(Statement.class);
when(statement.execute(DELETE_FROM_DUAL, new String[] {"col"})).thenReturn(false); when(statement.execute(DELETE_FROM_DUAL, new String[] {"col"})).thenReturn(false);
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, Collections.singletonList(createStatementExecutorWrapperForDML(statement, "ds_0"))); StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DELETE, createStatementMap(DELETE_FROM_DUAL, statement, "ds_0"));
assertFalse(actual.execute(new String[] {"col"})); assertFalse(actual.execute(new String[] {"col"}));
verify(statement).execute(DELETE_FROM_DUAL, new String[] {"col"}); verify(statement).execute(DELETE_FROM_DUAL, new String[] {"col"});
verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
...@@ -430,15 +425,18 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest { ...@@ -430,15 +425,18 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
verify(getEventCaller(), times(0)).verifyException(null); verify(getEventCaller(), times(0)).verifyException(null);
} }
private StatementExecutorWrapper createStatementExecutorWrapperForDQL(final Statement statement, final String dataSource) { private Map<SQLExecutionUnit, Statement> createStatementMap(final String sql, final Statement statement, final String dataSource) {
Map<SQLExecutionUnit, Statement> result = new HashMap<>();
SQLBuilder sqlBuilder = new SQLBuilder(); SQLBuilder sqlBuilder = new SQLBuilder();
sqlBuilder.appendLiterals(SELECT_FROM_DUAL); sqlBuilder.appendLiterals(sql);
return new StatementExecutorWrapper(statement, new SQLExecutionUnit(dataSource, sqlBuilder.toSQL(Collections.<String, String>emptyMap()))); result.put(new SQLExecutionUnit(dataSource, sqlBuilder.toSQL(Collections.<String, String>emptyMap())), statement);
return result;
} }
private StatementExecutorWrapper createStatementExecutorWrapperForDML(final Statement statement, final String dataSource) { private Map<SQLExecutionUnit, Statement> createStatementMap(final String sql, final Statement statement1, final String dataSource1, final Statement statement2, final String dataSource2) {
SQLBuilder sqlBuilder = new SQLBuilder(); Map<SQLExecutionUnit, Statement> result = new HashMap<>();
sqlBuilder.appendLiterals(DELETE_FROM_DUAL); result.putAll(createStatementMap(sql, statement1, dataSource1));
return new StatementExecutorWrapper(statement, new SQLExecutionUnit(dataSource, sqlBuilder.toSQL(Collections.<String, String>emptyMap()))); result.putAll(createStatementMap(sql, statement2, dataSource2));
return result;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册