use of org.teiid.translator.jdbc.JDBCQueryExecution in project teiid by teiid.
the class TestOracleTranslator method testDependentJoin.
@Test
public void testDependentJoin() throws Exception {
CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
Select command = (Select) commandBuilder.getCommand("select id from smalla where description = 'a'");
Parameter param = new Parameter();
param.setType(TypeFacility.RUNTIME_TYPES.STRING);
param.setDependentValueId("x");
param.setValueIndex(0);
Map<String, List<? extends List<?>>> dependentValues = new HashMap<String, List<? extends List<?>>>();
dependentValues.put("x", Arrays.asList(Arrays.asList("a"), Arrays.asList("b")));
command.setDependentValues(dependentValues);
((Comparison) command.getWhere()).setRightExpression(param);
Connection connection = Mockito.mock(Connection.class);
Statement statement = Mockito.mock(Statement.class);
Mockito.stub(connection.createStatement()).toReturn(statement);
PreparedStatement ps = Mockito.mock(PreparedStatement.class);
Mockito.stub(ps.executeBatch()).toReturn(new int[] { -2, -2 });
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("INSERT INTO TEIID_DKJ1 (COL1) VALUES (?)")).toReturn(ps);
// we won't bother to retrieve the results, but we expect the following join query
PreparedStatement ps1 = Mockito.mock(PreparedStatement.class);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("SELECT SmallishA.ID FROM TEIID_DKJ1, SmallishA WHERE SmallishA.description = TEIID_DKJ1.COL1")).toReturn(ps1);
OracleExecutionFactory ef = new OracleExecutionFactory() {
public String getTemporaryTableName(String prefix) {
// don't use random for testing
return prefix;
}
};
ef.setDatabaseVersion(Version.DEFAULT_VERSION);
ef.start();
JDBCQueryExecution e = new JDBCQueryExecution(command, connection, new FakeExecutionContextImpl(), ef);
e.execute();
Mockito.verify(statement, Mockito.times(1)).execute("DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN EXECUTE IMMEDIATE 'create global temporary table TEIID_DKJ1 (COL1 varchar2(100 char)) on commit delete rows; END;");
Mockito.verify(ps, Mockito.times(1)).setObject(1, "a", Types.VARCHAR);
Mockito.verify(ps, Mockito.times(1)).setObject(1, "b", Types.VARCHAR);
Mockito.verify(ps, Mockito.times(2)).addBatch();
Mockito.verify(ps, Mockito.times(1)).executeBatch();
}
use of org.teiid.translator.jdbc.JDBCQueryExecution 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);
}
Aggregations