Building Queries and Data Views
You can use complex parameter types (CPTs) to make one or several streaming data sources available for Liquid Data queries. Such content is variously called runtime source, data stream, real-time data, or in-flight XML. As long as an XML schema can model the runtime source, you can use it with Liquid Data queries. Liquid Data complex parameter types enable the on-the-fly aspect of this query.
A complex parameter type is a user-defined variable that allows modelling of runtime data as a data source for a Liquid Data query. Complex parameter types (CPTs) are defined through an XML schema. In other words, a CPT is a user-defined variable whose signature is expressed in via an XML schema.
When you are satisfied with your ability to run your query using a runtime data source, the query can be invoked via a EJB API or via a JSP. For details on invoking queries programmatically and the Liquid Data API see:
Complex parameter types allow you to access information that may not be available from traditional static data sources. For example, an enterprise frequently needs to bring together highly diverse pieces of information to complete a business activity or analysis.
A corporation typically receives large electronically-transmitted orders for customized computer chips from companies and governments all over the world. Orders are transmitted using an agreed-upon XML schema provided by eWorld. When an order is received, a variety of commissions and bonuses become payable.
When an order arrives, Liquid Data uses information from all these data sources, including the runtime order information. As the order is received as an in-flight XML document, a query is run and an XML report generated that calculates costs and commissions, taking into account both the order and cumulative discount and commission schedules for the buyers, middlemen, and sales people involved in the transaction.
This section describes elements of a sample CPT schema and its XML instance. It uses the DB-CPTCO sample installed with Liquid Data when describing a CPT schema and XML data source. The sample is installed in the following directory:
The CPT schema shown in Listing 9-1 (
coCptSample2.xsd) is from the DB-CPTCO sample. It is located in the Liquid Data repository
This simple example defines a complex variable type containing four data elements:
price. The complex type you design will vary depending on the signature of your runtime source.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:element name="CUSTOMER_ORDER" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="CUSTOMER_ID" type="xsd:string"/>
<xsd:element name="PRODUCT_NAME" type="xsd:string"/>
<xsd:element name="QUANTITY" type="xsd:decimal"/>
<xsd:element name="PRICE" type="xsd:decimal"/>
Components of the sample schema shown in Listing 9-1 include:
Note: Only one instance of a CPT (that is, a unique combination of namespace and schema root element) can be available in the Data View Builder. If you try and duplicate a CPT under another alias name, a red mark will appear over the duplicate CPT name to indicate that it is unavailable.
When you are first developing your query, you will likely want to create a sample XML data file to test your query with an EJB client such as the data in the Data View Builder. In the following listing from the DB-CPTCO sample XML data stream, note that the namespace must match that in the DB-CPTCO sample schema.
<?xml version="1.0" encoding="UTF-8"?>
Components in the sample XML data stream shown in Listing 9-2 include:
The namespace of your Complex Parameter Type must be unique. It is a good design pattern to have a namespace defined in your schema file and specified when you define your Complex Parameter Type to Liquid Data. If a namespace is specified in the Complex Parameter Type definition, all XQueries that access the Complex Parameter Type must specify the namespace. Regardless of whether you use namespaces, uniqueness is required.
namespace cocpt = "urn:schemas-bea-com:ld-cocpt"
for $CO_CPTSAMPLE.CUSTOMER_ORDER_2 in
($#QParamForCO-CPTSAMPLE of type element cocpt:CustOrder)
Create a schema that models the runtime source. See the Sample CPT Schema for a small schema example.
Note: In some design situations you may first create a CPT schema and then develop a model for the runtime source. The important point is that there is a tightly coupled relationship between the schema and the runtime data that it models. Both must work together and, once working, the structure of the documents cannot be changed independently.
Through the Liquid Data node of the WebLogic Administration Console, define a complex parameter type. for a detailed procedure, see Configuring Access to Complex Parameter Types in the Administration Guide.
Create your query either using the Data View Builder or by hand. See Key Concepts of Query Building for information on designing queries in Liquid Data.
Figure 9-2 shows the DB-CPT project. Notice that there are two complex parameter types available for use.
CPTSAMPLE is th
e complex parameter type used in the query.
To test your query the name of an XML data file that is modeled on the CPT schema must be entered in the Data View Builder (see Figure 9-3). To locate the Liquid Data sample XML file click on the Value field to open the Liquid Data file browser to the following directory:
Figure 9-4 shows the DB-CPT (
CPTSAMPLE.QPR) project when the query is run.
For a step by step example of building a query with a CPT, see Example 6: Complex Parameter Type (CPT) in Liquid Data by Example.
There are also two CPT query samples installed with the Liquid Data samples. These samples show how to create a complex parameter type, configure it as a complex parameter type, and then run the query.
Instructions for running the samples can be found under Complex Parameter Type (CPT) Sample Queries in Liquid Data by Example. The examples can be found under:
Also see the Liquid Data Samples page for information on other available query samples.