bea.com | products | dev2dev | support | askBEA |
![]() |
![]() |
|
![]() |
e-docs > Liquid Data for WebLogic > Building Queries and Data Views > Examples of Simple Queries |
Building Queries and Data Views
|
This section includes walk-through examples of how to build some simple queries using the Data View Builder tools and features just described:
To work through these examples, begin on the Data View Builder "Design" tab. If you have worked through the previous example using amtByState target schema, we suggest you close that project and open/save a new project for each of the examples described below.
Example: Return Customers by Name
In this example, you want to return the last and first names of all Wireless customers with a last name that begins with "K."
The approach we will use is similar to the first example in this chapter; however, you are adding a condition that the last name begins with "K." Build the condition with the starts-with function as follows.
Figure 3-6 shows the Design view of the query with conditions and source-to-target mappings completed.
Figure 3-6 Design View of Query Example: Return Customers By Name
View the XQuery and Run the Query to Test it
Now that you have built the query, you can switch to the Test tab to view the generated XQuery and run the query to see the kind of result it returns.
The generated XQuery is displayed in the Query panel on the left side of the Test tab as shown in Figure 3-7. The full XQuery is also provided in Listing 3-2.
Figure 3-7 XQuery for Example: Return Customers By Name
Listing 3-2 XQuery for Example: Return Customers By Name
{-- Generated by Data View Builder 1.0 --}
<customers>
{
for $PB_WL.CUSTOMER_1 in document("PB-WL")/db/CUSTOMER
where xf:starts-with($PB_WL.CUSTOMER_1/LAST_NAME,"K")
return
<CUSTOMER>
<LAST_NAME>{ xf:data($PB_WL.CUSTOMER_1/LAST_NAME) }</LAST_NAME>
</CUSTOMER>
}
</customers>
The query result is shown in the Result panel on the right side of the Test tab as shown in Figure 3-8. The full XML query result is provided in Listing 3-3.
Figure 3-8 Query Result for Example: Return Customers By Name
Listing 3-3 XML Query Result for Example: Return Customers By Name
<customers>
<CUSTOMER>
<LAST_NAME>KAY_1</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_2</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_3</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_4</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_5</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_6</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_7</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_8</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_9</LAST_NAME>
</CUSTOMER>
<CUSTOMER>
<LAST_NAME>KAY_10</LAST_NAME>
</CUSTOMER>
</customers>
(For complete details on how to test and run a query, see Testing Queries.)
Example: Query Customers by ID and Sort by State
In this example, there are two pieces of information that we want to display in the result. We want to find Customer IDs for customers who exist in both databases and we want to know the state each found customer resides in.
This example shows how to do the following:
Open the Data Sources and Add a Target Schema
Note: If amtByState.xsd is not already saved in the Samples server Repository, you can create it yourself and save it to the Repository. For a copy of the schema file and instructions on how to save it to the Repository, see Adding a Target Schema and the schema shown in Listing 3-1.
Map Nodes from Source to Target Schema to Project Output
To project Customer first and last names and state to Target, do the following:
To create a join between Wireless (PB-WL) and Broadband (PB-BB) on customer IDs, do the following:
The following shows the mappings in the Data View Builder.
Figure 3-9 Example: Query Customers by ID and Sort Output by State
Specify the Order of the Result Using the Sort By Features
To order the output alphabetically by State do the following:
View the XQuery and Run the Query to Test it
Now that you have built the query, you can switch to the Test tab to view the generated XQuery and run the query to see the kind of result it returns.
Listing 3-4 XQuery for Example: Query Customers by ID and Sort by State
{-- Generated by Data View Builder 1.0 --}
<customers>
{
for $PB_WL.CUSTOMER_1 in document("PB-WL")/db/CUSTOMER
let $CUSTOMER_2 :=
for $PB_BB.CUSTOMER_3 in document("PB-BB")/db/CUSTOMER
where ($PB_BB.CUSTOMER_3/CUSTOMER_ID eq $PB_WL.CUSTOMER_1/CUSTOMER_ID)
return
xf:true()
where xf:not(xf:empty($CUSTOMER_2))
return
<CUSTOMER>
<FIRST_NAME>{ xf:data($PB_WL.CUSTOMER_1/FIRST_NAME) }</FIRST_NAME>
<LAST_NAME>{ xf:data($PB_WL.CUSTOMER_1/LAST_NAME) }</LAST_NAME>
<STATE>{ xf:data($PB_WL.CUSTOMER_1/STATE) }</STATE>
</CUSTOMER>
sortby(STATE ascending)
}
</customers>
Listing 3-5 XML Result for Example: Query Customers by ID and Sort by State
<customers>
<CUSTOMER>
<FIRST_NAME>JOHN_3</FIRST_NAME>
<LAST_NAME>KAY_3</LAST_NAME>
<STATE>AZ</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_8</FIRST_NAME>
<LAST_NAME>KAY_8</LAST_NAME>
<STATE>AZ</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_10</FIRST_NAME>
<LAST_NAME>KAY_10</LAST_NAME>
<STATE>CA</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_5</FIRST_NAME>
<LAST_NAME>KAY_5</LAST_NAME>
<STATE>CA</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_4</FIRST_NAME>
<LAST_NAME>KAY_4</LAST_NAME>
<STATE>NV</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_9</FIRST_NAME>
<LAST_NAME>KAY_9</LAST_NAME>
<STATE>NV</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_1</FIRST_NAME>
<LAST_NAME>KAY_1</LAST_NAME>
<STATE>TX</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_6</FIRST_NAME>
<LAST_NAME>KAY_6</LAST_NAME>
<STATE>TX</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_2</FIRST_NAME>
<LAST_NAME>KAY_2</LAST_NAME>
<STATE>WA</STATE>
</CUSTOMER>
<CUSTOMER>
<FIRST_NAME>JOHN_7</FIRST_NAME>
<LAST_NAME>KAY_7</LAST_NAME>
<STATE>WA</STATE>
</CUSTOMER>
</customers>
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |