14.4 Query Enhancements


JDOQL is a simple query language that allows persistent objects to be found based on field values. In JDO 2.0, this query language may be extended to add better support for string operations, the ability to perform aggregate operations, and the ability to specify a projection as the result of a query.

14.4.1 Strings

JDOQL supports the String.startsWith() and String.endsWith() methods in query filters as the means of specifying datastore-specific wildcards. However, it does not support additional String methods that may generally be useful in query filters.

JDO 2.0 may add support for the String.toLowerCase() to allow case insensitive string comparisons. It may also add better support for wildcard or regular expression pattern matching beyond the startsWith() and endsWith() methods.

14.4.2 Aggregate operations

JDOQL currently does not support SQL aggregate operators like MIN, MAX, SUM, and AVG. If an application requires the summation of a field for all instances that match a specified criterion, it would have to first perform the query and then retrieve all matching persistent objects, summing their field values. Because many datastores support aggregate operators, this is not the most efficient way of solving the problem.

JDO 2.0 may add support for aggregate operators in JDOQL. This would allow an application to specify a query filter along with an aggregate operator, and rather than returning a collection of persistent objects, the query would return the aggregate result.

14.4.3 Projection

JDOQL currently does not support the ability to return certain fields of a persistent object as a result from a query rather than the persistent object itself.

JDO 2.0 may add the ability to define specific fields that should be returned from the datastore. Rather than returning a collection of persistent objects, the query would return a collection of field values instead. This is more akin to the JDBC concept of a result set.

This is useful when an application needs only the values of a single field of a persistence-capable class, perhaps to display in a selection box. Rather than having to retrieve the entire persistent object to get the field, it can be returned directly by the query, saving on further datastore requests .



Core Java Data Objects
Core Java Data Objects
ISBN: 0131407317
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net