Search in sources :

Example 16 with PreparedStatementExecutor

use of io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor in project sharding-jdbc by shardingjdbc.

the class PreparedStatementExecutorTest method assertExecuteUpdateForSinglePreparedStatementSuccess.

@Test
public void assertExecuteUpdateForSinglePreparedStatementSuccess() throws SQLException {
    PreparedStatement preparedStatement = mock(PreparedStatement.class);
    when(preparedStatement.executeUpdate()).thenReturn(10);
    when(preparedStatement.getConnection()).thenReturn(mock(Connection.class));
    PreparedStatementExecutor actual = new PreparedStatementExecutor(getExecutorEngine(), SQLType.DML, createPreparedStatementUnits(DML_SQL, preparedStatement, "ds_0"), Collections.emptyList());
    assertThat(actual.executeUpdate(), is(10));
    verify(preparedStatement).executeUpdate();
    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);
}
Also used : PreparedStatementExecutor(io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Aggregations

PreparedStatementExecutor (io.shardingjdbc.core.executor.type.prepared.PreparedStatementExecutor)16 Test (org.junit.Test)15 Connection (java.sql.Connection)14 PreparedStatement (java.sql.PreparedStatement)14 SQLException (java.sql.SQLException)6 ResultSet (java.sql.ResultSet)4 BatchPreparedStatementExecutor (io.shardingjdbc.core.executor.type.batch.BatchPreparedStatementExecutor)1 BatchPreparedStatementUnit (io.shardingjdbc.core.executor.type.batch.BatchPreparedStatementUnit)1 PreparedStatementUnit (io.shardingjdbc.core.executor.type.prepared.PreparedStatementUnit)1 GeneratedKeysResultSet (io.shardingjdbc.core.jdbc.core.resultset.GeneratedKeysResultSet)1 ShardingResultSet (io.shardingjdbc.core.jdbc.core.resultset.ShardingResultSet)1 JDBCQueryResult (io.shardingjdbc.core.merger.JDBCQueryResult)1 MergeEngine (io.shardingjdbc.core.merger.MergeEngine)1 QueryResult (io.shardingjdbc.core.merger.QueryResult)1 ArrayList (java.util.ArrayList)1