Building Expressions
Use the Expression Builder to create TopLink Expression queries.
To Build an Expression:
- From the Named Queries Format tab (see Figure 4-5), click Edit (or double-click a query string). The Expression Builder dialog box appears.
- Figure 4-8 calls out the following user-interface components:
- Expression tree
- Arguments
- Click Add or Add Nested to create a new expression. TopLink assigns a sequence number to each node and nested node.
- Click Remove to remove an existing expression.
- Select the node and use the Logical Operator drop-down list to specify the operator for the node (AND, OR, Not AND, or Not OR).
- Choose the expression and complete the "Adding Arguments" procedure.
- Click OK.
Adding Arguments
Each expression contains elements (arguments) to evaluate. Expressions using the Is Null or Not Null operators require only a single argument.
Use this procedure to add new arguments.
- Select an existing expression or click Add (or Add Nested) to add a new expression to the named query.
- For the First Argument, click Edit. The Choose Query Key dialog box appears.
- Select the attribute, specify if the query allows a null value, and click OK.
- Use the Operator drop-down list to specify how TopLink should evaluate the expression.
- For the Second Argument, select Literal, Query Key, or Parameter, and click Edit.
- For Literal arguments, the Edit the Literal Type and Value dialog box appears. Choose the literal type (such as String or Integer) and value.
- For Query Key arguments, the Choose Query Key dialog box appears (see Figure 4-9).
- For Parameter arguments, use the drop-down list to select the specific parameter, as created on the Named Queries General tab (see Figure 4-4 ).
Repeat this procedure for each expression or sub-expression.
This expression:
AND
1.manager(Allows Null).lastName EQUAL "Jones"
2.OR
2.1.projects.name LIKE "BETA"
2.2.projects.id EQUAL "4"
3.OR
3.1.AND
3.1.1.address.country EQUAL "Canada"
3.1.2.salary GREATER THAN "25000"
3.2.AND
3.1.1.address.country EQUAL "United States"
3.1.2.salary GREATER THAN "37500"
will find employees who:
- Have a manager with the last name Jones or have no manager, and
- Work on projects with the name Beta or project ID 4, and
- Live in Canada and have a salary of more than 25,000 or
Live in the United States and have a salary of more than 37,500
Copyright © 1997, 2004, Oracle.
All rights reserved.