Chapter 2: Queries


Overview

The ability to retrieve objects by queries is an essential feature of a persistence service, and for that reason, this book begins with JDO's query service. Queries are used to find persistent data objects that meet a set of conditions. A JDO query can search for the relevant objects either in the datastore or in a collection of persistent objects in memory.

Queries are one way that an application can retrieve references to persistent objects, but there are a variety of other ways. An application can retrieve an application data object using an identity object. An application can also iterate through all persistent objects of an application data class using the Extent interface, which is discussed in the next section. An application may obtain a reference to a persistent object by navigating the persistent fields of other data objects. Once obtained, references to persistent objects remain valid as long as the persistence manager that produced them remains open. As a result, a persistent application data object can be fetched in one transaction and modified in a later transaction.

Although there are many ways for the application to obtain a reference to a persistent object in memory, the typical application will make heavy use of JDO's query service. This chapter describes the Query interface in JDO. It begins with the Extent interface because extents are often used to construct queries. It describes the configuration of JDO queries, including setting the query filter and declaring variables and parameters. It compares JDO's queries to SQL queries. This chapter concludes by examining how the development process benefits by using the JDO query service.




Using and Understanding Java Data Objects
Using and Understanding Java Data Objects
ISBN: 1590590430
EAN: 2147483647
Year: 2005
Pages: 156
Authors: David Ezzio

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