Reusing XQuery Code through Vertical View Unfolding
ALDSP enables powerful data service code reusability.
Objectives
After completing this lesson, you will be able to:
Re-use code.
Unfold vertical file view.
Overview
ALDSP enables powerful data service code reusability. You can develop your logic once, and then re-use it later when building other data services. This feature is called view unfolding.
In addition to code reuse, ALDSP is smart enough to optimize your output and only query sources and elements that you request in your data service (vertical view unfolding).
27.1 Unfolding Vertical View
You will reuse the CustomerProfile data service previously built to retrieve Customer Order information. The CustomerProfile data service is built from three different tables in the underlying PointBase database: CUSTOMER, CUSTOMER_ORDER and CUSTOMER_ORDER_LINE_ITEM.
Objectives
In this exercise, you will:
Import the CustomerOrder data service into the CustomerManagement folder.
Import CustomerOrder.xsd, and then associate the schema with the CustomerOrder data service.
Implement a query function, and define its conditions.
Instructions
Import CustomerOrder.ds into DataServices\CustomerManagement. The file is located in <beahome>\weblogic81\samples\LiquidData\EvalGuide.
Import CustomerOrder.xsd into DataServices\CustomerManagement\schemas. The file is also located in <beahome>\weblogic81\samples\LiquidData\EvalGuide.
Implement the getCustomerOrder() function in the CustomerOrder data service, by completing the following steps:
Open CustomerOrder.ds in XQuery Editor View.
In Data Services Palette, drag and drop getAllCustomers() into XQuery Editor View. The method call is located in the folder:
DataServices\CustomerManagement\CustomerProfile
Set the conditions for the function, by completing the following steps:
Select the Customer* element. This will activate the Expression Editor and make visible the ns2:getAllCustomers()/customer expression. You will use the Expression Editor to scope the data returned in the getAllCustomers() function.
Figure 27-1 Default Expression
Triple-click the Expression field.
Modify the expression by adding the following code:
ns2:getAllCustomers()/customer/orders/order
Click the green checkmark icon to accept the changes. The CustomerProfile* element changes to the order* element, and the For:$CustomerProfile schema now includes the order elements.
Figure 27-2 Modified Expression
Create a simple mapping: Drag and drop all order* elements (source node) to the corresponding CUSTOMER_ORDER elements in the Return type.
Figure 27-3 XQuery Editor View—Mappings
Save the data service file.
Open CustomerOrders.ds in Source View and notice that the function is using the CustomerProfile file as its data source.
Figure 27-4 Source View of Vertical File Unfolding Function
27.2 Testing a Vertical File Unfolding
Testing a vertical file unfolding is similar to testing any other data service function.
Objectives
In this exercise, you will:
Test the CustomerOrder data service.
Review the results.
Instructions
Open CustomerOrders.ds in Test View.
Select getCustomerOrder() from the function drop-down list.
Click Execute.
Confirm that you can retrieve customer order information.
Figure 27-5 Vertical File Unfolding Test Results
Lesson Summary
In this lesson, you learned how to:
Build a data service based on another data service (view unfolding)