Table of Contents Previous Section
Building a Qualifier
EOModeler's Fetch Specification Builder mode provides an interface for building a qualifier graphically. To use it, select your fetch specification, and choose the Qualifier tab in the Fetch Specification Builder.For example, a Movie has a Voting object that keeps a runningAverage of how reviewers have voted on the movie. Suppose you want to create a fetch specification for the Movie entity that fetches all movies whose runningAverage is greater than eight. To build the qualifier for such a query:
- In the attribute browser, click Movie's voting relationship.
- In the second column of the browser, select the runningAverage attribute.
- Click the >= button.
- In the text field, type "8" as the right hand side of the expression.
The text field just under the browser is updated to display the attribute as the left hand side of an expression. Note that the runningAverage attribute is represented by a key path (voting.runningAverage) that identifies the relationship (voting) through which the attribute is accessed.
Figure 41. Building an Expression.
EOModeler adds a greater than or equal to operator to the expression.
Creating Compound Qualifiers
You can also use the Query Builder to create compound qualifiers made up of multiple expressions. Click the And button to create a new expression and AND it with the first one. Click the Or button to create a new expression and OR it with the first.For example, building on the example in the previous section, suppose that you want to fetch movies with a runningAverage greater than or equal to eight but that also have at least ten voters contributing to the average. To further restrict the fetch specification:
- Click the And button.
- Choose voting.numberOfVotes in the attribute browser.
- Click the >= button.
- Type 10 as the right hand side of the expression.
EOModeler adds a second expression and ANDs it to the first expression.
As you build up a complex query, the text field at the bottom of the Query Builder updates to include the full text of the compound qualifier. Instead of building up expressions one by one with the And and Or buttons, you can type directly into this lower text field. The Qualifier Builder parses the qualifier string and displays the individual expressions.
Figure 42. Creating a Compound Qualifier
Using Qualifier Variables
You can specify absolute criteria for a fetch specification's qualifier- "voting.runningAverage >= 8", for example. However, such a fetch specification is of limited use. More frequently, you want to specify the form of a qualifier and let users supply specific values when they run the application. You can do this with qualifier variables.You specify a qualifier variable using the dollar sign character ($), as in the following:
dateReleased = $aDateFor example, suppose you want to allow users to search for movies by title, date released, or studio. The query would look like this:
((title = $title) ORYou can build this qualifier in EOModeler as specified in the previous sections, and then bind its qualifier variables (title, date, studioName) to your application's user interface. When the application runs, Enterprise Objects Framework automatically replaces the qualifier variables with values supplied in the user interface. You can set this up as follows:
(dateReleased = $date) OR
(studio.name = $studioName))
- Create the fetch specification with EOModeler.
- Use Query Builder's user interface to set up a query on the title, date, and studio.name attributes.
On the right side of each expression, use the $ syntax to identify the qualifier variables.
- Use WebObjects builder to create a component that allows the user to enter the query criteria.
- Drag the fetch specification from EOModeler into your component.
- In the WebObjects Builder panel that opens, choose "Add and Configure."
- Configure the new display group, setting its fetch specification to the one you defined in your model.
- In WebObjects Builder, bind the user interface elements to the queryBindings.title, queryBindings.date, and queryBindings.studioName keys of your display group (movieDisplayGroup, for example).
You might create text fields for the title and date released and a pop-up list for the studio name, for example.
This has the effect of creating a new display group for your specification's entity.
Table of Contents Next Section