PreparedStatementExecutor extends AbstractStatementExecutor { @Override public boolean execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext) throws SQLException { boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); SQLExecutorCallback<Boolean> sqlExecutorCallback = createDefaultSQLExecutorCallbackWithBoolean(isExceptionThrown); List<Boolean> result = getSqlExecutor().execute(inputGroups, sqlExecutorCallback); refreshTableMetaData(getSchemaContexts().getDefaultSchema(), sqlStatementContext); if (null == result || result.isEmpty() || null == result.get(0)) { return false; } return result.get(0); } PreparedStatementExecutor(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); @Override boolean execute(final Collection<InputGroup<StatementExecuteUnit>> inputGroups, final SQLStatementContext<?> sqlStatementContext);  }
@Test public void assertExecuteForSinglePreparedStatementSuccessWithDML() throws SQLException { PreparedStatement preparedStatement = getPreparedStatement(); when(preparedStatement.execute()).thenReturn(false); assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(preparedStatement), false), createSQLStatementContext())); verify(preparedStatement).execute(); }
@Test public void assertExecuteForMultiplePreparedStatementsSuccessWithDML() throws SQLException { PreparedStatement preparedStatement1 = getPreparedStatement(); PreparedStatement preparedStatement2 = getPreparedStatement(); when(preparedStatement1.execute()).thenReturn(false); when(preparedStatement2.execute()).thenReturn(false); assertFalse(actual.execute(getExecuteGroups(Arrays.asList(preparedStatement1, preparedStatement2), false), createSQLStatementContext())); verify(preparedStatement1).execute(); verify(preparedStatement2).execute(); }
@Test public void assertExecuteForSinglePreparedStatementFailureWithDML() throws SQLException { PreparedStatement preparedStatement = getPreparedStatement(); SQLException ex = new SQLException(""); when(preparedStatement.execute()).thenThrow(ex); assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(preparedStatement), false), createSQLStatementContext())); verify(preparedStatement).execute(); }
@Test public void assertExecuteForMultiplePreparedStatementsFailureWithDML() throws SQLException { PreparedStatement preparedStatement1 = getPreparedStatement(); PreparedStatement preparedStatement2 = getPreparedStatement(); SQLException ex = new SQLException(""); when(preparedStatement1.execute()).thenThrow(ex); when(preparedStatement2.execute()).thenThrow(ex); assertFalse(actual.execute(getExecuteGroups(Arrays.asList(preparedStatement1, preparedStatement2), false), createSQLStatementContext())); verify(preparedStatement1).execute(); verify(preparedStatement2).execute(); }
@Test public void assertExecuteForSinglePreparedStatementWithDQL() throws SQLException { PreparedStatement preparedStatement = getPreparedStatement(); when(preparedStatement.execute()).thenReturn(true); assertTrue(actual.execute(getExecuteGroups(Collections.singletonList(preparedStatement), true), createSQLStatementContext())); verify(preparedStatement).execute(); }
@Test public void assertExecuteForMultiplePreparedStatements() throws SQLException { PreparedStatement preparedStatement1 = getPreparedStatement(); PreparedStatement preparedStatement2 = getPreparedStatement(); when(preparedStatement1.execute()).thenReturn(true); when(preparedStatement2.execute()).thenReturn(true); assertTrue(actual.execute(getExecuteGroups(Arrays.asList(preparedStatement1, preparedStatement2), true), createSQLStatementContext())); verify(preparedStatement1).execute(); verify(preparedStatement2).execute(); }