Data Services Developer's Guide

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

AquaLogic Data Services Platform Projects and Project Components

BEA Aqualogic Data Services Platform-enabled projects can be added to WebLogic Workshop in two ways:

The basic menus, common behavior, and look-and-feel associated with WebLogic Workshop apply to AquaLogic Data Services Platform. For detailed information on WebLogic Workshop see:


http://download.oracle.com/docs/cd/E13226_01/workshop/docs81/index.html

This chapter discusses:

The following major topics are covered:

 


AquaLogic Data Services Platform-Based BEA WebLogic Applications

As noted above, you can create a WebLogic Workshop application that automatically includes a AquaLogic Data Services Platform project. Or you can add AquaLogic Data Services Platform projects to any BEA WebLogic application.

Note: It often makes sense to consolidate AquaLogic Data Services Platform queries into a WebLogic Workshop application dedicated to AquaLogic Data Services Platform development. Other applications can then access these queries through the DSP Mediator API or a AquaLogic Data Services Platform control. For complete details related to how client applications can access AquaLogic Data Services Platform functions and procedures see the Client Application Developer's Guide.

Verifying Your AquaLogic Data Services Platform Version Number

To ascertain that AquaLogic Data Services Platform is available to your application or to determine the version that you are running, start your BEA WebLogic Server and access its Administration Console.

As an example, the WebLogic Server Console for the sample domain provided with BEA WebLogic can be accessed from:


http://localhost:7001/console

Navigate to the Console Arrow symbolVersions page (Console being the top menu item) and find the version number and creation date for AquaLogic Data Services Platform.

Creating a AquaLogic Data Services Platform-based Application

To create a AquaLogic Data Services Platform-based application select File Arrow symbolNew Arrow symbolApplication from WebLogic Workshop menu. When the dialog appears, select AquaLogic Data Services Platform Application (Figure 2-1).

Figure 2-1 Creating a New AquaLogic Data Services Platform Application

Creating a New AquaLogic Data Services Platform Application

You probably will want to change the name of the application from Untitled to something else. Your new application automatically contains an initial AquaLogic Data Services Platform-based project.

Figure 2-2 Application View of a New AquaLogic Data Services Platform Application

Application View of a New AquaLogic Data Services Platform Application

You can save your application at any time using the File Arrow symbol Save, Save As, or Save All commands. Save All saves any modified files in your application.

When you initially create a WebLogic Workshop application such as "myLD", a file called myLD.work is created in the root directory of your application. Invoking Workshop using this file also opens your application.

An application can contain any number of AquaLogic Data Services Platform or other types of WebLogic Workshop projects.

Adding a AquaLogic Data Services Platform Project to an Existing BEA WebLogic Application

You can also add one or several AquaLogic Data Services Platform projects to any WebLogic Workshop application.

To do this select File Arrow symbolNew Arrow symbolProject. When the project creation dialog appears, choose AquaLogic Data Services Platform Project.

Figure 2-3 Application Tab of a New AquaLogic Data Services Platform Application

Application Tab of a New AquaLogic Data Services Platform Application

Major Components of a AquaLogic Data Services Platform Project

When a new AquaLogic Data Services Platform application or project is created, a AquaLogic Data Services Platform project folder is also created. This becomes the root directory of your project (see Figure 2-3). Two Java archive (.jar) files are added to the application's Libraries folder including ld-server-app.jar and the mediator.jar. The latter file manages creation of Service Data Objects (SDOs), described in detail in the Client Application Developer's Guide.

Table 2-4 lists major AquaLogic Data Services Platform file types and their purposes.

Table 2-4 AquaLogic Data Services Platform Components, Including File Types
Component
Purpose
Data Services (.ds files)
Data services are contained in DS files and can be located anywhere in your application. Each data service file is an XQuery document.

Note: Since a DS file may contain numerous XQueries as well as other automatically-generated pragma directives, care should be taken when editing this file directly.

Model Diagrams (.md files)
Model diagrams provide a graphical representation of the relationships between various data services, which themselves represent the physical and logical data services available to your AquaLogic Data Services Platform queries.
Model diagrams have the extension .md and can be located anywhere in your AquaLogic Data Services Platform project.
Metadata information
Metadata information is contained in META-INF folders associated with JAR files. The non-editable contents of this Libraries folder contains information on data sources used by data services.
Schemas (.xsd files)
Data services typically are associated with XML types whose physical representation is an XML schema file. Schema files can be located anywhere in your application. Schemas automatically created by the Metadata Import wizard are placed in a schemas project inside your application.
Schema files can be manually created or modified using any text editor. There is also a built-in schema editor in AquaLogic Data Services Platform Design View and in model diagrams containing the data service.
The XML type associated with a data service is also the return type of each function in your data service.The return type precisely describes the shape of the document to be returned by your query.
The return type can be modified through the XQuery Editor or directly in source. However, this generally should only be done in conjunction with the Save and Associate Schema command (see Creating a Simple Data Service Function for details).
XQuery function libraries
(.xfl files)
XQuery function libraries typically contain utility XQuery functions that can be used by application data services and in building data transformations. A typical example would be a routine for converting currencies based on daily exchange rate. Such transformational functions could be used by any data service in your application.

Other files which may appear in AquaLogic Data Services Platform projects include Java files containing custom update logic and SDO configuration files such as sdo.xsdconfig, which allows XMLBean technology to create SDOs rather than XMLBeans.

Data Service Project Right-click Menu Options

AquaLogic Data Services Platform adds several options to the standard WebLogic Workshop project right-click menu (Figure 2-5).

Figure 2-5 Data Service Project Right-click Menu Options
Application Tab of a New AquaLogic Data Services Platform Application

The following table describes AquaLogic Data Services Platform additions to the Project right-click menu.

Table 2-6 Data Service Extensions to the Workshop Right-click Menu
Option
Usage
New
You can create the following data service-specific artifacts in WebLogic Workshop projects:
  • Model Diagram
  • Data Service
  • XQuery Function Library
Install
New data service libraries can be installed through this option.
Import Source Metadata
Opens a dialog for importing source metadata into your project.
Update Source Metadata
Opens a dialog for updating source metadata for your entire project.
Publish Data Services for SQL Use
Opens a dialog for selecting project artifacts for publication through the AquaLogic Data Services Platform JDBC driver.

Data Service Right-click Menu Options

AquaLogic Data Services Platform adds several options to the right-click menu associated with data services. (Figure 2-7).

Figure 2-7 Data Service Right-click Menu Options

Data Service Right-click Menu Options

The following table describes AquaLogic Data Services Platform additions to the standard right-click menu options.

Table 2-8 Data Service Extensions to the Workshop Right-click Menu
Option
Usage
Find Usages
For information on determining where various AquaLogic Data Services Platform artifacts are used see Usages of Data Services Artifacts.
Refactor
For information on data service refactoring operations see Refactoring AquaLogic Data Services Platform Artifacts.
Generate WSDL File for Service Bus
Create a WSDL file that enables users of AquaLogic Service Bus to invoke data service functions. See the Accessing Data Services Through AquaLogic Service Bus chapter in the Client Application Developer's Guide for details.
Update Source Metadata
Opens a dialog for updating source metadata for your data service.

Using the WebLogic Workshop IDE

WebLogic Workshop is fully described in on-line and printed documentation. A good place to start is:


http://download.oracle.com/docs/cd/E13226_01/workshop/docs81/index.html

Alternatively, WebLogic Workshop provides complete on-line help.

Figure 2-9 Some WebLogic Workshop Components in a AquaLogic Data Services Platform-Based Project

Some WebLogic Workshop Components in a AquaLogic Data Services Platform-Based Project

Table 2-10 briefly describes:

Table 2-11 describes the several WebLogic Workshop menu commands often used with AquaLogic Data Services Platform projects.

Table 2-11 Summary of WebLogic Workshop Menu Services Used by AquaLogic Data Services Platform
Service
Purpose
File menu
When working with AquaLogic Data Services Platform projects you will often use the following File menu options:
  • Save, Save As, Save All. The Save command saves the current file while the Save All command saves all open or modified files in your project. Use the Save All command to make sure that all changes you have made to your application will be persisted.
  • Import commands. Use the Import file browser to add files or libraries to your application. For example, if you have an externally developed schema you can use the Import command and associated file browser to bring a copy of it into your application.

Property Editor

You can use the Property Editor to view details related to any WebLogic Workshop artifact (see Figure 2-12). For example, in Design View (see Design View) if you click on the general data service, the Property Editor provides details on that service. If you click on a relationship representation in your data service, property details on that relationship appear. In many cases, property settings are editable or configurable.

Figure 2-12 Relationship Properties in a Data Service

Relationship Properties in a Data Service

Finding Text in Files

WebLogic Workshop provides a comprehensive file search facility with its Find in Files option, available from the Edit menu (Edit Arrow symbol Find in Files).

Figure 2-13 Workshop File Search Facility

Workshop File Search Facility

You can use Find in Files to search for references to any AquaLogic Data Services Platform artifacts such as particular data sources, use of functions, and so forth.

Survey of AquaLogic Data Services Platform Additions to WebLogic Workshop

An AquaLogic Data Services Platform project adds menu items and views to the basic WebLogic Workshop environment to support the following functionality:

Metadata Import

Data services are central to creating data models and physical and logical data views that can be used in AquaLogic Data Services Platform queries. The first step in creating a data service is to import metadata from physical data sources so that corresponding physical data services can be created.

Figure 2-14 Selecting Metadata Import for a AquaLogic Data Services Platform Project

Selecting Metadata Import for a AquaLogic Data Services Platform Project

For details related to importing and updating metadata into your AquaLogic Data Services Platform project see Obtaining Enterprise Metadata.

Data Models

Through the data model interface that you can:

For details on developing and maintaining data models see Modeling Data Services.

Data Services

Every data service provides a Design View, XQuery Editor View, Source View, Test View, and Query Plan View. Each data service is based around a single XQuery source file. And every data service has an associated XML type (XDS file).

Data services are composed of read and navigation functions and procedures. Read functions must return the XML type of the data service. Navigation functions, return the XML type of their native data service. Procedures, also known as side-effecting functions, need not return anything.

Figure 2-16 Sample Data Service

Sample Data Service

Design View

Design View is the central reference point of every data service. Through Design View that you can:

For details on developing and maintaining data services see Designing Data Services.

XQuery Editor View

Through the XQuery Editor View you can develop query functions by projecting data service function elements, as well as transformations, to the function's return type.

Figure 2-17 Sample XQuery Editor Query with Its Return Type

Sample XQuery Editor Query with Its Return Type

The graphical editor directly supports common constructs of the 1.0 XQuery standard. Several resources are available to help in the development and maintenance of business logic. These are all available from the WebLogic Workshop View or View Arrow symbolWindows menu).

For details on developing queries using XQuery Editor View see Working with the XQuery Editor.

XQuery Function Palette

An XQuery function palette (Figure 2-18) is available that supports standard XQuery and BEA-specific functions. This function palette is also available from the Workshop View Arrow symbolWindows menu.

Figure 2-18 XQuery Function Palette

XQuery Function Palette

Like all Workshop panes, the XQuery Function Palette can be placed anywhere in the WebLogic Workshop window. Functions from this palette can be dragged into XQuery Editor View, as well as Source View.

XQuery Constructs Palette

AquaLogic Data Services Platform projects also have access to the XQuery Constructs palette (Figure 2-19). This palette supports creation of different types of XQuery statements in the XQuery Editor View or Source View. Many of the construct prototypes such as FLWGR, FGWOR, FWGR, and so forth are variations on the most common XQuery construct, FLWR (for-let-where-return).

Figure 2-19 XQuery Constructs Palette

XQuery Constructs Palette

For example, FLWGR adds the AquaLogic Data Services Platform extension Group By. The prototype is shown below in Source View.

for $var in ()
let $var2:=()
where (true)
group by () as $var3 with partitions $var as $var4
return
()

For details on Group By and other BEA XQuery extensions see the XQuery Developer's Guide.

Data Services Palette

The Data Services Palette (Figure 2-20) is only available to AquaLogic Data Services Platform projects. It provides the AquaLogic Data Services Platform XQuery Editor with access to data service and XFL (XQuery function library) routines.

Figure 2-20 Data Services Palette

Data Services Palette

For details on using the XQuery Editor see Working with the XQuery Editor.

Editing XML Types and Return Types

A schema editor for modifying XML types in model diagrams and data services, as well as return types in the XQuery Editor, is available. See Working with Logical Data Service XML Types. Most editor options are available from the right-click menu.

Right-click menu commands for return types differ slightly from those in the XML type editor. The reason is that you can use the XQuery Editor to create if-then-else constructs, zones, and cloned elements as a means of more exactly specifying the form your query result document should take. (See Modifying a Return Type.)

Figure 2-21 Editing an XML Type Element

Editing an XML Type Element

Test View

After you have developed a query you can run it using Test View. For details see Testing Query Functions and Viewing Query Plans.

Source View

If you are working in Source View you can easily add pre-built XQuery functions and constructs to your source, as well as make other editing changes to your data service. For additional details see Working with XQuery Source.

Query Plan View

You can review the query plan developed by AquaLogic Data Services Platform for a particular function in order to verify the generated SQL or look for opportunities to improve performance. See Using Query Plan View.

Query Plan Viewer Utility

A query plan viewer utility is available from the Start menu of a AquaLogic Data Services Platform-enable WebLogic Workshop application:

start Arrow symbol All Programs Arrow symbol BEA WebLogic Platform 8.1 Arrow symbolBEA AquaLogic Data Services Platform 2.5Arrow symbolQuery Plan Viewer

Although this utility can be used while developing data services, it is more typically used by client application developers. Documentation for the utility can be found in the Using SQL to Access Data Services chapter of the Client Application Developer's Guide.

Usages of Data Services Artifacts

It is often convenient to determine which AquaLogic Data Services Platform artifacts are in use by which other artifacts. For example, before making changes in an XML type it is important to determine what other data services might be impacted. Of course you can do this through the Metadata Browser, described in the "Viewing Metadata" chapter of the AquaLogic Data Services Platform Administration Guide. However, it is often more convenient to do this in the context of the WebLogic Workshop navigation pane or the AquaLogic Data Services Platform Design View.

For example, in the RTLApp, right-clicking on a data service shows a number of options including Find Usages (Figure 2-22).

Figure 2-22 Finding Data Service Usages in RTLApp

Finding Data Service Usages in RTLApp

When you pick this option, usages of the artifact are displayed, as shown in Figure 2-23.

Figure 2-23 Usages of the Customer Data Service in the RTLAPP

Usages of the Customer Data Service in the RTLAPP

You can find the usages of the following types of AquaLogic Data Services Platform artifacts:

Updating Application or Project Data Service Libraries

When you save a AquaLogic Data Services Platform application its JAR libraries files are bound to that application. If you subsequently migrate to a newer version of AquaLogic Data Services Platform, you also need to upgrade your application to the latest library files. For details see the AquaLogic Data Services Platform Installation Guide.

 


Building and Deploying Applications, JARs, and SDO Mediator Clients

AquaLogic Data Services Platform attempts to rebuild your application as necessary. However, there are times when you will need to initiate a build directly.

Building, Deploying, and Updating Applications

Table 2-24 describes relevant Build menu options and their uses.

Table 2-24 Build Menu Options and Usage
Build Menu Options
Usage
Build Application
Builds or rebuilds your application. The result is that the contents of all the project-specific JAR files are updated according to the underlying project script. If your application has already been deployed, this option will automatically redeploy after a successful build.
You can also build individual projects.
Clean Application
Attempts to undeploy EJBs and other resources that were produced by the compilation process. In some cases this is not possible because of the state of the server. If Clean Application does not solve the problem, stop and restart WebLogic Server.
Clean Application addresses problems that occur due to cyclic compilation of Java files during iterative development, not on production servers.
You can also clean individual projects.
Build EAR
Creates a Java archive (JAR) file of your application. The EAR file has the same name as your application.

When to Rebuild Your AquaLogic Data Services Platform Project

You need to rebuild your project whenever you delete a file from a AquaLogic Data Services Platform-based project. Rebuilds can occur on a project or at the application level. Generally speaking, there is no need to rebuild your entire application unless you have made changes to multiple projects.

Rebuild your project (or application) in two steps:

  1. Clean your project (application). You can do this by right-clicking on your project (application) in the Application pane and selecting the available Clean option. Alternatively, use the appropriate Clean option available from the WebLogic Workshop Build menu.
  2. Build your project (or application) using the appropriate right-click or Build menu options.
Note: If you try to run a function in Test View and it fails unexpectedly, it is often curative to clean, then rebuild your application before attempting to run your query again.

Deploying Your Application

If your application is already deployed, it will be automatically redeployed whenever you rebuild it. Under some conditions you may want to undeploy your application first. Table 2-25 describes relevant deployment menu options available when you click on your application folder in the Application pane.

Table 2-25 Deployment Menu Options
Application Level Right-click Menu Deployment Options
Usage
Deployment Arrow symbol Redeploy
Redeploys your application.

Note: When you build your application it is automatically redeployed.

DeploymentArrow symbol Full Redeploy
First removes your application from the server, then redeploys it.
DeploymentArrow symbol Undeploy
Removes your application from the server.

For additional information on deploying WebLogic Workshop applications see:

Creating the SDO Mediator API

After you have created and tested your application's query functions, you need to make them available to client applications. The SDO mediator API is the primary means of providing access to your updateable functions.

Note: For details on SDO programming and accessing data in Java clients through the mediator API see Data Programming Model and Update Framework in the   Client Application Developer's Guide.

Generating the SDO Mediator JAR in Workshop

One way to create the SDO mediator client Java archive (.jar) file is through the right-click menu option Build SDO Mediator Client. This is only available from the root folder of your application.

When successful, your SDO mediator client will be created in the root directory of your application. The file will be named as:

<name_of_your_application>-ld-client.jar

The SDO mediator JAR file will also be automatically added to your application's Libraries folder.

Note: Insure that all of your projects are up-to-date and built before creating your SDO mediator JAR file. See also Building, Deploying, and Updating Applications on page 2-24.

Command-line Generation of the SDO Mediator API

You can also create the SDO mediator client JAR file through the command line using ant scripts.

When an EAR File is Available

If you already have an EAR file you can use the script:

ant -f $WL_HOME/liquiddata/bin/ld_clientapi.xml
-Darchive=</your_path/name_of_your_application>.ear>

in which case the name of your JAR file will be taken from the EAR file:

<name_of_your_application>-ld-client.jar

It will be created in the same directory as the EAR file.

Generating an SDO Mediator JAR File

You can generate an SDO mediator client JAR file (without needing an EAR file) by simply specifying an application directory:

ant -f $WL_HOME/liquiddata/bin/ld_clientapi.xml
-Dapproot=</your_path/name_of_your_application>/root>

This approach will use the directory name of the application root to compute the JAR file name; in the above case the name would be root-ld-client.jar. If that's not what is wanted, you could specify:

-Dsdojarname=<MyApp-ld-client.jar>

to override this. Either way the JAR file will be generated in the application root directory.

Generating JAR Files in Non-default Directories

For either case you could specify the additional ant parameter:

-Doutdir=</path/to/dir>

to generate the JAR file to a specific directory location.

Similarly you could use:

-Dtmpdir=</path/to/tmp>

to specify an alternate directory for temporary files, including the generated .java code.

The default tmp file location is specified by the Java system property:

java.io.tmpdir

In any case, when building from the command line, the SDO mediator.jar file will not be added to your application's Libraries folder (shown in Figure 2-2).

 


Refactoring AquaLogic Data Services Platform Artifacts

There are times when you will want to move, rename, or delete artifacts in your AquaLogic Data Services Platform projects. A typical example: your application is first developed with test data, so as to not expose confidential information to unauthorized individuals. Then, once developed, your application is ready for deployment with the actual, secured data sources. You can use refactoring to greatly simplify the renaming, deleting, or relocating of AquaLogic Data Services Platform components.

Figure 2-26 Refactoring Options Available for the RTLApp's Address Data Service

Refactoring Options Available for the RTLApp's Address Data Service

Without refactoring, changes you make to artifact names can easily result in invalid references. For example, renaming a data service file automatically invalids any relationship functions in other data services that refer to that file. The alternative to refactoring is to manually find all usages of a given artifact and make manual edits to data service source; this can be quite tedious and error-prone, particular as projects grow.

When you use the Refactor option you initially see the effect your refactoring change will have on impacted application artifacts (Figure 2-27). A checkbox allows you to exempt any artifact from the refactoring operation.

Note: Care should be taken when deselecting elements recommended for refactoring. Without additional manual changes to the underlying source you likely will no longer be able to build or deploy your application.
Figure 2-27 Artifacts Impacted by a Refactoring

Artifacts Impacted by a Refactoring

Artifacts Supporting Refactoring

Table 2-28 describes artifacts subject to refactoring and their options.

Table 2-28 Data Service Artifacts Supporting Refactoring and Available Refactoring Options
Artifact
Refactoring Options
Data service (DS files)
Move, refactor rename, safe delete
XML File Library (XFL files)
Move, refactor rename, safe delete
Schemas (XSD files) referred to within a data service
Move, refactor rename, safe delete
Functions (data service and XFL)
Rename, safe delete, add/remove parameters
Namespace declarations
Rename selected prefix or propagate the change through the project.
Schema import (data service and XFL)
Rename selected schema import prefix or propagate the renaming through the project.
Artifacts published as SQL Objects
Move, refactor rename, safe delete

Move, rename, and add/remove parameter operations are typically accomplished without adverse consequence. Delete operations, however, can adversely affect your project. For this reason the usages of the artifact you have identified for deletion are shown (see Figure 2-29). From this information you can easily determine the trade-offs between the automation of the refactoring operation and its consequences, which may require additional manual actions on your part.

Figure 2-29 Implications of a Safe Delete Operation

Implications of a Safe Delete Operation

Setting Refactor Options

Access to refactor options depends on the artifact:

Caution: Although you can deselect any artifact that you do not want to be included in a refactor operation, doing so will invalidate that artifact and any files dependent on that artifact. For this reason selective deselection of artifacts scheduled for refactoring should generally not be employed.
Note: In the case of namespace prefixes, names should be changed (or not) based on readability or consistency issues. Neither a local or a global change will adversely affect your code.

Impacts of Various Refactoring Operations

It is useful to understand the various potential effects of a refactoring operation. In Table 2-34 each type of refactoring operation is described in terms of its potential impact on related artifacts.

Table 2-34 Effect of Refactoring on Various Types of AquaLogic Data Services Platform Artifacts
Artifact(s)
Renaming Operations
Move Operations
Safe Delete Operations
Data service
Renames data service
Updates:
  • Name in source.
  • Namespace URI for data service functions
  • Dependent annotations
  • Dependent function references
  • Dependent model diagrams
  • Dependent data service controls
  • Function dependent on read function and relationship functions
Moves data service to a new location in the project.
Move operations update the same artifacts listed under Renaming Operations.
Deletes after warning regarding any dependencies.
  • Data service read functions
  • Relationship functions
  • Private functions
  • XFL functions
Updates:
  • Name in source.
  • External or internal references to this function in other function bodies, if any.
  • References to this function in inverse and equivalent transform annotations, if any.
N/A
  • Delete name in source.
  • Warns of any dependencies, including:
    • references to this function in other function bodies
    • references to this function in inverse and equivalent transform annotations.
  • Namespace declarations
  • Schema import declarations
Updates:
  • Prefix declaration and usages in source (local).
  • Prefix usages for the specified namespace URI for the entire project (global option).
N/A
N/A
External schema declarations
Updates:
  • External schema URI (local)
  • External schema URI for the entire project (global option).
N/A
N/A

 


Creating and Working with XQuery Function Libraries

XQuery function libraries (XFLs) contain functions that can be used by any data service or any other XFL in your application. Such libraries provide for:

Functions in XFL files cannot be directly invoked by data service clients. Instead, they are used by other data services. XFL functions provide user-defined routines that can be shared across a set of executable artifacts.

An XQuery function library (.xfl file) is ideal for creating sharable transformation, security, and other types of functions.

Table 2-35 File Types Supported by XQuery Function Libraries
XFL file type
Purpose
Relational
Associates an XQuery function with relational data source.
Web service
Associates an XQuery function with a WSDL.
Java function
Associates an XQuery function with a class file.
User-defined
User-defined XQuery functions
External database functions
Registers external built-in or custom database functions so that they can be invoked by data service or other XFL functions.

The first three types of files contain functions bound to an instance of a certain type of physical source (that is relational, WSDL, or class file). User-defined XQuery functions provide you with the ability to share common functions across all the data services in your project. External database functions provide application programs with the ability to invoke user-defined or built-in vendor-specific SQL functions from data services.

XQuery function libraries can be created in two ways:

XQuery function libraries are available from the Data Services Palette.

List of Prefix Bindings Potentially Affected by a Global Prefix Change

XQuery Function Library Views

An XQuery function library (XFL) can contain any number of functions. In an AquaLogic Data Services Platform-enabled project, you will find that XFL Design View is similar to the data service Design View (shown in Sample Data Service). The primary differences are:

The tabular modes available in data services — Source View, XQuery Editor View, Test View, and Query Plan View — are available to XQuery function libraries as well. Similarly, XFL functions have associated properties that can be viewed through the Property Editor.

Note: XFL files also play an important role in creating inverse functions. See Using Inverse Functions to Improve Query Performance in Best Practices and Advanced Topics.

Creating an XFL Function

It is not difficult to make a function in a data service available throughout your project as an XML function library. For example, the following function is available in the RTLApp's DataServices/RTLServices/Credit Card data service (namespace declarations from a separate section of the source file are also included):

declare namespace ns1="ld:DataServices/BillingDB/CREDIT_CARD";

import schema namespace ns0="urn:retailerType" at "ld:DataServices/RTLServices/schemas/CreditCard.xsd";

declare namespace tns="ld:DataServices/RTLServices/CreditCard";
(: ... :)
declare function tns:getCreditCard() as element(ns0:CREDIT_CARD)* {
for $CREDIT_CARD in ns1:CREDIT_CARD()
return <ns0:CREDIT_CARD>
<CreditCardID>{fn:data($CREDIT_CARD/CC_ID)}</CreditCardID>
<CustomerID>{fn:data($CREDIT_CARD/CUSTOMER_ID)}</CustomerID>
<CustomerName>{fn:data($CREDIT_CARD/CC_CUSTOMER_NAME)}</CustomerName>
<CreditCardType>{fn:data($CREDIT_CARD/CC_TYPE)}</CreditCardType>
<CreditCardBrand>{fn:data($CREDIT_CARD/CC_BRAND)}</CreditCardBrand>
<CreditCardNumber>{fn:data($CREDIT_CARD/CC_NUMBER)}</CreditCardNumber>
<LastDigits>{fn:data($CREDIT_CARD/LAST_DIGITS)}</LastDigits>
<ExpirationDate>{fn:data($CREDIT_CARD/EXP_DATE)}</ExpirationDate>
{fn-bea:rename($CREDIT_CARD/STATUS,<Status/>)}
{fn-bea:rename($CREDIT_CARD/ALIAS,<Alias/>)}
<AddressID>{fn:data($CREDIT_CARD/ADDR_ID)}</AddressID>
</ns0:CREDIT_CARD>
};

Here are the steps you would take to create this function in an XQuery library:

  1. The first step is to create and name a library, if you do not already have one:
  2. File Arrow symbol New Arrow symbol XQuery Function Library

    Figure 2-36 Creating an XQuery Function Library


    Creating an XQuery Function Library

  3. Name your library, such as myXQueryLibrary.
  4. Copy your function into the newly created file.
  5. Change the function declaration to match the namespace of your library file.

Source for the XQuery library file containing the CREDIT_CARD function appears below. To simplify, the object is returned as $x rather than as a set of individually-mapped elements.

xquery version "1.0" encoding "WINDOWS-1252";
(::pragma xfl <x:xfl xmlns:x="urn:annotations.ld.bea.com"></x:xfl> ::)

declare namespace tns="lib:DataServices/myXQueryLibrary";

declare namespace ns1="ld:DataServices/BillingDB/CREDIT_CARD";
import schema namespace ns0="urn:retailerType" at "ld:DataServices/RTLServices/schemas/CreditCard.xsd";

declare function tns:getCreditCard() as element(ns1:CREDIT_CARD)* {
for $x in ns1:CREDIT_CARD()
return $x
};

XFL Database Function Views

A database function library is an XFL that contains only database function locations and signatures. Such libraries can contain only database functions.

Database functions are designed to extend SQL support beyond that provided through standard JDBC functionality. There are several benefits:

Support for Built-in and User-Defined SQL Functions

A database function library provides access to two additional types of SQL functions:

Once a function has been registered in a library, it can be become available through XQuery or as SQL:

Creating a Database XFL and Registering Database Functions

The following example shows how such a library is created:

  1. Create a new XFL, as described previously in this section.
  2. Start your server, if it is not already running.
  3. Right-click on the titlebar of your new library, select Designate as Database Function Library... (Figure 2-37).
  4. Figure 2-37 Designating an XFL as a Database Function Library


    Designating an XFL as a Database Function Library

  5. Select one or more data sources from the drop-down list of data sources available to your server (Figure 2-38). You should identify data sources containing the built-in or user-defined database functions you want to access through your data services.
  6. Note: Once you have created your database function library, you can add additional database functions through your XFL Properties Editor (see Figure 2-40).
    Figure 2-38 Selecting Data Sources Containing Database Functions Planned for Registration


    Selecting Data Sources Containing Database Functions Planned for Registration

  7. After you have selected your data sources you are ready to add support for specific database functions to your library. Do this by right-clicking on your database function library in Design View and selecting the only available option: Add Database Function.
  8. Enter the information necessary to identify your database function (see Figure 2-39). All fields are optional but the SQL function name and XQuery function name. A placeholder XQuery function name is also generated; it should be changed to any valid, non-conflicting XQuery function name.
  9. Figure 2-39 Adding Database Function Information


    Adding Database Function Information

  10. Click OK.
  11. Complete the function definition including identifying parameters in Source View.

XFL database function libraries are available from the Data Services Palette.

Note: A mapping of XML to JDBC types can be found in the Using SQL to Access Data Services chapter of the Client Application Developer's Guide.
Modifying XFL Database Function Information

You can adjust catalog, schema, package, and XQuery function name settings through the Property Editor (Figure 2-40) at any time.

Figure 2-40 XFL Database Function in Design View and Its Associated Property Editor

XFL Database Function in Design View and Its Associated Property Editor

Once your XFL database functions have been published to SQL (as described in Publishing Data Service Functions for SQL Use) and your AquaLogic Data Services Platform application deployed, your functions will be available to client application developers through standard data service calls, including JDBC, the mediator API and, as a Data Service control.

Note: If you build a SQL query using a reporting tool, the unqualified JDBC function name is used in the generated SQL. When an application developer invokes an XFL database function, the default catalog and schema name must be defined when the JDBC connection is created. For this reason it is also a requirement that any JDBC connection utilize functions available from a single catalog:schema pair location.
Note: The following is an example URL defining a default catalog and schema for a JDBC connection:
jdbc:dsp@localhost:7001/myApplication/myCatalog/mySchema
Adding Data Sources to an XFL Database Function Library

It is easy to associate or disassociate DFL data sources using the XFL Properties Editor. Figure 2-41 shows two data sources associated with a sample XFL database function library: cgDataSource and cgDataSource-nonXA.

Figure 2-41 Data Sources for Registered XFL Database Functions

Data Sources for Registered XFL Database Functions

You can change a database name designation by clicking on the database name and then selecting another database from the drop-down list. You can add a new database by clicking the "+" next to the Registered Function(s) Data Sources property. Similarly, you can remove a registered database function data source by clicking the "-" next to that data source name.

Understanding XFL Database Function Calls Through Source View

When you declare an XFL as a database function library, an underlying pragma statement is generated in Source View identifying your XFL as dedicated to database function declarations.

In Listing 2-1 names of databases available to function declarations are contained in a customNativeFunctions type. (Custom native functions are the same as XFL database functions.)

Listing 2-1 Pragma Identifying an XFL as a Database Function Library
(::pragma xfl <x:xfl xmlns:x="urn:annotations.ld.bea.com">
 <creationDate>
  2006-07-11T11:13:18
 </creationDate>
<customNativeFunctions>
<relational>
<dataSource>cgDataSource-nonXA</dataSource>
<dataSource>bpmArchDataSource</dataSource>
</relational>
</customNativeFunctions>
</x:xfl> ::)
XFL Database Function Declarations

The sample in Listing 2-2 shows code automatically created when you add an XFL database function declaration to your library.

Listing 2-2 XFL Database Function Declaration
(::pragma function 
<f:function xmlns:f="urn:annotations.ld.bea.com"  nativeLevel1Container="cat1"
 nativeLevel2Container="schema1"
 nativeLevel3Container="sql_functions1"
 nativeName="POWER">
</f:function>::)
declare function tns:Power() as xdt:anyAtomicType? external;

Notice that function is identified as external to the application.

Note: The sequence of dataSource elements carry the names of the relational sources to which the specified functions apply. The native qualified name of each function is captured in the values of:
"nativeLevelNContainer" (N = 1,2,3) 

and:

"nativeName" 

For example, the qualified name of a custom SQL function MEDIAN, defined under package STATISTICS, will be represented by the following annotation:

(::pragma function 
<f:function xmlns:f="urn:annotations.ld.bea.com" nativeName="MEDIAN" nativeLevel3Container="STATISTICS"/> ::)

The qualified name (the qname) of the XQuery function representing the native function is user-defined.

The native signature of each function is reflected in the signature specified by the XQuery function declaration. In the case of user-defined SQL functions, the SQL type of an input parameter or output of the SQL function (e.g., TIME) is reflected in the corresponding XQuery type in the function signature (e.g., xs:time).

Note: It is important that type mappings between XML and SQL be correct. See "XML and SQL Type Mappings" in the Using SQL to Access Data Services chapter of the Client Application Developer's Guide.
Support for Polymorphism

Native functions that expose a certain type of polymorphism, in that their output type is determined by the actual type of one of their parameters, may use the optional annotation element isPolymorphic. The element isPolymorphic accepts the required parameter element as its content. The element "parameter" accepts the index attribute, as described in Table 2-42.

Table 2-42 Use of the isPolymorphic Index Parameter
isPolymorphic Parameter
Usage
index
An optional attribute denoting the index of the parameter based on which function parameter is declared polymorphic.
The index of the first parameter is assumed to be 1. It may be omitted if the function being annotated has a single parameter.

The following example illustrates the use of the isPolymorphic element.

declare namespace stat = "urn:sample";

(::pragma function <f:function xmlns:f="urn:annotations.ld.bea.com" nativeName="MEDIAN" nativeLevel3Container="STATISTICS">
	<isPolymorphic><parameter/></isPolymorphic>
</function>::)
declare function stat:median($x as xdt:anyAtomicType*) as xdt:anyAtomicType external;

  Back to Top       Previous  Next