This page last changed on Mar 24, 2008.
Physical Data Service from a Java Function - Example CodeThis topic provides examples showing the use of imported Java functions in an XQuery and the processing of complex types. Using a Function Returning an Array of Java PrimitivesAs an example, the Java function getRunningTotal can be defined as follows: public static float[] getRunningTotal(float[] list) { if (null == list || 1 >= list.length) return list; for (int i = 1; i < list.length; i++) { list[i] = list[i-1] + list[i]; } return list; } The corresponding XQuery for executing the above function is as follows: Declare namespace f1="ld:javaFunc/float"
Let $y := (2.0, 4.0, 6.0, 8.0, 10.0)
Let $x := f1:getRunningTotal($y)
Return $x
The results of the query is as follows: 2.0, 6.0, 12.0, 20.0, 30.0 Processing complex types represented via XMLBeansConsider a schema called Customer (customer.xsd), as shown in the following: <?xml version="1.0" encoding="UTF-8" ?> <xs:schema targetNamespace="ld:xml/cust:/BEA_BB10000" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="CUSTOMER"> <xs:complexType> <xs:sequence> <xs:element name="FIRST_NAME" type="xs:string" minOccurs="1"/> <xs:element name="LAST_NAME" type="xs:string" minOccurs="1"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> You could compile the schema using XMLBeans to generate a Java class corresponding to the types in the schema. xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER
Following this, you can use the CUSTOMER element as shown in the following: public static xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER[] getCustomerListGivenCustomerList(xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER[] ipListOfCust) throws XmlException { xml.cust.beaBB10000.CUSTOMERDocument.CUSTOMER [] mylocalver = pListOfCust; return mylocalver; } The resulting metadata information produced by the New Physical Data Service wizard will be: (::pragma function <f:function xmlns:f="urn:annotations.ld.bea.com" kind="datasource" access="public"> <params> <param nativeType="[Lxml.cust.beaBB10000.CUSTOMERDocument$CUSTOMER;"/> </params> </f:function>::) declare function f1:getCustomerListGivenCustomerList($x1 as element(t1:CUSTOMER)*) as element(t1:CUSTOMER)* external; The corresponding XQuery for executing the above function is: declare namespace f1 = "ld:javaFunc/CUSTOMER"; let $z := ( validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>), validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>), validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>), validate(<n:CUSTOMER xmlns:n="ld:xml/cust:/BEA_BB10000"><FIRST_NAME>John2</FIRST_NAME><LAST_NAME>Smith2</LAST_NAME> </n:CUSTOMER>)) for $zz in $z return |
![]() |
Document generated by Confluence on Apr 28, 2008 15:54 |