use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteUpdateWithColumnNames.
@Test
public void assertExecuteUpdateWithColumnNames() throws SQLException {
Statement statement = mock(Statement.class);
when(statement.executeUpdate(DML_SQL, new String[] { "col" })).thenReturn(10);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
assertThat(actual.executeUpdate(new String[] { "col" }), is(10));
verify(statement).executeUpdate(DML_SQL, new String[] { "col" });
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 assertNoStatement.
@Test
public void assertNoStatement() throws SQLException {
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DQL, Collections.<StatementUnit>emptyList());
assertFalse(actual.execute());
assertThat(actual.executeUpdate(), is(0));
assertThat(actual.executeQuery().size(), is(0));
}
use of io.shardingjdbc.core.executor.type.statement.StatementExecutor in project sharding-jdbc by shardingjdbc.
the class StatementExecutorTest method assertExecuteUpdateWithAutoGeneratedKeys.
@Test
public void assertExecuteUpdateWithAutoGeneratedKeys() throws SQLException {
Statement statement = mock(Statement.class);
when(statement.executeUpdate(DML_SQL, Statement.NO_GENERATED_KEYS)).thenReturn(10);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
assertThat(actual.executeUpdate(Statement.NO_GENERATED_KEYS), is(10));
verify(statement).executeUpdate(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 assertExecuteForMultipleStatements.
@Test
public void assertExecuteForMultipleStatements() throws SQLException {
Statement statement1 = mock(Statement.class);
Statement statement2 = mock(Statement.class);
when(statement1.execute(DQL_SQL)).thenReturn(true);
when(statement2.execute(DQL_SQL)).thenReturn(true);
when(statement1.getConnection()).thenReturn(mock(Connection.class));
when(statement2.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DQL, createStatementUnits(DQL_SQL, statement1, "ds_0", statement2, "ds_1"));
assertTrue(actual.execute());
verify(statement1).execute(DQL_SQL);
verify(statement2).execute(DQL_SQL);
verify(statement1).getConnection();
verify(statement2).getConnection();
verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL);
verify(getEventCaller(), times(2)).verifyDataSource("ds_0");
verify(getEventCaller(), times(2)).verifyDataSource("ds_1");
verify(getEventCaller(), times(4)).verifySQL(DQL_SQL);
verify(getEventCaller(), times(4)).verifyParameters(Collections.emptyList());
verify(getEventCaller(), times(2)).verifyEventExecutionType(EventExecutionType.BEFORE_EXECUTE);
verify(getEventCaller(), times(2)).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 assertExecuteUpdateForSingleStatementSuccess.
@Test
public void assertExecuteUpdateForSingleStatementSuccess() throws SQLException {
Statement statement = mock(Statement.class);
when(statement.executeUpdate(DML_SQL)).thenReturn(10);
when(statement.getConnection()).thenReturn(mock(Connection.class));
StatementExecutor actual = new StatementExecutor(getExecutorEngine(), SQLType.DML, createStatementUnits(DML_SQL, statement, "ds_0"));
assertThat(actual.executeUpdate(), is(10));
verify(statement).executeUpdate(DML_SQL);
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);
}
Aggregations