use of org.teiid.translator.jdbc.JDBCProcedureExecution in project teiid by teiid.
the class TestOracleTranslator method testCursorResult.
@Test
public void testCursorResult() throws Exception {
// $NON-NLS-1$
String input = "call proc('foo')";
// $NON-NLS-1$
String output = "{call proc(?,?)}";
String ddl = "create foreign procedure proc (in x string, out y object options (native_type 'REF CURSOR')) returns table (a string);";
Command command = helpTestVisitor(RealMetadataFactory.fromDDL(ddl, "x", "y"), input, EMPTY_CONTEXT, null, output);
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(2)).toReturn(rs);
// $NON-NLS-1$
Mockito.stub(connection.prepareCall(output)).toReturn(cs);
OracleExecutionFactory ef = new OracleExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
procedureExecution.execute();
// TODO we may not want to actually return the resultset, but this ensures full compatibility
assertEquals(Arrays.asList(rs), procedureExecution.getOutputParameterValues());
Mockito.verify(cs, Mockito.times(1)).registerOutParameter(2, OracleExecutionFactory.CURSOR_TYPE);
}
use of org.teiid.translator.jdbc.JDBCProcedureExecution 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.translator.jdbc.JDBCProcedureExecution in project teiid by teiid.
the class TestOracleTranslator method testProcedureExecution.
@Test
public void testProcedureExecution() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call spTest8(1)");
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("{?= call spTest8(?,?)}")).toReturn(cs);
OracleExecutionFactory ef = new OracleExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
procedureExecution.execute();
assertEquals(Arrays.asList(4), procedureExecution.getOutputParameterValues());
Mockito.verify(cs, Mockito.times(1)).registerOutParameter(1, OracleExecutionFactory.CURSOR_TYPE);
Mockito.verify(cs, Mockito.times(1)).getObject(1);
}
Aggregations