use of org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl in project teiid by teiid.
the class TestOracleTranslator method testCharType.
@Test
public void testCharType() throws Exception {
CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
Command command = commandBuilder.getCommand("select id from smalla where description = 'a' and ndescription in ('b', 'c')");
for (Literal l : CollectorVisitor.collectObjects(Literal.class, command)) {
l.setBindEligible(true);
}
Connection connection = Mockito.mock(Connection.class);
PreparedStatement ps = Mockito.mock(PreparedStatement.class);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("SELECT SmallishA.ID FROM SmallishA WHERE SmallishA.description = ? AND SmallishA.ndescription IN (?, ?)")).toReturn(ps);
OracleExecutionFactory ef = new OracleExecutionFactory();
ef.start();
JDBCQueryExecution e = new JDBCQueryExecution(command, connection, new FakeExecutionContextImpl(), ef);
e.execute();
Mockito.verify(ps, Mockito.times(1)).setObject(1, "a", OracleExecutionFactory.FIXED_CHAR_TYPE);
Mockito.verify(ps, Mockito.times(1)).setObject(2, "b", OracleExecutionFactory.FIXED_CHAR_TYPE);
}
use of org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl in project teiid by teiid.
the class TestOracleTranslator method testSourceHint2.
@Test
public void testSourceHint2() throws Exception {
ExecutionContextImpl impl = new FakeExecutionContextImpl();
impl.setHints(Arrays.asList("hello world"));
helpTestVisitor(getTestVDB(), "with x (y) as /*+ no_inline */ (select part_name from parts) select y from x", impl, null, "WITH x AS (SELECT g_0.PART_NAME AS y FROM PARTS g_0) SELECT /*+ hello world */ g_1.y FROM x g_1", true);
}
use of org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl in project teiid by teiid.
the class TestJDBCDirectQueryExecution method testPrepareUpdateCount.
@Test
public void testPrepareUpdateCount() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('update source set e1=? where e2 = ?', 2, 'foo')");
Connection connection = Mockito.mock(Connection.class);
PreparedStatement stmt = Mockito.mock(PreparedStatement.class);
ResultSet rs = Mockito.mock(ResultSet.class);
ResultSetMetaData rsm = Mockito.mock(ResultSetMetaData.class);
Mockito.stub(stmt.getUpdateCount()).toReturn(-1);
Mockito.stub(stmt.getUpdateCount()).toReturn(5);
Mockito.stub(stmt.execute()).toReturn(false);
Mockito.stub(rs.getMetaData()).toReturn(rsm);
Mockito.stub(rsm.getColumnCount()).toReturn(2);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("update source set e1=? where e2 = ?")).toReturn(stmt);
DatabaseMetaData dbmd = Mockito.mock(DatabaseMetaData.class);
Mockito.stub(connection.getMetaData()).toReturn(dbmd);
JDBCExecutionFactory ef = new JDBCExecutionFactory();
ef.setSupportsDirectQueryProcedure(true);
ResultSetExecution execution = (ResultSetExecution) ef.createExecution(command, new FakeExecutionContextImpl(), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] { 5 }, (Object[]) execution.next().get(0));
}
use of org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl in project teiid by teiid.
the class TestJDBCUpdateExecution method testAutoGeneretionKeysPrepared.
@Test
public void testAutoGeneretionKeysPrepared() throws Exception {
// $NON-NLS-1$
Insert command = (Insert) TranslationHelper.helpTranslate("create foreign table SmallA (IntKey integer 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();
((org.teiid.query.util.CommandContext) context.getCommandContext()).setReturnAutoGeneratedKeys(Collections.EMPTY_LIST);
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));
}
use of org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl in project teiid by teiid.
the class TestJDBCUpdateExecution method testPreparedInsertWithGeometry.
@Test
public void testPreparedInsertWithGeometry() throws Exception {
// $NON-NLS-1$
Insert command = (Insert) TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "insert into cola_markets(name,shape) values('foo124', ST_GeomFromText('POINT (300 100)', 8307))");
Parameter param = new Parameter();
param.setType(DataTypeManager.DefaultDataClasses.STRING);
param.setValueIndex(0);
List<Expression> values = ((ExpressionValueSource) command.getValueSource()).getValues();
values.set(0, param);
param = new Parameter();
param.setType(DataTypeManager.DefaultDataClasses.GEOMETRY);
param.setValueIndex(1);
values.set(1, param);
GeometryType value = new GeometryType();
value.setSrid(123);
command.setParameterValues(Arrays.asList(Arrays.asList("a", value)).iterator());
Connection connection = Mockito.mock(Connection.class);
PreparedStatement p = Mockito.mock(PreparedStatement.class);
Mockito.stub(p.executeBatch()).toReturn(new int[] { 1 });
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("INSERT INTO COLA_MARKETS (NAME, SHAPE) VALUES (?, st_geomfromwkb(?, ?))")).toReturn(p);
JDBCExecutionFactory config = new JDBCExecutionFactory();
JDBCUpdateExecution updateExecution = new JDBCUpdateExecution(command, connection, new FakeExecutionContextImpl(), config);
updateExecution.execute();
Mockito.verify(p, Mockito.times(1)).addBatch();
Mockito.verify(p, Mockito.times(1)).setObject(1, "a", Types.VARCHAR);
Mockito.verify(p, Mockito.times(1)).setInt(3, 123);
}
Aggregations