@Test public void testAutoGeneretionKeysPrepared() throws Exception { Insert command = (Insert)TranslationHelper.helpTranslate("create foreign table SmallA (IntKey integer auto_increment primary key, IntNum integer)", "insert into SmallA (IntKey, IntNum) values (1, 2)"); ((Literal)((ExpressionValueSource)command.getValueSource()).getValues().get(0)).setBindEligible(true); Connection connection = Mockito.mock(Connection.class); PreparedStatement s = Mockito.mock(PreparedStatement.class); Mockito.stub(connection.prepareStatement("INSERT INTO SmallA (IntKey, IntNum) VALUES (?, 2)", new String[] {"IntKey"})).toReturn(s); JDBCExecutionFactory config = new JDBCExecutionFactory() { @Override public boolean supportsGeneratedKeys() { return true; } @Override public boolean useColumnNamesForGeneratedKeys() { return true; } }; ResultSet r = Mockito.mock(ResultSet.class); Mockito.stub(r.next()).toReturn(true).toReturn(false); ResultSetMetaData rs = Mockito.mock(ResultSetMetaData.class); Mockito.stub(r.getMetaData()).toReturn(rs); Mockito.stub(s.getGeneratedKeys()).toReturn(r); FakeExecutionContextImpl context = new FakeExecutionContextImpl(); context.setGeneratedKeyColumns(command); JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(command, connection, context, config); updateExecution.execute(); Mockito.verify(s, Mockito.times(1)).getGeneratedKeys(); Mockito.verify(s, Mockito.times(1)).executeUpdate(); config = new JDBCExecutionFactory() { @Override public boolean supportsGeneratedKeys() { return true; } }; assertEquals(0, context.getCommandContext().getGeneratedKeys().getKeyIterator().next().get(0)); }
@Override public void execute() throws TranslatorException { if (command instanceof BatchedUpdates) { execute(((BatchedUpdates)command)); } else { TranslatedCommand translatedComm = translateCommand(command); executeTranslatedCommand(translatedComm); } }
JDBCUpdateExecution extends JDBCBaseExecution implements UpdateExecution { @Override public void execute() throws TranslatorException { if (command instanceof BatchedUpdates) { execute(((BatchedUpdates)command)); } else { TranslatedCommand translatedComm = translateCommand(command); executeTranslatedCommand(translatedComm); } } }
JDBCUpdateExecution extends JDBCBaseExecution implements UpdateExecution { @Override public void execute() throws TranslatorException { if (command instanceof BatchedUpdates) { execute(((BatchedUpdates)command)); } else { TranslatedCommand translatedComm = translateCommand(command); executeTranslatedCommand(translatedComm); } } JDBCUpdateExecution(Command command, Connection connection, ExecutionContext context, JDBCExecutionFactory env); }
JDBCUpdateExecution extends JDBCBaseExecution implements UpdateExecution { @Override public void execute() throws TranslatorException { if (command instanceof BatchedUpdates) { execute(((BatchedUpdates)command)); } else { TranslatedCommand translatedComm = translateCommand(command); executeTranslatedCommand(translatedComm); } } JDBCUpdateExecution(Command command, Connection connection, ExecutionContext context, JDBCExecutionFactory env); @Override void execute(); int[] execute(BatchedUpdates batchedCommand); @Override int[] getUpdateCounts(); void setMaxPreparedInsertBatchSize(int maxPreparedInsertBatchSize); void setAtomic(boolean atomic); }
JDBCUpdateExecution extends JDBCBaseExecution implements UpdateExecution { @Override public void execute() throws TranslatorException { if (command instanceof BatchedUpdates) { execute(((BatchedUpdates)command)); } else { TranslatedCommand translatedComm = translateCommand(command); executeTranslatedCommand(translatedComm); } } JDBCUpdateExecution(Command command, Connection connection, ExecutionContext context, JDBCExecutionFactory env); @Override void execute(); int[] execute(BatchedUpdates batchedCommand); @Override int[] getUpdateCounts(); void setMaxPreparedInsertBatchSize(int maxPreparedInsertBatchSize); void setAtomic(boolean atomic);  }