Chapter 9. The JDO Query Language

In Chapter 8 we learned how to access all the instances of a class by using an Extent. Once we have accessed some instances from the datastore, we can navigate to other related instances in Java by traversing references and iterating through collections. This allows us to access an application-specific closure of related instances to perform the functionality provided by the application.

But when you iterate an Extent, you potentially access all the instances of a class. We may only care about one or a small number of instances of the class that meet certain criteria. Once these initial instances have been accessed, we typically then navigate to instances related to those initial instances. However, getting to the first few persistent instances is a bootstrap issue. JDO provides a query language, called JDO Query Language (JDOQL), that is used to access persistent instances based on specified search criteria.

You perform queries in JDO by using the Query interface. The PersistenceManager interface is a factory for creating Query instances, and queries are executed in the context of the PersistenceManager instance used to create the Query instance. JDO queries allow you to filter out instances from a set of candidate instances specified by either an Extent or a Collection. A filter consisting of a Boolean expression is applied to the candidate instances. The query result includes all of the instances for which the Boolean expression is true.

The JDO ...

Get Java Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.