Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Examples/JPA/nonJDBCArgsToStoredProcedures

< EclipseLink‎ | Examples‎ | JPA
Revision as of 13:08, 23 November 2007 by Unnamed Poltroon (Talk) (How to handle nonJDBC arguments for Oracle Stored Procedures)

{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:

<span style='color:#7f0055; font-weight:bold; '>import</span><span style='color:#7f0055; '> oracle</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>toplink</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>internal</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>helper</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>NonSynchronizedVector</span><span style='color:#7f0055; '>;</span>
<span style='color:#7f0055; font-weight:bold; '>import</span><span style='color:#7f0055; '> oracle</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>toplink</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>platform</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>database</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>oracle</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>PLSQLStoredProcedureCall</span><span style='color:#7f0055; '>;</span>
<span style='color:#7f0055; font-weight:bold; '>import</span><span style='color:#7f0055; '> static oracle</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>toplink</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>platform</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>database</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>oracle</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>OraclePLSQLTypes</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>PLSQLBoolean</span><span style='color:#7f0055; '>;</span>

<span style='color:#7f0055; font-weight:bold; '>public</span> <span style='color:#7f0055; font-weight:bold; '>class</span> NonJDBCTestSuite {

  <span style='color:#7f0055; font-weight:bold; '>public</span> <span style='color:#7f0055; font-weight:bold; '>static</span> <span style='color:#7f0055; font-weight:bold; '>void</span> main(<span style='color:#7f0055; font-weight:bold; '>String</span> args[]) {
    PLSQLStoredProcedureCall call = <span style='color:#7f0055; font-weight:bold; '>new</span> PLSQLStoredProcedureCall();
    call.setProcedureName(<span style='color:#2a00ff; '>"bool_in_test"</span>);
    call.addNamedArgument(<span style='color:#2a00ff; '>"X"</span>, PLSQLBoolean);
    DataModifyQuery query = <span style='color:#7f0055; font-weight:bold; '>new</span> DataModifyQuery();
    query.addArgument(<span style='color:#2a00ff; '>"X"</span>);
    query.setCall(call);
    <span style='color:#7f0055; font-weight:bold; '>Vector</span> queryArgs = <span style='color:#7f0055; font-weight:bold; '>new</span> NonSynchronizedVector();
    queryArgs.add(<span style='color:#7f0055; font-weight:bold; '>Integer</span>.valueOf(1));
    s.executeQuery(query, queryArgs);
  }
}

Back to the top