Search in sources :

Example 1 with BaseStatementUnit

use of io.shardingjdbc.core.executor.BaseStatementUnit in project sharding-jdbc by shardingjdbc.

the class ExecuteEventListenerTest method assertSQLException.

@Test(expected = SQLException.class)
public void assertSQLException() throws Exception {
    Statement statement = mock(Statement.class);
    when(statement.getConnection()).thenReturn(mock(Connection.class));
    executorEngine.executeStatement(SQLType.DQL, Collections.singleton(new StatementUnit(new SQLExecutionUnit("ds_0", "select ..."), statement)), new ExecuteCallback<Integer>() {

        @Override
        public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
            throw new SQLException();
        }
    });
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) SQLExecutionUnit(io.shardingjdbc.core.routing.SQLExecutionUnit) StatementUnit(io.shardingjdbc.core.executor.type.statement.StatementUnit) BaseStatementUnit(io.shardingjdbc.core.executor.BaseStatementUnit) BaseStatementUnit(io.shardingjdbc.core.executor.BaseStatementUnit) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 2 with BaseStatementUnit

use of io.shardingjdbc.core.executor.BaseStatementUnit in project sharding-jdbc by shardingjdbc.

the class ExecuteEventListenerTest method assertMultiStatement.

@Test
public void assertMultiStatement() throws Exception {
    List<StatementUnit> statementUnitList = new ArrayList<>(2);
    Statement stm1 = mock(Statement.class);
    when(stm1.getConnection()).thenReturn(mock(Connection.class));
    statementUnitList.add(new StatementUnit(new SQLExecutionUnit("ds_0", "insert into ..."), stm1));
    Statement stm2 = mock(Statement.class);
    when(stm2.getConnection()).thenReturn(mock(Connection.class));
    statementUnitList.add(new StatementUnit(new SQLExecutionUnit("ds_0", "insert into ..."), stm2));
    executorEngine.executeStatement(SQLType.DML, statementUnitList, new ExecuteCallback<Integer>() {

        @Override
        public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
            return 0;
        }
    });
    assertThat(TRACER.finishedSpans().size(), is(3));
}
Also used : Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) SQLExecutionUnit(io.shardingjdbc.core.routing.SQLExecutionUnit) StatementUnit(io.shardingjdbc.core.executor.type.statement.StatementUnit) BaseStatementUnit(io.shardingjdbc.core.executor.BaseStatementUnit) BaseStatementUnit(io.shardingjdbc.core.executor.BaseStatementUnit) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 3 with BaseStatementUnit

use of io.shardingjdbc.core.executor.BaseStatementUnit in project sharding-jdbc by shardingjdbc.

the class ExecuteEventListenerTest method assertSingleStatement.

@Test
public void assertSingleStatement() throws Exception {
    Statement statement = mock(Statement.class);
    when(statement.getConnection()).thenReturn(mock(Connection.class));
    executorEngine.executeStatement(SQLType.DML, Collections.singleton(new StatementUnit(new SQLExecutionUnit("ds_0", "insert into ..."), statement)), new ExecuteCallback<Integer>() {

        @Override
        public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
            return 0;
        }
    });
    assertThat(TRACER.finishedSpans().size(), is(2));
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) SQLExecutionUnit(io.shardingjdbc.core.routing.SQLExecutionUnit) StatementUnit(io.shardingjdbc.core.executor.type.statement.StatementUnit) BaseStatementUnit(io.shardingjdbc.core.executor.BaseStatementUnit) BaseStatementUnit(io.shardingjdbc.core.executor.BaseStatementUnit) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

BaseStatementUnit (io.shardingjdbc.core.executor.BaseStatementUnit)3 StatementUnit (io.shardingjdbc.core.executor.type.statement.StatementUnit)3 SQLExecutionUnit (io.shardingjdbc.core.routing.SQLExecutionUnit)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Statement (java.sql.Statement)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1