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