This discussion is archived
6 Replies Latest reply: Dec 12, 2012 10:07 AM by user491422 - oracle RSS

Passing in parameters to Data Instance

970125 Newbie
Currently Being Moderated
Hi

I read in OSM 7.2 Release Notes on vf:instance :

You can now add explicit parameter values from within an XQuery or XPath that
augment or override the parameters defined in the OSM data dictionary using
vf:instance()

My question is, how do I make use of the parameters passed in in my Data Instance?

The example given in Developer's Guide says:

log:info($log,local-name(
vf:instance($order/oms:GetOrder.Response/oms:_root/oms:data[1],'DataInstance',<oms:url>file://us/catalog.xml</oms:url>)/*[1]
))

How do I make use of parameter oms:url in the Data Instance?

I tried using ${oms:url} but it gives me compile error.

I created a new namespace for the data instance to obtain the passed in parameters. Is this the correct way?
the xquery to invoke the data instance:
let $dataInstanceParams := <m1:params xmlns:m1="http://xxx.com/bcc/osm/com/orderopco/xml">
<m1:OMGroupRefID>{fn:normalize-space(im:MainOrderLineItem[0]/im:OMGroupRefID/text())}</m1:OMGroupRefID>
<m1:ActionCode>{fn:normalize-space(im:MainOrderLineItem[0]/im:ActionCode/text())}</m1:ActionCode>
</m1:params>
let $dboutput2 := vf:instance('CheckProductGroupExists',$dataInstanceParams/*)


adapter is JDBC adapter, built-in.


My Data Instance Behavior's oms:sql is:
<query xmlns:im="http://xxx.com/bcc/osm/com/orderopco">
<sql>
select opg_ref_id from C_OM_OPG_MAP
where om_product_group='{$OMGroupRefID}'
and action_code='{$ActionCode}'
</sql>
</query>


Thanks.
Will

Edited by: will.s on Dec 10, 2012 6:01 PM added xquery to invoke the data instance
  • 1. Re: Passing in parameters to Data Instance
    user491422 - oracle Journeyer
    Currently Being Moderated
    Can you show the xquery you are using to invoke the data instance?

    Also, what adapter are you using, is this the built-in DatabaseAdapter?

    Thanks,

    Brian.
  • 2. Re: Passing in parameters to Data Instance
    970125 Newbie
    Currently Being Moderated
    I created a new namespace for the data instance to obtain the passed in parameters. Is this the correct way?
    the xquery to invoke the data instance:

    let $dataInstanceParams := <m1:params xmlns:m1="http://xxx.com/bcc/osm/com/orderopco/xml">
    <m1:OMGroupRefID>{fn:normalize-space(im:MainOrderLineItem[0]/im:OMGroupRefID/text())}</m1:OMGroupRefID>
    <m1:ActionCode>{fn:normalize-space(im:MainOrderLineItem[0]/im:ActionCode/text())}</m1:ActionCode>
    </m1:params>
    let $dboutput2 := vf:instance('CheckProductGroupExists',$dataInstanceParams/*)


    adapter is JDBC adapter, built-in.


    Thanks

    Edited by: will.s on Dec 10, 2012 6:07 PM
  • 3. Re: Passing in parameters to Data Instance
    user491422 - oracle Journeyer
    Currently Being Moderated
    Hi Will;

    The DatabaseAdapter expects input parameters to be named "in:1", "in:2", "in:3" and so-on. The numbers 1, 2, 3, etc. correspond to the position of the ? entry in your SQL parameter. in:1 would be used as the value for the first ? in your sql, in:2 would be used as the value for the second ? and so-on.

    So based on this, your xquery would need to be something like this:

    let $dataInstanceParams := <m1:params xmlns:m1="http://xxx.com/bcc/osm/com/orderopco/xml">
    <in:1>{fn:normalize-space(im:MainOrderLineItem[0]/im:OMGroupRefID/text())}</in:1>
    <in:2>{fn:normalize-space(im:MainOrderLineItem[0]/im:ActionCode/text())}</in:2>
    </m1:params>
    let $dboutput2 := vf:instance('CheckProductGroupExists',$dataInstanceParams/*)

    We don't care what the namespace is that you use, but the namespace prefix must be "in:".

    For your reference, I'm copying below the full text of the Javadocs for the DatabaseAdapter. You can find the docs for this and other adapters in the OSM SDK Javadocs.

    This class implements a View Framework external instance adapter that executes a SQL statement and builds an XML document based on the result set.

    There are two mandatory parameters for this class, oms:sql and oms:dataSource.
    oms:dataSource: Refers to the jndi name of a JDBC datasource defined in WebLogic. For example 'mslv/oms/oms1/internal/jdbc/DataSource'
    oms:sql: Contains the sql that will be sent to the database. For example 'select * from scott.emp where empno=?'

    Additional optional input parameters may be supplied that will be bound to parameters defined in the oms:sql value. For example, in the above sql statement a parameter is used to define the value for 'empno' in the where clause. A value for this parameter may be specified by defining a paremter called "in:1". If there were additional input parameters defined in the sql statement, these could be passed as "in:2", "in:3" and so on.
    In all cases these input parameters will be assumed to be string values and bound to the sql statement as string values.
    The following is an example of using the DatabaseAdapter to invoke a query:
    <instance name="well_paid_salesman" xsi:type="externalInstanceType">
    <adapter>com.mslv.oms.view.rule.adapter.DatabaseAdapter</adapter> <parameter
    name="oms:dataSource">'mslv/oms/oms1/internal/jdbc/DataSource'</parameter> <parameter
    name="oms:sql">"select * from scott.emp where job='SALESMAN' and sal > ?"</parameter> <parameter
    name="in:1">1250</parameter> </instance>
    The above declaration returns the following XML instance:
    <results> <rowSet> <row> <empno>7499</empno> <ename>ALLEN</ename> <job>SALESMAN</job> <mgr>7698</mgr>
    <hiredate>1981-02-20 00:00:00.0</hiredate> <sal>1600</sal> <comm>300</comm> <deptno>30</deptno> </row> <row>
    <empno>7844</empno> <ename>TURNER</ename> <job>SALESMAN</job> <mgr>7698</mgr> <hiredate>1981-09-08
    00:00:00.0</hiredate> <sal>1500</sal> <comm>0</comm> <deptno>30</deptno> </row> </rowSet> </results>
    The DatabaseAdapter can also be used to execute SQL stored procedures.
    The DatabaseAdapter provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all RDBMSs. This escape syntax is defined as part of the Java JDBC API.
    This escape syntax has one form that includes a result parameter and one that does not. If used, the result parameter must be registered as an OUT parameter. The other parameters can be used for input, output or both. Parameters are referred to sequentially, by number, with the first parameter being 1.
    {?= call [,, ...]}
    {call [,, ...]}
    Values for input parameters to the stored procedure are specified using the in:1, in:2 (etc.) parameters in the same way as they are for regular SQL queries.
    Output parameters are specified using out:1, out:2 (etc.). Keep in mind that the parameter number (1, 2, 3, etc.) are numbered sequentially from 1 ordered from left to right in the specified SQL statement including both input and output parameters.
    The value of the parameter is the parameter SQL type (see http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Types.html for a list of types).
    The following example illustrates how to call a database stored procedure that has one output parameter (the result of the stored procedure call), and one input parameter.
    <instance name="lock_count" xsi:type="externalInstanceType">
    <adapter>com.mslv.oms.view.rule.adapter.DatabaseAdapter</adapter> <parameter
    name="oms:dataSource">'mslv/oms/oms1/internal/jdbc/DataSource'</parameter> <parameter
    name="oms:sql">"{? = call om_cartridge_pkg.get_any_cartridge_id('my_cartridge',?)}"</parameter> <parameter
    name="out:1">'INTEGER'</parameter> <parameter name="in:2">'1.1'</parameter> </instance>
    The above declaration returns the following XML instance:
    <results> <outputParameter number="1">1234</outputParameter> </results>
  • 4. Re: Passing in parameters to Data Instance
    970125 Newbie
    Currently Being Moderated
    Thanks Brian.

    What do I put in in:n parameters' expressions in Data Instance behaviour?

    Thanks.
    Will
  • 5. Re: Passing in parameters to Data Instance
    970125 Newbie
    Currently Being Moderated
    Hi Brian
    When I do this:
    let $dataInstanceParams := <m1:params xmlns:m1="http://xxx.com/bcc/osm/com/orderopco/xml">
    <in:1>{fn:normalize-space(saxon:evaluate(im:MainOrderLineItem[1]/im:OMGroupRefID/text()))}</in:1>
    <in:2>{fn:normalize-space(saxon:evaluate(im:MainOrderLineItem[1]/im:ActionCode/text()))}</in:2>
    </m1:params>

    During deploy I get the error:
    net.sf.saxon.trans.XPathException: XQuery syntax error in #.../com/orderopco/xml"> <in:1>#:
    Invalid element name <in:1>

    Kindly advise

    Will
  • 6. Re: Passing in parameters to Data Instance
    user491422 - oracle Journeyer
    Currently Being Moderated
    Hi Will;

    Looks like we have a problem.

    An XML element name cannot start with a number, so in:1, in:2 etc. are invalid elements.

    Unfortunately this wil require a core product change to the DatabaseAdapter.

    Please contact customer support and reference this thread (provide the URL).

    Thanks,

    Brian.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points