Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/nonJDBCArgsToStoredProcedures"

(How to handle nonJDBC arguments for Oracle Stored Procedures)
(How to handle nonJDBC arguments for Oracle Stored Procedures)
Line 10: Line 10:
  
 
the TopLink code would be:
 
the TopLink code would be:
 +
<font color="#000000">'''<font color="#7f0055">import</font>'''<font color="#7f0055"> oracle</font><font color="#7f0055">.</font><font color="#7f0055">toplink</font><font color="#7f0055">.</font><font color="#7f0055">internal</font><font color="#7f0055">.</font><font color="#7f0055">helper</font><font color="#7f0055">.</font><font color="#7f0055">NonSynchronizedVector</font><font color="#7f0055"><nowiki>;</nowiki></font>
 +
'''<font color="#7f0055">import</font>'''<font color="#7f0055"> oracle</font><font color="#7f0055">.</font><font color="#7f0055">toplink</font><font color="#7f0055">.</font><font color="#7f0055">platform</font><font color="#7f0055">.</font><font color="#7f0055">database</font><font color="#7f0055">.</font><font color="#7f0055">oracle</font><font color="#7f0055">.</font><font color="#7f0055">PLSQLStoredProcedureCall</font><font color="#7f0055"><nowiki>;</nowiki></font>
 +
'''<font color="#7f0055">import</font>'''<font color="#7f0055"> static oracle</font><font color="#7f0055">.</font><font color="#7f0055">toplink</font><font color="#7f0055">.</font><font color="#7f0055">platform</font><font color="#7f0055">.</font><font color="#7f0055">database</font><font color="#7f0055">.</font><font color="#7f0055">oracle</font><font color="#7f0055">.</font><font color="#7f0055">OraclePLSQLTypes</font><font color="#7f0055">.</font><font color="#7f0055">PLSQLBoolean</font><font color="#7f0055"><nowiki>;</nowiki></font>
 +
 +
'''<font color="#7f0055">public</font>''' '''<font color="#7f0055">class</font>''' NonJDBCTestSuite {
 +
 +
  '''<font color="#7f0055">public</font>''' '''<font color="#7f0055">static</font>''' '''<font color="#7f0055">void</font>''' main('''<font color="#7f0055">String</font>''' args[]) {
 +
    PLSQLStoredProcedureCall call = '''<font color="#7f0055">new</font>''' PLSQLStoredProcedureCall();
 +
    call.setProcedureName(<font color="#2a00ff">"bool_in_test"</font>);
 +
    call.addNamedArgument(<font color="#2a00ff">"X"</font>, PLSQLBoolean);
 +
    DataModifyQuery query = '''<font color="#7f0055">new</font>''' DataModifyQuery();
 +
    query.addArgument(<font color="#2a00ff">"X"</font>);
 +
    query.setCall(call);
 +
    '''<font color="#7f0055">Vector</font>''' queryArgs = '''<font color="#7f0055">new</font>''' NonSynchronizedVector();
 +
    queryArgs.add('''<font color="#7f0055">Integer</font>'''.valueOf(1));
 +
    s.executeQuery(query, queryArgs);
 +
  }
 +
}
 +
</font>

Revision as of 13:09, 23 November 2007

{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);
  }
}