Samples Tutorial

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Integrating Data from Multiple Data Sources

The power of logical data services in Data Services Platform (ALDSP) is the ability to integrate and transform data from multiple physical and logical data services.

In the previous lesson, you created a simple logical data service that mapped to a single physical data service. In this lesson, you will further develop the logical data service to enable data retrieval from multiple data services.

 


Objectives

After completing this lesson, you will be able to:

 


Overview

How is data integration different from process integration? Most applications involve a combination of informational interactions and transactional interactions. Examples of informational interaction include: get customer info, review order status, get customer profile, and get customer's case history. Examples of transactional interactions include: place order, update customer address, and create customer.

Informational interactions involve efficiently aggregating discrete pieces of data that are potentially resident in multiple data sources, and potentially in multiple data formats. Developers can end up spending inordinate amounts of time writing custom code to handle the various interface protocols and data formats, and integrate disparate data into manageable, business-relevant information. ALDSP simplifies this activity by providing a simple, declarative approach to aggregating data from heterogeneous data sources.

Transactional interactions involve taking a piece of data (say a purchase order) and orchestrating its propagation to the various underlying applications. This involves coordinating a business process through a formal or informal workflow, managing long-running processes, managing human interactions (such as a supervisor approval to an order), handling applications that have indeterminate response times (such as batch systems), maintaining transactional integrity across applications, etc.

Both data integration and process integration are essential elements when building applications that handle information from across multiple data sources. For functions of interest across data services, you can use function libraries. A function library (.xfl file) contains operations that return simple types (not the XML data type of a standard data service) that can be called from various data services. Read functions on a data service can be defined to return information in various ways. For example, the data service may define read functions for getting all customers, customers by region, or customers with a minimum order amount.

 


4.1 Joining Multiple Physical Data Services within a Logical Data Service

In the previous exercise, you mapped a single physical data service to the Return type. In this exercise, you will enable data retrieval from both the CUSTOMER and CUSTOMER_ORDER physical data services.

Objectives

In this exercise, you will:

Instructions

  1. Open CustomerProfile.ds in XQuery Editor View.
  2. Select the getAllCustomer() function.
  3. In the Data Services Palette, expand ApparelDB\CUSTOMER_ORDER data service.
  4. Drag and drop the data service's CUSTOMER_ORDER() function into XQuery Editor View to create a second for node, For:$CUSTOMER_ORDER.
  5. Create a simple map: Drag and drop the individual elements from the $CUSTOMER_ORDER source node onto their corresponding elements in the Return type.
Note: Do not map the TRACKING_NUMBER and DATE_INT elements.
  1. Create a join: Drag and drop the CUSTOMER_ID element from the $CUSTOMER source node onto the C_ID element in the $CUSTOMER_ORDER source node. This action joins the two for nodes. By joining these two nodes, you automatically create a where clause within the FLWOR statement.
  2. Figure 4-1 Joined Data Services


    Joined Data Services

  3. Select the Source View tab to view the XQuery code. You should see a where clause joining $CUSTOMER and $CUSTOMER_ORDER, using CUSTOMER_ID and C_ID as join elements. In Figure 4-2, the where clause is:
  4. where $CUSTOMER/CUSTOMER_ID = $CUSTOMER_ORDER/C_ID
    Figure 4-2 Source View of Joined Data Services


    Source View of Joined Data Services

  5. Build the DataServices project. Right-click the DataServices project folder and choose Build DataServices.
  6. After the build is successful, select the Test View tab in order to retrieve order information integrated with the customer information. You can do this by completing the following steps:
    1. Select getAllCustomers() from the function drop-down list.
    2. Click Execute. (You don't need any parameters, because you are not testing the limit returned tuples feature.)
    3. Expand the nodes. The results should include order information for each customer, as displayed in Figure 4-3.
Note: If the Validate Results option is selected, you will see a warning indicating that results do not conform to the associated XML type. The warning can be ignored.
Figure 4-3 Integrated Customer and Order Data Results

Integrated Customer and Order Data Results

 


4.2 Defining a Where Clause to Join Multiple Physical Data Services

In the previous exercise, you joined the CUSTOMER and CUSTOMER_ORDER data services, thereby automatically generating a where clause. In this exercise, you will manually define the where clause that joins multiple data services.

Objectives

In this exercise, you will:

Instructions

  1. Switch to XQuery Editor View for the getAllCustomers() function.
  2. In the Data Services Palette, expand ApparelDB\CUSTOMER_ORDER_LINE_ITEM data services.
  3. Drag and drop the CUSTOMER_ORDER_LINE_ITEM() function from the Data Service palette into the data service's XQuery Editor View. This creates a third for node:
  4. For: $CUSTOMER_ORDER_LINE_ITEM.
  5. Create simple mappings by dragging and dropping the individual elements from the $CUSTOMER_ORDER_LINE_ITEM source node onto the corresponding elements in the Return type.
  6. Figure 4-4 Three Data Service Functions Mapped to the Return Type


    Three Data Service Functions Mapped to the Return Type

  7. Define a where clause for CUSTOMER_ORDER and CUSTOMER_ORDER_LINE_ITEM, by completing the following steps:
    1. Select the node header (For: $CUSTOMER_ORDER_LINE_ITEM) to activate the expression editor for that node. (Note: Do not select the CUSTOMER_ORDER_LINE_ITEM* element.)
    2. Click the Where clause icon.
    3. Put your cursor into the where expression line editor.
    4. Click the ORDER_ID element in the $CUSTOMER_ORDER_LINE_ITEM source node. You should see the following in the WHERE field (the variable name may be different, in your case):
    5.  $CUSTOMER_ORDER_LINE_ITEM/ORDER_ID
    6. Select eq: Compare Single Values from the operator list ("..." icon). Since the Where clause is incomplete, the text will go red. The Where field now appears as:
    7. $CUSTOMER_ORDER_LINE_ITEM/ORDER_ID eq
    8. Click the ORDER_ID element in the CUSTOMER_ORDER source node. The Where clause becomes valid and you should see the following in the where field (the variable name may be different, in your case):
    9. $CUSTOMER_ORDER_LINE_ITEM/ORDER_ID eq $CUSTOMER_ORDER/ORDER_ID
    10. Click the Accept box (green checkmark icon) to add the parameterized WHERE clause to the getAllCustomers() function.
    11. Figure 4-5 Where Clause Joining Two Data Services


      Where Clause Joining Two Data Services

  8. Verify the joins you created and view the results by completing the following steps:
    1. Open CustomerProfile.ds in Design View. The physical data services associated with the three functions that you dropped into XQuery Editor View as for nodes are displayed in the right pane as data sources for the logical data service.
    2. Figure 4-6 Design View of Integrated and Parameterized Data Service


      Design View of Integrated and Parameterized Data Service

    3. Open CustomerProfile.ds in Source View. The XQuery code for the logical data service is displayed.
    4. Figure 4-7 Source Code for Data Integrated with WHERE Clauses and Parameters


      Source Code for Data Integrated with WHERE Clauses and Parameters

  9. Test the results, by completing the following steps:
    1. Build the DataServices project.
    2. Open CustomerProfile.ds in Test View.
    3. Select getAllCustomers() from the function drop-down list.
    4. Set the element (by path) option to CustomerProfile/customer.
    5. Click Execute. (You do not need any parameters.)
    6. Expand the nodes and confirm that you can retrieve order line information integrated with order information, similar to that displayed in Figure 4-8. (You can use customer_id = CUSTOMER3 to verify this information).
    7. Click Edit.
    8. Navigate to the Orders node for CUSTOMER3 and update handling_charge information for ORDER_3_0 by double clicking the element content (the 6.8 value).
    9. Change to any value other than the current value.
    10. Confirm your new value by pressing Submit button.
    11. Verify that the update was done successfully by re-executing getAllCustomers() function and navigating to order information for CUSTOMER3.
    12. Figure 4-8 Order Line Data Integrated Withing Order Information


      Order Line Data Integrated Withing Order Information

 


4.3 Creating a Parameterized Function

Adding a parameter to a function ensures that the consuming application can access specific user-defined data, such as an individual customer's profile information.

Objectives

In this exercise, you will:

Instructions

  1. In Design View, create a new function for the CustomerProfile data service, and name it getCustomerProfile().
  2. Click getCustomerProfile() to open XQuery Editor View for that function.
  3. In the Data Services Palette, expand CustomerManagement\CustomerProfile data service.
  4. Drag and drop getAllCustomers() into the XQuery Editor View. You should see a new for node. For: $CustomerProfile, with its shape defined by the CustomerProfile logical data service's getAllCustomers() function.
  5. Figure 4-9 Complex Element Node


    Complex Element Node

Note: In a previous exercise, you defined getAllCustomers() to include a complex, nested customer element associated with the customer_id element of the $CUSTOMER_ORDER_LINE_ITEM source. You must set the context of the $CustomerProfile source node to point to the customer element because customer_id uses a string parameter for filtering.
  1. Create a parameter by completing the following steps:
    1. Right-click an empty space in XQuery Editor View.
    2. Select Add Parameter.
    3. Enter CustomerID in the Parameter Name field.
    4. Select xs:string from the Primitive Type drop-down list.
    5. Click OK.
    6. Figure 4-10 Add Parameter


      Add Parameter

Note: You may need to move the $CustomerProfile node to make the parameter node visible.
  1. Create a complex, overwrite mapping, by completing the following steps:
    1. Press Ctrl.
    2. Drag and drop the $CustomerProfile customer* element onto the customer+ element in the Return type.
  2. Create a join: Drag and drop the parameter's string element onto the customer_id element of the $CustomerProfile source node. This joins the string parameter to the $CustomerProfile source node and creates a function that will return data based on the user-specified parameter. (You will see this in action in the next exercise.)
  3. Figure 4-11 Data Source Node and Parameter Joined


    Data Source Node and Parameter Joined

  4. Select the Source View tab and confirm that the XQuery code for the getCustomerProfile() function is as follows:
  5. declare function tns:getCustomerProfile($CustomerID as xs:string) as element(ns0:CustomerProfile)* {
        <ns0:CustomerProfile>
            {
                for $CustomerProfile in tns:getAllCustomers()/customer
                where $CustomerID = $CustomerProfile/customer_id
                return
                $CustomerProfile
            }
        </ns0:CustomerProfile> 
  6. Remove the asterisk * from the return type element(ns0:CustomerProfile)*, because this function, as currently written, will return all customer profiles. The exercise calls for returning a single customer profile. Thus your source should be similar to that displayed in Figure 4-12.
  7. Figure 4-12 Source Code for a Parameterized and Complex Overwrite Mapped Function


    Source Code for a Parameterized and Complex Overwrite Mapped Function

  8. Test the function, by completing the following steps:
    1. Build your project.
    2. Open CustomerProfile.ds in Test View.
    3. Select getCustomerProfile(CustomerID) from the function drop-down list.
    4. Enter CUSTOMER3 in the xs:string CustomerID Parameter field. (Note: The parameter is case-sensitive.)
    5. Press Execute.
    6. Confirm that you retrieved the requested information — customer, orders, and order line items for Britt Pierce.
    7. Figure 4-13 Integrated Data Results


      Integrated Data Results

 


Lesson Summary

In this lesson, you learned how to:


  Back to Top       Previous  Next