Search in sources :

Example 6 with FakeExecutionContextImpl

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

the class TestJDBCUpdateExecution method testBatchedUpdateFailed.

@Test
public void testBatchedUpdateFailed() throws Exception {
    // $NON-NLS-1$
    Insert command = (Insert) TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into BQT1.SmallA (IntKey) values (1)");
    // $NON-NLS-1$
    Insert command1 = (Insert) TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into BQT1.SmallA (StringKey) values ('1')");
    Connection connection = Mockito.mock(Connection.class);
    Statement s = Mockito.mock(Statement.class);
    Mockito.stub(s.executeBatch()).toThrow(new BatchUpdateException(new int[] { Statement.EXECUTE_FAILED }));
    Mockito.stub(connection.createStatement()).toReturn(s);
    JDBCExecutionFactory config = new JDBCExecutionFactory();
    ResultSet r = Mockito.mock(ResultSet.class);
    ResultSetMetaData rs = Mockito.mock(ResultSetMetaData.class);
    Mockito.stub(r.getMetaData()).toReturn(rs);
    Mockito.stub(s.getGeneratedKeys()).toReturn(r);
    FakeExecutionContextImpl context = new FakeExecutionContextImpl();
    JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(new BatchedUpdates(Arrays.asList((Command) command, command1)), connection, context, config);
    try {
        updateExecution.execute();
        fail();
    } catch (TranslatorBatchException e) {
        int[] counts = e.getUpdateCounts();
        assertArrayEquals(new int[] { -3 }, counts);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Insert(org.teiid.language.Insert) TranslatorBatchException(org.teiid.translator.TranslatorBatchException) BatchUpdateException(java.sql.BatchUpdateException) BatchedUpdates(org.teiid.language.BatchedUpdates) Test(org.junit.Test)

Example 7 with FakeExecutionContextImpl

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

the class TestJDBCUpdateExecution method testBatchedUpdate.

@Test
public void testBatchedUpdate() throws Exception {
    // $NON-NLS-1$
    Insert command = (Insert) TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into BQT1.SmallA (IntKey) values (1)");
    // $NON-NLS-1$
    Insert command1 = (Insert) TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into BQT1.SmallA (StringKey) values ('1')");
    Connection connection = Mockito.mock(Connection.class);
    Statement s = Mockito.mock(Statement.class);
    Mockito.stub(s.executeBatch()).toReturn(new int[] { 1, 1 });
    Mockito.stub(connection.createStatement()).toReturn(s);
    JDBCExecutionFactory config = new JDBCExecutionFactory();
    ResultSet r = Mockito.mock(ResultSet.class);
    ResultSetMetaData rs = Mockito.mock(ResultSetMetaData.class);
    Mockito.stub(r.getMetaData()).toReturn(rs);
    Mockito.stub(s.getGeneratedKeys()).toReturn(r);
    FakeExecutionContextImpl context = new FakeExecutionContextImpl();
    ((org.teiid.query.util.CommandContext) context.getCommandContext()).setReturnAutoGeneratedKeys(Collections.EMPTY_LIST);
    JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(new BatchedUpdates(Arrays.asList((Command) command, command1)), connection, context, config);
    updateExecution.execute();
    assertArrayEquals(new int[] { 1, 1 }, updateExecution.getUpdateCounts());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Insert(org.teiid.language.Insert) BatchedUpdates(org.teiid.language.BatchedUpdates) Test(org.junit.Test)

Example 8 with FakeExecutionContextImpl

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

the class TestJDBCUpdateExecution method testInsertIteratorUpdate.

@Test
public void testInsertIteratorUpdate() throws Exception {
    // $NON-NLS-1$
    Insert command = (Insert) TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into BQT1.SmallA (IntKey, IntNum) values (1, 2)");
    Parameter param = new Parameter();
    param.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    param.setValueIndex(0);
    List<Expression> values = ((ExpressionValueSource) command.getValueSource()).getValues();
    values.set(0, param);
    param = new Parameter();
    param.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    param.setValueIndex(1);
    values.set(1, param);
    command.setParameterValues(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(1, 2)).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, IntNum) VALUES (?, ?)")).toReturn(p);
    JDBCExecutionFactory config = new JDBCExecutionFactory();
    JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(command, connection, new FakeExecutionContextImpl(), config);
    updateExecution.execute();
    Mockito.verify(p, Mockito.times(2)).addBatch();
}
Also used : FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Expression(org.teiid.language.Expression) Connection(java.sql.Connection) Parameter(org.teiid.language.Parameter) PreparedStatement(java.sql.PreparedStatement) Insert(org.teiid.language.Insert) ExpressionValueSource(org.teiid.language.ExpressionValueSource) Test(org.junit.Test)

Example 9 with FakeExecutionContextImpl

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

the class TestOracleTranslator method testSourceHint.

@Test
public void testSourceHint() throws Exception {
    ExecutionContextImpl impl = new FakeExecutionContextImpl();
    impl.setHints(Arrays.asList("hello world"));
    helpTestVisitor(getTestVDB(), "select part_name from parts", impl, null, "SELECT /*+ hello world */ g_0.PART_NAME FROM PARTS g_0", true);
}
Also used : FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) ExecutionContextImpl(org.teiid.dqp.internal.datamgr.ExecutionContextImpl) FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Test(org.junit.Test)

Example 10 with FakeExecutionContextImpl

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

the class TestOracleTranslator method testSourceHint3.

@Test
public void testSourceHint3() throws Exception {
    ExecutionContextImpl impl = new FakeExecutionContextImpl();
    impl.setHints(Arrays.asList("hello world"));
    impl.setGeneralHints(Arrays.asList("other"));
    helpTestVisitor(getTestVDB(), "select part_name from parts", impl, null, "SELECT /*+ hello world other */ g_0.PART_NAME FROM PARTS g_0", true);
}
Also used : FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) ExecutionContextImpl(org.teiid.dqp.internal.datamgr.ExecutionContextImpl) FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) 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