StatementExecutor extends AbstractStatementExecutor { @Override public int executeUpdate(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext) throws SQLException { return executeUpdate(inputGroups, Statement::executeUpdate, sqlStatementContext); } StatementExecutor(final Map<String, DataSource> dataSourceMap, final SchemaContexts schemaContexts, final SQLExecutor sqlExecutor); @Override List<QueryResult> executeQuery(final Collection<InputGroup<StatementExecuteUnit>> inputGroups); @Override int executeUpdate(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext); int executeUpdate(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext, final int autoGeneratedKeys); int executeUpdate(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext, final int[] columnIndexes); int executeUpdate(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext, final String[] columnNames); @Override boolean execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext); boolean execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext, final int autoGeneratedKeys); boolean execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext, final int[] columnIndexes); boolean execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext, final String[] columnNames);  }
@Test public void assertExecuteUpdateForSingleStatementSuccess() throws SQLException { Statement statement = getStatement(); when(statement.executeUpdate(DML_SQL)).thenReturn(10); assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext()), is(10)); verify(statement).executeUpdate(DML_SQL); }
@Test public void assertExecuteUpdateForMultipleStatementsSuccess() throws SQLException { Statement statement1 = getStatement(); Statement statement2 = getStatement(); when(statement1.executeUpdate(DML_SQL)).thenReturn(10); when(statement2.executeUpdate(DML_SQL)).thenReturn(20); assertThat(actual.executeUpdate(getExecuteGroups(Arrays.asList(statement1, statement2), false), createSQLStatementContext()), is(30)); verify(statement1).executeUpdate(DML_SQL); verify(statement2).executeUpdate(DML_SQL); }
@Test public void assertExecuteUpdateForSingleStatementFailure() throws SQLException { Statement statement = getStatement(); SQLException ex = new SQLException(""); when(statement.executeUpdate(DML_SQL)).thenThrow(ex); assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext()), is(0)); verify(statement).executeUpdate(DML_SQL); }
@Test public void assertExecuteUpdateForMultipleStatementsFailure() throws SQLException { Statement statement1 = getStatement(); Statement statement2 = getStatement(); SQLException ex = new SQLException(""); when(statement1.executeUpdate(DML_SQL)).thenThrow(ex); when(statement2.executeUpdate(DML_SQL)).thenThrow(ex); assertThat(actual.executeUpdate(getExecuteGroups(Arrays.asList(statement1, statement2), false), createSQLStatementContext()), is(0)); verify(statement1).executeUpdate(DML_SQL); verify(statement2).executeUpdate(DML_SQL); }
@Test public void assertExecuteUpdateWithAutoGeneratedKeys() throws SQLException { Statement statement = getStatement(); when(statement.executeUpdate(DML_SQL, Statement.NO_GENERATED_KEYS)).thenReturn(10); assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext(), Statement.NO_GENERATED_KEYS), is(10)); verify(statement).executeUpdate(DML_SQL, Statement.NO_GENERATED_KEYS); }
@Test public void assertExecuteUpdateWithColumnIndexes() throws SQLException { Statement statement = getStatement(); when(statement.executeUpdate(DML_SQL, new int[] {1})).thenReturn(10); assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext(), new int[] {1}), is(10)); verify(statement).executeUpdate(DML_SQL, new int[] {1}); }
@Test public void assertExecuteUpdateWithColumnNames() throws SQLException { Statement statement = getStatement(); when(statement.executeUpdate(DML_SQL, new String[] {"col"})).thenReturn(10); assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext(), new String[] {"col"}), is(10)); verify(statement).executeUpdate(DML_SQL, new String[] {"col"}); }