StatementExecutor extends AbstractStatementExecutor { @Override public boolean execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext) throws SQLException { return execute(inputGroups, Statement::execute, 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 assertExecuteForSingleStatementSuccessWithDML() throws SQLException { Statement statement = getStatement(); when(statement.execute(DML_SQL)).thenReturn(false); assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext())); verify(statement).execute(DML_SQL); }
@Test public void assertExecuteForMultipleStatementsSuccessWithDML() throws SQLException { Statement statement1 = getStatement(); Statement statement2 = getStatement(); when(statement1.execute(DML_SQL)).thenReturn(false); when(statement2.execute(DML_SQL)).thenReturn(false); assertFalse(actual.execute(getExecuteGroups(Arrays.asList(statement1, statement2), false), createSQLStatementContext())); verify(statement1).execute(DML_SQL); verify(statement2).execute(DML_SQL); }
@Test public void assertExecuteForSingleStatementFailureWithDML() throws SQLException { Statement statement = getStatement(); SQLException ex = new SQLException(""); when(statement.execute(DML_SQL)).thenThrow(ex); assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext())); verify(statement).execute(DML_SQL); }
@Test public void assertExecuteForMultipleStatementsFailureWithDML() throws SQLException { Statement statement1 = getStatement(); Statement statement2 = getStatement(); SQLException ex = new SQLException(""); when(statement1.execute(DML_SQL)).thenThrow(ex); when(statement2.execute(DML_SQL)).thenThrow(ex); assertFalse(actual.execute(getExecuteGroups(Arrays.asList(statement1, statement2), false), createSQLStatementContext())); verify(statement1).execute(DML_SQL); verify(statement2).execute(DML_SQL); }
@Test public void assertExecuteForSingleStatementWithDQL() throws SQLException { Statement statement = getStatement(); when(statement.execute(DQL_SQL)).thenReturn(true); assertTrue(actual.execute(getExecuteGroups(Collections.singletonList(statement), true), createSQLStatementContext())); verify(statement).execute(DQL_SQL); }
@Test public void assertExecuteForMultipleStatements() throws SQLException { Statement statement1 = getStatement(); Statement statement2 = getStatement(); when(statement1.execute(DQL_SQL)).thenReturn(true); when(statement2.execute(DQL_SQL)).thenReturn(true); assertTrue(actual.execute(getExecuteGroups(Arrays.asList(statement1, statement2), true), createSQLStatementContext())); verify(statement1).execute(DQL_SQL); verify(statement2).execute(DQL_SQL); }
@Test public void assertExecuteWithAutoGeneratedKeys() throws SQLException { Statement statement = getStatement(); when(statement.execute(DML_SQL, Statement.NO_GENERATED_KEYS)).thenReturn(false); assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext(), Statement.NO_GENERATED_KEYS)); verify(statement).execute(DML_SQL, Statement.NO_GENERATED_KEYS); }
@Test public void assertExecuteWithColumnIndexes() throws SQLException { Statement statement = getStatement(); when(statement.execute(DML_SQL, new int[] {1})).thenReturn(false); assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext(), new int[] {1})); verify(statement).execute(DML_SQL, new int[] {1}); }
@Test public void assertExecuteWithColumnNames() throws SQLException { Statement statement = getStatement(); when(statement.execute(DML_SQL, new String[] {"col"})).thenReturn(false); assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext(), new String[] {"col"})); verify(statement).execute(DML_SQL, new String[] {"col"}); }
@Test public void assertOverallExceptionFailure() throws SQLException { ExecutorExceptionHandler.setExceptionThrown(true); Statement statement = getStatement(); SQLException ex = new SQLException(""); when(statement.execute(DML_SQL)).thenThrow(ex); try { assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), createSQLStatementContext())); } catch (final SQLException ignored) { } }