bea.com | products | dev2dev | support | askBEA |
![]() |
![]() |
|
![]() |
e-docs > Liquid Data for WebLogic > Building Queries and Data Views > Example 3: Date and Time Duration |
Building Queries and Data Views
|
Example 3: Date and Time Duration
Data View Builder supports a set of functions that operate on date and time. For more information on date and time functions see Date and Time Functions in the "Functions Reference."
Determine if a Broadband customer has any open orders in the Broadband database before a specified date.
For each Broadband order that matches the given Customer ID, you need to set these conditions:
To create the solution, follow these steps:
Date and Time Duration 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 3: Step 1. Verify the Target Schema is Saved in Repository
For this example, we will use a target schema called customerLineItems.xsd. This schema is available in the Samples server repository.
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-8 XML Source for customerLineItems.xsd Target Schema File
<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
<xsd:element name = "customers">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref = "customer" minOccurs = "0" maxOccurs = "unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name = "customer">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref = "first_name"/>
<xsd:element ref = "last_name"/>
<xsd:element ref = "orders" minOccurs = "0" maxOccurs = "unbounded"/>
</xsd:sequence>
<xsd:attribute name = "id" use = "required" type = "xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name = "first_name" type = "xsd:string"/>
<xsd:element name = "last_name" type = "xsd:string"/>
<xsd:element name = "orders">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref = "order" minOccurs = "0" maxOccurs = "unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name = "order">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref = "line_item" minOccurs = "0" maxOccurs = "unbounded"/>
</xsd:sequence>
<xsd:attribute name = "id" use = "required" type = "xsd:string"/>
<xsd:attribute name = "date" use = "required" type = "xsd:string"/>
<xsd:attribute name = "amount" use = "required" type = "xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name = "line_item">
<xsd:complexType>
<xsd:attribute name = "id" use = "required" type = "xsd:string"/>
<xsd:attribute name = "product" use = "required" type = "xsd:string"/>
<xsd:attribute name = "status" use = "required" type = "xsd:string"/>
<xsd:attribute name = "expected_ship_date" use = "required" type = "xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Ex 3: Step 2. Open Source and Target Schemas
Ex 3: Step 3. Map Source to Target Nodes to Project the Output
Project the output values as follows.
At this point, the following mappings should be displayed on the Mappings tab. (Getting the mappings in the same order as shown is not as important as verifying that the relationships between source and target nodes are the same. The @ symbols indicate attributes.)
Join customer with corresponding line-item data. This requires two joins, one to find the customer's Order IDs, and another that uses the Order IDs and finds the corresponding line-item information:
Ex 3: Step 5. Create Two Query Parameters for Customer ID and Date to be Provided at Query Runtime
Create two Query Parameter variables: customer_id and date1, that you can use to insert as variable values when the query runs. Create both variables as type xs:string. Do this as follows:
Ex 3: Step 6. Set a Condition Using the Customer ID
Ex 3: Step 7. Set a Condition to Determine if Order Ship Date is Earlier or Equal to a Date Submitted at Query Runtime
([PB-BB]/db/CUSTOMER_ORDER_LINE_ITEM/EXPECTED_SHIP_DATE le xfext:date-from-string-with-format(pattern,srcval))
yyyy-MM-dd
([PB-BB]/db/CUSTOMER_ORDER_LINE_ITEM/EXPECTED_SHIP_DATE le xfext:date-from-string-with-format("yyyy-MM-dd",date1))
Ex 3: Step 8. Set a Condition to Include Only "Open" Orders in the Result
Set the second condition to an Open Order status.
Ex 3: Step 9. View the XQuery and Run the Query to Test it
Listing 9-9 XQuery for Example 3: Date and Time Duration
{-- Generated by Data View Builder 1.0 --}
<customers>
{
for $PB-BB.CUSTOMER_1 in document("PB-BB")/db/CUSTOMER
where ($#customer_id of type xs:string eq $PB-BB.CUSTOMER_1/CUSTOMER_ID)
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>
<orders>
<order>
{
for $PB-BB.CUSTOMER_ORDER_2 in document("PB-BB")/db/CUSTOMER_ORDER
for $PB-BB.CUSTOMER_ORDER_LINE_ITEM_3 in document("PB-BB")/db/CUSTOMER_ORDER_LINE_ITEM
where ($PB-BB.CUSTOMER_ORDER_2/ORDER_ID eq $PB-BB.CUSTOMER_ORDER_LINE_ITEM_3/ORDER_ID)
and ($PB-BB.CUSTOMER_ORDER_LINE_ITEM_3/EXPECTED_SHIP_DATE le xfext:date-from-string-with-format("yyyy-MM-dd",$#date1 of type xs:string))
and ($PB-BB.CUSTOMER_ORDER_LINE_ITEM_3/STATUS eq "OPEN")
and ($PB-BB.CUSTOMER_1/CUSTOMER_ID eq $PB-BB.CUSTOMER_ORDER_2/CUSTOMER_ID)
return
<line_item id={$PB-BB.CUSTOMER_ORDER_LINE_ITEM_3/LINE_ID} product={$PB-BB.CUSTOMER_ORDER_LINE_ITEM_3/PRODUCT_NAME} status={$PB-BB.CUSTOMER_ORDER_LINE_ITEM_3/STATUS} expected_ship_date={$PB-BB.CUSTOMER_ORDER_LINE_ITEM_3/EXPECTED_SHIP_DATE}>
</line_item>
}
</order>
</orders>
</customer>
}
</customers>
Ex 3: Step 9. Verify the Result
Running this query with customer_id set to "CUSTOMER_1" and date1 set to "2002-08-01" produces the following XML query result.
Listing 9-10 Result for Example 3: Date and Time Duration
<customers>
<customer>
<first_name>JOHN_B_1</first_name>
<last_name>KAY_1</last_name>
<orders>
<order>
<line_item expected_ship_date="2002-03-06-08:00" id="LINE_ID_1" product="RBBC01" status="OPEN"/>
<line_item expected_ship_date="2002-03-06-08:00" id="LINE_ID_3" product="BN16" status="OPEN"/>
<line_item expected_ship_date="2002-03-06-08:00" id="LINE_ID_5" product="CS100" status="OPEN"/>
<line_item expected_ship_date="2002-03-06-08:00" id="LINE_ID_1" product="RBBC01" status="OPEN"/>
<line_item expected_ship_date="2002-03-06-08:00" id="LINE_ID_3" product="BN16" status="OPEN"/>
<line_item expected_ship_date="2002-03-06-08:00" id="LINE_ID_5" product="CS100" status="OPEN"/>
</order>
</orders>
</customer>
</customers>
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |