Samples Tutorial

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

Creating a Logical Data Service

As noted in Tutorial 2, there are two types of data services: physical and logical. Physical data services model a single physical data source residing in a relational database, Web service, flat file, XML file, or Java function.

To enable the integration of data from multiple sources through Data Services Platform (ALDSP), you define a logical data service. In this lesson you will create a logical data service that integrates data from the CUSTOMER data service.

 


Objectives

After completing this lesson, you will be able to:

 


Overview

A logical data service integrates data from two or more physical or logical data services. Its shape is defined by an XML type schema that classifies a data element as a particular form of information, according to its allowable contents and units of data. For example, an xs:string type can be a sequence of alphabetic, numeric, and/or special characters, while an xs:date type can only be numeric characters presented in a YYYY-MM-DD format.

The data service interface consists of public functions that enable client-based consuming applications to retrieve data from the modeled data source. A data service's functions can be of several types:

In addition to public functions, a data service can include private functions and side effect functions. Private functions are only used within the data service. They generally contain common processing logic that can be used by more than one data service function. Side effect functions can be invoked from the client side. For example, a side effect function can contain code to update a non-RDBMS data source, such as xml, flat files, and Web services, and clients can invoke this function to perform updates. (For more information, see the Data Service Developer's Guide.)

Every function within a logical data service also includes source-to-target mappings that define what results will be returned by that function. There are four types of mappings:

In addition to the mappings, each function can also include parameters and variations on the basic XQuery FLWOR (for-let-where-order by-return) statements that further define the data retrieval results.

When you click on the name of a data service in the Application pane (Figure 2-10), your data service will open in Design View (Figure 3-1). In the Customer data service, what you see in Design View is a logical data service that:

If you open XQuery Editor View for a particular function, you would see the function's source-to-target mappings.

If you open Source View, you would see each function's parameters and FLWOR statements.

 


3.1 Creating a Simple Logical Data Service

A logical data service integrates and transforms data from multiple physical and logical data services.

Objectives

In this exercise, you will:

Instructions

  1. Create a new folder within the DataServices project and name it CustomerManagement.
  2. Create a new data service within the CustomerManagement folder by completing the following steps:
    1. Right-click the CustomerManagement folder.
    2. Choose New Arrow symbol Data Service. The New File dialog box opens.
    3. Confirm that Data Service Arrow symbol Data Service are selected.
    4. Enter CustomerProfile in the Name field.
    5. Click Create.
    6. Figure 3-2 New Data Service


      New Data Service

A new data service is generated, but without any associated data services or XML type.

 


3.2 Defining the Logical Data Service Shape

A data service transforms received data into the shape defined by its Return type. Pragmatically, the Return type is the "R" in a FLWOR (for-let-where-order by-return) query. A Return type, which describes the structure or shape of data returned by the data service's queries, serves two main purposes:

The Return type is generated from the data service's XML type. An XML type classifies a data element as a particular form of information, according to its allowable contents and units of data. For example, an xs:string type can be a sequence of alphabetic, numeric, and/or special characters, while an xs:date type can only be numeric characters presented in a YYYY-MM-DD format.

Objectives

In this exercise, you will:

Instructions

Note: Although you can use ALDSP to graphically build a schema file, in this exercise you will import a pre-defined schema file to save time. For more information on using WebLogic Workshop to create the XML types, see the Data Service Developer's Guide.
  1. Create a new folder in the CustomerManagement folder and name it schemas.
  2. Import a schema file into the schema folder by completing the following steps:
    1. Right-click the schema folder, located in the CustomerManagement folder.
    2. Choose Import.
    3. Navigate to:
    4. <beahome>\weblogic81\samples\liquiddata\EvalGuide
    5. Select the CustomerProfile.xsd file.
    6. Click Import.
    7. Figure 3-3 Import XML Schema Definition File


      Import XML Schema Definition File

  3. Right-click the CustomerProfile Data Service header on the Design View tab.
  4. Choose Associate XML Type.
  5. Select the CustomerProfile.xsd file, located in:
  6. CustomerManagement\schemas
  7. Click Select.
  8. Figure 3-4 Associating XML type with XSD


    Associating XML type with XSD

You should see that the CustomerProfile data service is now shaped by the CustomerProfile.xsd file.

You should also see that several of the elements are identified with a question (?) mark. This indicates that these elements are optional. Because the schema file identifies these elements as optional, ALDSP will not require the mapping of these elements to the Return type; however, if mapped to the Return type and there is no corresponding data in the underlying data source, then the result set will not include the empty elements.

Figure 3-5 Logical Data Service XML type

Logical Data Service XML type

 


3.3 Adding a Function to a Logical Data Service

A data service consumer—a client application or another data service—uses the data service's function calls to retrieve information. A logical data service includes the same types of functions that are found in a physical data service:

Objectives

In this exercise, you will:

Instructions

  1. Right-click the CustomerProfile Data Service header.
  2. Choose Add Function. A new function displays in the left pane of the data service model.
  3. Enter getAllCustomers as the function name.
  4. Figure 3-6 Design View of New Function


    Design View of New Function

 


3.4 Mapping Source and Target Elements

In the previous exercise, you associated a logical data service with an XML Schema Definition (.xsd file), which generated a Return type that includes all data elements defined within the schema. However, there are no conditions associated with the Return type; conditions specify which source data will be returned.

You can define conditions by mapping source and target (Return) elements.

Objectives

Instructions

  1. Click the getAllCustomers() function to open XQuery Editor View. You should see a Return type populated with the CustomerProfile schema definition. The Return type determines what data can be made available to consuming applications, as well as the shape (string, data, integer, and so on) that the data will take. The Return type was automatically populated when you associated the logical data service with the CustomerProfile.xsd.
  2. Figure 3-7 XQuery Editor View of Function Return Type


    XQuery Editor View of Function Return Type

  3. In the Data Services Palette, expand CustomerDB\CUSTOMER.ds. If the Data Services Palette is not open, choose View Arrow symbol Windows Arrow symbol Data Services Palette.
  4. Figure 3-8 Data Services Palette


    Data Services Palette

  5. Drag and drop CUSTOMER() into XQuery Editor View. This method call represents a root or global element within the CUSTOMER physical data service (see 3.2 Defining the Logical Data Service Shape). A for node for that element is automatically generated and assigned a variable, such as For: $CUSTOMER. Within the XQuery Editor View, this for node is a graphical representation of a for clause, which is an integral part of an XQuery FLWOR expression (for-let-where-order by-return).
  6. Figure 3-9 Source Node and Return Type


    Source Node and Return Type

  7. Create a simple map by dragging and dropping individual elements from the $CUSTOMER source node onto the corresponding elements in the Return type. The logical data service CustomerProfile should now be similar to what is shown in Figure 3-10.
Note: There are alternatives to mapping elements instead of using the slow simple mapping technique. Faster mapping techniques are described in exercises that follow.
Figure 3-10 Simple Mapping Between Source Node and Return Type

Simple Mapping Between Source Node and Return Type

 


3.5 Viewing XQuery Source Code

When you use XQuery Editor View to construct an XQuery, source code in XQuery syntax is automatically generated. You can view this generated source code in Source View and, if needed, modify the code. Any changes made in Source View will be reflected in XQuery Editor View.

Objectives

In this exercise, you will:

Instructions

  1. Select the Source View tab. A portion of the generated XQuery source code is displayed in Figure 3-11.
  2. Notice the for clause, which references the CUSTOMER() function.
  3. Notice the return clause, which reflects the simple mapping between the $CUSTOMER source node and the Return type. All optional elements are identified with a question mark in the field description, as shown (emphasis added):
  4. <TelephoneNumber?> {fn:data(CUSTOMER/TELEPHONE_NUMBER)}</Telephone number
  5. Also, notice that the <orders> elements are empty because order information has not yet been mapped to the Return type. This means that a consuming application, using this query, will only see customer information, not order information.
  6. Figure 3-11 Source View of XQuery Code for CUSTOMER() Node


    Source View of XQuery Code for CUSTOMER() Node

 


3.6 Testing a Logical Data Service Function

You can use Test View to validate the functionality of a logical data service.

Objectives

In this exercise, you will:

Instructions

  1. Build the DataServices project by right-clicking the DataServices folder and choosing Build DataServices from the pop-up menu.
  2. After the build completes successfully, select the Test View tab.
  3. Select getAllCustomers() from the function drop-down list.

Test the ability to specify the number of tuples returned by completing the following steps:

    1. Uncheck the Validate Result option. This feature is not mandatory to complete this exercise.
    2. Enter CustomerProfile/customer in the Parameter field (or select from the drop-down list). This parameter specifies the XPath expression for the element whose return results you want to limit to a set number of occurrences (such as customer).
    3. Enter 5 in the Number field. This will limit the results to the first five customers retrieved.
    4. Click Execute.
    5. Figure 3-12 Test Truncate Capabilities


      Test Truncate Capabilities

  1. View the results, which appear in the Result pane.
  2. Expand the top-level node. There should be only five Customer Profiles listed.
  3. Expand the first <customer> node. You should see a Customer Profile for Jack Black, as displayed in Figure 3-13.
  4. Figure 3-13 Customer Profile Test Results


    Customer Profile Test Results

 


Lesson Summary

In this lesson, you learned how to:


  Back to Top       Previous  Next