Search in sources :

Example 1 with JDBCProcedureExecution

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);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JDBCProcedureExecution(org.teiid.translator.jdbc.JDBCProcedureExecution) Test(org.junit.Test)

Example 2 with JDBCProcedureExecution

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);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JDBCProcedureExecution(org.teiid.translator.jdbc.JDBCProcedureExecution) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 3 with JDBCProcedureExecution

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);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JDBCProcedureExecution(org.teiid.translator.jdbc.JDBCProcedureExecution) Test(org.junit.Test)

Aggregations

CallableStatement (java.sql.CallableStatement)3 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)3 Test (org.junit.Test)3 Command (org.teiid.language.Command)3 ExecutionContext (org.teiid.translator.ExecutionContext)3 JDBCProcedureExecution (org.teiid.translator.jdbc.JDBCProcedureExecution)3 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)3 CommandBuilder (org.teiid.cdk.CommandBuilder)1