Add a Read Function This page last changed on Nov 28, 2008. .stickable, h1, h2, h3, h4, h5 false true Show Sticky notes Hide Sticky notes Save Cancel Oracle Data Service Integrator Documentation > Data Services Developer's Guide # How To Add a Read Function This topic describes how to add a read function to a logical entity service. Overview Create the Function in Workshop for WebLogic See Also ## Overview A read function in a logical entity service retrieves data from underlying data sources, either physical or logical, and returns XML elements in the shape of the service's return type. You can build a logical service without a read function. However, the service must have at least one read function, marked primary, to have an update map. Only one read function in a service can be primary. A read function is associated with exactly one XML schema, which is the service's return type. The read function must return the return type, but cannot take any other actions or have any side effects. When you create a primary read function visually in Workshop for WebLogic, Oracle Data Service Integrator generates a pragma annotation and XQuery source. The pragma looks something like this:
    (::pragma  function <f:function kind="read" visibility="public" isPrimary="true" xmlns:f="urn:annotations.ld.bea.com"/>::)
The initial XQuery source, before you map data types in Query Map view, shows that the read function returns an instance of the service's return type:
    declare function tns:read() as element(tns:CustomerAndAddress)*{
        <tns:CustomerAndAddress>
            <CUSTOMER>
                <CUSTOMER_ID></CUSTOMER_ID>
                <FIRST_NAME></FIRST_NAME>
                <LAST_NAME></LAST_NAME>
                <SSN?></SSN>
                {
                    <ADDRESS>
                        <ADDR_ID></ADDR_ID>
                        <CUSTOMER_ID></CUSTOMER_ID>
                        <FIRST_NAME></FIRST_NAME>
                        <ZIPCODE></ZIPCODE>
                        <COUNTRY></COUNTRY>
                    </ADDRESS>
                }
            </CUSTOMER>
        </tns:CustomerAndAddress>
    };
At this point, the return type has no values. The values are added after you map data sources to the return type in Query Map view:
    declare function tns:read() as element(tns:CustomerAndAddress)*{
    for $CUSTOMER in cus1:CUSTOMER()
    return
            <tns:CustomerAndAddress>
                <CUSTOMER>
                    <CUSTOMER_ID>{fn:data($CUSTOMER/CUSTOMER_ID)}</CUSTOMER_ID>
                    <FIRST_NAME>{fn:data($CUSTOMER/FIRST_NAME)}</FIRST_NAME>
                    <LAST_NAME>{fn:data($CUSTOMER/LAST_NAME)}</LAST_NAME>
                    <SSN?>{fn:data($CUSTOMER/SSN)}</SSN>
                    {
                        for $ADDRESS in add:ADDRESS()
                        return
                        <ADDRESS>
                            <ADDR_ID>{fn:data($ADDRESS/ADDR_ID)}</ADDR_ID>
                            <CUSTOMER_ID>{fn:data($ADDRESS/CUSTOMER_ID)}</CUSTOMER_ID>
                            <FIRST_NAME>{fn:data($ADDRESS/FIRST_NAME)}</FIRST_NAME>
                            <ZIPCODE>{fn:data($ADDRESS/ZIPCODE)}</ZIPCODE>
                            <COUNTRY>{fn:data($ADDRESS/COUNTRY)}</COUNTRY>
                        </ADDRESS>
                    }
                </CUSTOMER>
            </tns:CustomerAndAddress>
    };
1. ## Create the Function in Workshop for WebLogic Create a logical entity service.
   | Create Your First Data Services
In the Overview tab, right-click at the left, right, or top, and choose Add Operation. At Visibility, choose an access level. Public means the procedure can be called from the same dataspace and from client APIs; protected, only from the same dataspace; private, only from the same data service. At Kind, choose read. Enter a name for the function. At Return Type, click Edit. Click Complex Type, and choose a schema file. At Kind, choose element. At Occurrence, choose Zero or More. Select Primary, and click OK. ## See Also ##### How Tos Create a Return Type Test a Read Function and Simple Update ##### Concepts Data Service Types and Functions

Document generated by Confluence on Jan 13, 2009 15:57