use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteWithColumnIndexes.
@Test
public void assertExecuteWithColumnIndexes() throws SQLException {
Statement statement = mock(Statement.class);
when(statement.execute(DML_SQL, new int[] { 1 })).thenReturn(false);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
assertFalse(actual.execute(new int[] { 1 }));
verify(statement).execute(DML_SQL, new int[] { 1 });
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifySQL(DML_SQL);
verify(getEventCaller(), times(2)).verifyParameters(Collections.emptyList());
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
verify(getEventCaller(), times(0)).verifyException(null);
}
use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteUpdateForMultipleStatementsFailure.
@Test
public void assertExecuteUpdateForMultipleStatementsFailure() throws SQLException {
Statement statement1 = mock(Statement.class);
Statement statement2 = mock(Statement.class);
SQLException exp = new SQLException();
when(statement1.executeUpdate(DML_SQL)).thenThrow(exp);
when(statement2.executeUpdate(DML_SQL)).thenThrow(exp);
when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement1, "ds_0", statement2, "ds_1"));
assertThat(actual.executeUpdate(), is(0));
verify(statement1).executeUpdate(DML_SQL);
verify(statement2).executeUpdate(DML_SQL);
verify(statement1).getConnection();
verify(statement2).getConnection();
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifyDataSource("ds_1");
verify(getEventCaller(), times(4)).verifySQL(DML_SQL);
verify(getEventCaller(), times(4)).verifyParameters(Collections.emptyList());
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.EXECUTE_FAILURE);
verify(getEventCaller(), times(2)).verifyException(exp);
}
use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteQueryForSingleStatementSuccess.
@Test
public void assertExecuteQueryForSingleStatementSuccess() throws SQLException {
Statement statement = mock(Statement.class);
ResultSet resultSet = mock(ResultSet.class);
when(statement.executeQuery(DQL_SQL)).thenReturn(resultSet);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DQL, createStatementUnits(DQL_SQL, statement, "ds_0"));
assertThat(actual.executeQuery(), is(Collections.singletonList(resultSet)));
verify(statement).executeQuery(DQL_SQL);
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifySQL(DQL_SQL);
verify(getEventCaller(), times(2)).verifyParameters(Collections.emptyList());
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
verify(getEventCaller(), times(0)).verifyException(null);
}
use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteWithAutoGeneratedKeys.
@Test
public void assertExecuteWithAutoGeneratedKeys() throws SQLException {
Statement statement = mock(Statement.class);
when(statement.execute(DML_SQL, Statement.NO_GENERATED_KEYS)).thenReturn(false);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
assertFalse(actual.execute(Statement.NO_GENERATED_KEYS));
verify(statement).execute(DML_SQL, Statement.NO_GENERATED_KEYS);
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifySQL(DML_SQL);
verify(getEventCaller(), times(2)).verifyParameters(Collections.emptyList());
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
verify(getEventCaller(), times(0)).verifyException(null);
}
use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteForSingleStatementWithDQL.
@Test
public void assertExecuteForSingleStatementWithDQL() throws SQLException {
Statement statement = mock(Statement.class);
when(statement.execute(DQL_SQL)).thenReturn(true);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DQL, createStatementUnits(DQL_SQL, statement, "ds_0"));
assertTrue(actual.execute());
verify(statement).execute(DQL_SQL);
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifySQL(DQL_SQL);
verify(getEventCaller(), times(2)).verifyParameters(Collections.emptyList());
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller()).verifyEventExecutionType(EventExecutionType.EXECUTE_SUCCESS);
verify(getEventCaller(), times(0)).verifyException(null);
}
Aggregations