use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testNativeQueryProcPreparedExecution.
@Test
public void testNativeQueryProcPreparedExecution() throws Exception {
CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
Command command = commandBuilder.getCommand("call proc(2)");
Connection connection = Mockito.mock(Connection.class);
CallableStatement cs = Mockito.mock(CallableStatement.class);
Mockito.stub(cs.getUpdateCount()).toReturn(-1);
ResultSet rs = Mockito.mock(ResultSet.class);
Mockito.stub(cs.getObject(1)).toReturn(rs);
Mockito.stub(cs.getInt(3)).toReturn(4);
// $NON-NLS-1$
Mockito.stub(connection.prepareCall("select x from y where z = ?")).toReturn(cs);
OracleExecutionFactory ef = new OracleExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
procedureExecution.execute();
Mockito.verify(cs, Mockito.never()).registerOutParameter(1, OracleExecutionFactory.CURSOR_TYPE);
Mockito.verify(cs, Mockito.never()).getObject(1);
Mockito.verify(cs, Mockito.times(1)).setObject(1, 2, Types.INTEGER);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method helpTestVisitor.
/**
* Helper method takes a QueryMetadataInterface impl instead of a VDB filename
* @throws TranslatorException
*/
private Command helpTestVisitor(QueryMetadataInterface metadata, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws TranslatorException {
// Convert from sql to objects
CommandBuilder commandBuilder = new CommandBuilder(metadata);
Command obj = commandBuilder.getCommand(input);
this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
return obj;
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testConcat2_useLiteral.
@Test
public void testConcat2_useLiteral() throws Exception {
// $NON-NLS-1$
String input = "select concat2(stringnum,'_xx') from bqt1.Smalla";
// $NON-NLS-1$
String output = "SELECT (g_0.StringNum || '_xx') FROM SmallA g_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
commandBuilder.getLanguageBridgeFactory().setSupportsConcat2(true);
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestOracleTranslator method testRowLimitWithUnionOrderBy.
@Test
public void testRowLimitWithUnionOrderBy() throws Exception {
// $NON-NLS-1$
String input = "(select intkey from bqt1.smalla limit 50, 100) union select intnum from bqt1.smalla order by intkey";
// $NON-NLS-1$
String output = "(SELECT c_0 FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT g_1.IntKey AS c_0 FROM SmallA g_1) VIEW_FOR_LIMIT WHERE ROWNUM <= 150) WHERE ROWNUM_ > 50) UNION SELECT g_0.IntNum AS c_0 FROM SmallA g_0 ORDER BY c_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand(input, true, true);
this.helpTestVisitor(obj, EMPTY_CONTEXT, null, output);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestJDBCDirectQueryExecution method testPrepareExecution.
@Test
public void testPrepareExecution() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('select * from Source where e1 = ?', 2)");
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.getResultSet()).toReturn(rs);
Mockito.stub(stmt.execute()).toReturn(true);
Mockito.stub(rs.getMetaData()).toReturn(rsm);
Mockito.stub(rsm.getColumnCount()).toReturn(2);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("select * from Source where e1 = ?")).toReturn(stmt);
Mockito.stub(rs.next()).toReturn(true);
Mockito.stub(rs.getObject(1)).toReturn(5);
Mockito.stub(rs.getObject(2)).toReturn("five");
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();
Mockito.verify(stmt).setObject(1, 2);
assertArrayEquals(new Object[] { 5, "five" }, (Object[]) execution.next().get(0));
}
Aggregations