[ Team LiB ] |
Chapter 9. The JDO Query LanguageIn 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 query facility was designed with the following goals:
The execution of a query might be performed by the PersistenceManager or it might be delegated to the underlying datastore. Thus, the actual underlying datastore query executed might be implemented in a language very different from Java, and it might be optimized to take advantage of a particular query-language implementation. |
[ Team LiB ] |