Search in sources :

Example 16 with FakeExecutionContextImpl

use of org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl in project teiid by teiid.

the class TestJDBCUpdateExecution method testBulkUpdate.

@Test
public void testBulkUpdate() throws Exception {
    // $NON-NLS-1$
    Insert command = (Insert) TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into BQT1.SmallA (IntKey) values (1)");
    Parameter param = new Parameter();
    param.setType(Integer.class);
    param.setValueIndex(0);
    ExpressionValueSource evs = new ExpressionValueSource(Arrays.asList((Expression) param));
    command.setValueSource(evs);
    List<List<?>> vals = new ArrayList<List<?>>();
    for (int i = 0; i < 8; i++) {
        vals.add(Arrays.asList(i));
    }
    command.setParameterValues(vals.iterator());
    Connection connection = Mockito.mock(Connection.class);
    PreparedStatement p = Mockito.mock(PreparedStatement.class);
    Mockito.stub(p.executeBatch()).toReturn(new int[] { 1, 1 });
    // $NON-NLS-1$
    Mockito.stub(connection.prepareStatement("INSERT INTO SmallA (IntKey) VALUES (?)")).toReturn(p);
    JDBCExecutionFactory config = new JDBCExecutionFactory();
    config.setMaxPreparedInsertBatchSize(2);
    ResultSet r = Mockito.mock(ResultSet.class);
    ResultSetMetaData rs = Mockito.mock(ResultSetMetaData.class);
    Mockito.stub(r.getMetaData()).toReturn(rs);
    Mockito.stub(p.getGeneratedKeys()).toReturn(r);
    FakeExecutionContextImpl context = new FakeExecutionContextImpl();
    ((org.teiid.query.util.CommandContext) context.getCommandContext()).setReturnAutoGeneratedKeys(Collections.EMPTY_LIST);
    JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(command, connection, context, config);
    updateExecution.execute();
    assertArrayEquals(new int[] { 1, 1, 1, 1, 1, 1, 1, 1 }, updateExecution.getUpdateCounts());
}
Also used : FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Insert(org.teiid.language.Insert) ResultSetMetaData(java.sql.ResultSetMetaData) Expression(org.teiid.language.Expression) ResultSet(java.sql.ResultSet) Parameter(org.teiid.language.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) ExpressionValueSource(org.teiid.language.ExpressionValueSource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 FakeExecutionContextImpl (org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl)16 Connection (java.sql.Connection)12 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)8 ResultSetMetaData (java.sql.ResultSetMetaData)8 Insert (org.teiid.language.Insert)8 ExpressionValueSource (org.teiid.language.ExpressionValueSource)5 Parameter (org.teiid.language.Parameter)5 Statement (java.sql.Statement)4 ExecutionContextImpl (org.teiid.dqp.internal.datamgr.ExecutionContextImpl)4 Expression (org.teiid.language.Expression)4 Command (org.teiid.language.Command)3 BatchUpdateException (java.sql.BatchUpdateException)2 DatabaseMetaData (java.sql.DatabaseMetaData)2 List (java.util.List)2 CommandBuilder (org.teiid.cdk.CommandBuilder)2 BatchedUpdates (org.teiid.language.BatchedUpdates)2 Literal (org.teiid.language.Literal)2 ResultSetExecution (org.teiid.translator.ResultSetExecution)2