Create a Named Query |
![]() Previous |
![]() Next |
A named query is a TopLink query that you create and store, by name, for later retrieval and execution. Named queries improve application performance because they are prepared once and can be efficiently reused.
In this step, we will create a named query to find employees with a specific phone number area code.
For more information, see "Configuring Named Queries" in Oracle Toplink Developer's Guide.
Select the PhoneNumber descriptor in the Navigator. The PhoneNumber properties page appears in the Editor.
Select the Queries tab, then select the Named Queries subtab.
On the Named Queries tab, click Add. The Add Named Query dialog appears.
Select the Read All type, enter the name of the query (such as localNumbers) and click OK.
The localNumbers query now appears in the list of queries on the Named Queries tab. Select the General subtab.
On the General subtab, select the localNumbers( ) query, then in the Parameters area, click Add.
In the Add Query dialog, select java.lang.String in the Type field, type ID in the Name field, then click OK.
Select the Selection Criteria tab. In the Type field, select Expression, then click Edit. The Expression Builder dialog appears.
In the Expression Builder dialog, click Add to create a new node to the expression.
For the First Argument, click Edit then select the areaCode.
For the Operator, select Equal.
For the Second Argument, select Literal. Select String as the Type and enter 603 as the Value.
Click OK. The Expression area of the Selection Criteria now shows the completed expression.