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);
}
}
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());
}
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();
}
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);
}
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);
}
Aggregations