11.2. Optional Query Elements
Prev | Chapter 11. Query | Next

## 11.2. Optional Query Elements

The following are optional elements of JDO queries:

- Imports. Imports are specified with the `declareImports` method, and are given as a single, semicolon-delimited string following the standard Java `import` syntax. They are used so that you don't have to type out full class names when declaring parameters and variables, as described below.

- Parameter declarations. Parameters act as placeholders in the filter string. They allow you to write a single query, then execute it multiple times, supplying new values each time. Parameters are specified via the `declareParameters` method. The syntax of the method's `String` argument follows the syntax for declaring the parameter signature of a Java method.

- Variable declarations. Variables are typically used to test whether some item in a collection matches certain criteria. They are specified with the `declareVariables` method, using the standard Java syntax for variable declarations.

- Ordering. Sometimes you would like the results of a query to be returned in a specific order. For example, you might want a list of all cars for sale in ascending order by price. The `setOrdering` method enables you to add ordering criteria to your queries. The `String` argument to the method is a comma-separated list of ordering declarations, where each declaration consists of a field name followed by the keywords "ascending" or "descending". The results will be ordered primarily by the first (left-most) ordering declaration. Wherever two results compare equal with this expression, the next ordering expression will be used to order them, and so on.

Prev | Up | Next
Chapter 11. Query | Home | 11.3. JDOQL