Create Logical Data Service Keys This page last changed on Nov 27, 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 Create Logical Data Service Keys This topic describes how to create a key for a logical data service. Overview Generate a Key Select Elements for a Key Select a Key Schema File View and Map a Key See Also ## Overview A logical data service key uniquely identifies a data record the logical service defines. Because a logical service combines data from various physical and logical services, its key can combine or be different from the keys defined on underlying data sources. For example, you might have a logical data service with a flat return type that combines data from two relational tables, CUSTOMER and ORDER. These tables have keys CUSTOMER_ID and ORDER_ID, respectively. In your logical data service, each data record is a unique combination of Customer and Order, so you create a composite key that combines CUSTOMER_ID and ORDER_ID. Create procedures return a key to identify the data record that was inserted. Update and Delete procedures act on the data record the key identifies. A logical data service can have one key, although you can have multiple key schema files from which you select the key. You can have Oracle Data Service Integrator auto-generate the key, choose the elements you want in the key, or select an available schema (XSD) file to use for the key. The key definition requires specific knowledge of your data and the update map the service uses. You can create a key for any logical data service that has a primary Read function. Once you create the key, you can view it in an update map and test it. ## Generate a Key For an auto-generated key, Oracle Data Service Integrator uses elements from the return type of the primary Read function that are designated as keys in the underlying data sources and have single (1..1) cardinality. To auto-generate the key: Be sure the logical data service has a primary Read function. Open the logical data service in Workshop for WebLogic, and click the Overview tab. Right-click in the service name bar, or at the left or right of the screen, and choose Manage Key. Select Generate a New Schema. Accept the default key name, or give your key a name ending in .xsd. Click Next. Select Auto Generate the Key, then click Finish. ##### Auto-Generating a Logical Data Service Key You can now use the key as an argument or return type to an update map procedure, such as a Create, Update, or Delete procedure. If you create a key, then delete it and create another one, you need to edit the signature of your Create procedure to return the new key: Overview tab > right-click > Edit Signature ## Select Elements for a Key When you select elements for a key, you can add any element with single (1..1) or zero (0..1) cardinality, whether or not it is a key element in the underlying data source. An element with zero cardinality is optional and might contain null values, but you can use it as a key element. This allows you to create a wider variety of keys. For example, you might have two data sources, one using a Social Security Number to identify records, and the other, a tax identification number. Your logical data service might have a return type that joins the two sources, so that a data record has either a social security number or a tax ID number. In the return type, both the social security number and the tax ID number are optional. The key can use either element to identify the record.
| You cannot select an element that has multiple (0..m or 1..m) cardinality to be part of a key.
To create a key with elements that you select: Be sure the logical data service has a primary Read function. Open the logical data service in Workshop for WebLogic. Click the Overview tab. Right-click in the service name bar, or the left or right of the screen, and choose Manage Keys. Click Generate a New Schema. Give your key schema a name ending in .xsd. Click Manually select the fields that make up the key. Select the key fields you want, then click Finish. ##### Selecting Elements for a Key ## Select a Key Schema File You can also select an existing schema (XSD) file to use as the key: Be sure the logical data service has a primary Read function. Open the logical data service in Workshop for WebLogic. Click the Overview tab. Right-click in the service name bar, or the left or right of the screen, and choose Manage Key. Click Select an existing schema type, then Browse. The Manage Keys dialog shows you the key schema's global element and selector element. Click Finish. The schema in the Overview tab now displays a key icon next to the current key element or elements. ##### Selecting the Key Schema ## View and Map a Key Once you create the key (whether by auto-generating, identifying key fields, or selecting a key schema file), you can see the key elements in the service's update map, at the lower left. ##### Viewing the Key in the Update Map The Return Key block represents the key elements a Create procedure returns when a new data record is added. In most cases, the key fields are automatically mapped to elements in the data sources on the left. If they are not mapped, you can add a mapping. Locate the Update block on the left that contains the key element. Drag from the key element in the Update block to the key element in the Return Key block. ##### Mapping a Key Element from an Update Block to the Return Key
| Map the key element from an update block on the left, not from the return type on the right. If you map the key from the return type on the right, you allow the key value to be updated from data a user enters.
Once the key element is mapped, you can test it (preferably using sample data): Click the Test tab. At Select operation, choose one of the service's Create procedures. Enter data in the XML template in the Parameters box. Click Run. The key value is returned in the Result box: You can also view the key schema file by locating the key in the Project Explorer, right-clicking, and choosing an XML editor to open the file. A key schema looks like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema targetNamespace="ld:logical/CustomerOrder" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="CustomersAndOrders_KEY">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="CUSTOMER_ID" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
In the key schema, all elements must be in the same namespace as the root element. In the previous example, the namespace of the root element is: ld:logical/CustomerOrder A key schema cannot contain elements in different namespaces.
| If you have key schema files from a previous version of Oracle Data Service Integrator that you want to reuse, be sure that all elements within the schema are in the same namespace.
## See Also ##### Concepts Data Service Keys

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