bea.com | products | dev2dev | support | askBEA |
![]() |
![]() |
|
![]() |
e-docs > Liquid Data for WebLogic > Building Queries and Data Views > Example 5: Minus |
Building Queries and Data Views
|
A minus relationship (A minus B) returns all instances of some named value that are in A but not in B. There is no explicit minus operation in the XQuery language or Data View Builder; however, a simple compare and count technique can be used. For example: for each instance of the named value in A, count all matching instances in B; if the count is zero, that means there are no matches, and the query therefore returns the instance from A.
Find all customers that are Broadband customers, but not Wireless customers. Assume that Customer IDs match across databases.
The shaded area in Figure 9-4 represents the Broadband customers who are not Wireless customers.
Figure 9-4 Broadband and Wireless Customers
If a customer has only a Broadband account, then a join across the Broadband and Wireless databases on that Customer ID produces an empty result. We can take advantage of that fact by counting the number of instances produced by the join. If the number is zero, then the Customer ID represents a Broadband-only customer.
To create the solution, follow these steps:
Minus Demo... If you are looking at this documentation online, you can click the "Demo" button to see a viewlet demo showing how to build the conditions and create the mappings described in this example. This demo previews the steps described in detail in the following sections. The demo assumes you already have the target schema in the server Repository.
Ex 5: Step 1. Verify the Target Schema is Saved in Repository
For this example, we will use a target schema called minus.xsd. This schema is available in the Samples server repository. The path to the schemas folder in the Liquid Data server repository is:
ld_repository/schemas/
See Example directories for information on how example directory names are used.
Just in case you want to verify that you have the right schema file, the following code listing shows the XML for this schema.
Listing 9-14 XML Source for minus.xsd Target Schema File
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<xsd:element name="results">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CUSTOMER" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FIRST_NAME" type="xsd:string"/>
<xsd:element name="LAST_NAME" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Ex 5: Step 2. Open Source and Target Schemas
Ex 5: Step 3. Find Broadband and Wireless Customers with the Same Customer ID
Ex 5: Step 4. Find the Count of the Wireless Customers
Ex 5: Step 5. Set a Condition that Specifies the Output of "count" is Zero
Ex 5: Step 6. View the XQuery and Run the Query to Test it
Listing 9-15 XQuery for Example 5: Minus
{-- Generated by Data View Builder 1.1 --}
<results>
{
for $PB_BB.CUSTOMER_1 in document("PB-BB")/db/CUSTOMER
let $srcval_2 :=
for $PB_WL.CUSTOMER_3 in document("PB-WL")/db/CUSTOMER
where ($PB_BB.CUSTOMER_1/CUSTOMER_ID eq $PB_WL.CUSTOMER_3/CUSTOMER_ID)
return
xf:data($PB_WL.CUSTOMER_3/CUSTOMER_ID)
let $xf:count_4 := xf:count($srcval_2)
where ($xf:count_4 eq 0)
return
<CUSTOMER>
<FIRST_NAME>{ xf:data($PB_BB.CUSTOMER_1/FIRST_NAME) }</FIRST_NAME>
<LAST_NAME>{ xf:data($PB_BB.CUSTOMER_1/LAST_NAME) }</LAST_NAME>
</CUSTOMER>
}
</results>
Ex 5: Step 7. Verify the Result
When you run this query on the sample data sources as described here, the result will be one record because the sample Broadband data source has one customer record that is different from the Wireless customer records.
Listing 9-16 Result for Example 5: Minus
<results>
<CUSTOMER>
<FIRST_NAME>JOHN</FIRST_NAME>
<LAST_NAME>PARKER</LAST_NAME>
</CUSTOMER>
</results>
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |