EclipseLink/Examples/JPA/nonJDBCArgsToStoredProcedures

From Eclipsepedia

Jump to: navigation, search

{available as of EclipseLink 1.0M2}

How to handle nonJDBC arguments for Oracle Stored Procedures

The standard way of handling a Stored Procedure is to build an instance of oracle.toplink.queryframework.StoredProcedureCall. However, the arguments must be compatible with the JDBC specification.

To handle nonJDBC arguments (e.g. BOOLEAN, PLS_INTEGER, PL/SQL record, etc.) a new sub-class has been created: oracle.toplink.platform.database.oracle.PLSQLStoredProcedureCall:

For the target procedure:

procedure bool_test(x IN BOOLEAN)

the TopLink code would be:

import oracle.toplink.internal.helper.NonSynchronizedVector;
import oracle.toplink.platform.database.oracle.PLSQLStoredProcedureCall;
import static oracle.toplink.platform.database.oracle.OraclePLSQLTypes.PLSQLBoolean;

public class NonJDBCTestSuite {

  public static void main(String args[]) {
    PLSQLStoredProcedureCall call = new PLSQLStoredProcedureCall();
    call.setProcedureName("bool_in_test");
    call.addNamedArgument("X", PLSQLBoolean);
    DataModifyQuery query = new DataModifyQuery();
    query.addArgument("X");
    query.setCall(call);
    Vector queryArgs = new NonSynchronizedVector();
    queryArgs.add(Integer.valueOf(1));
    s.executeQuery(query, queryArgs);
  }
}