Creating and Initializing a Query
The PersistenceManager
interface contains a set of Query
factory methods used to construct Query
instances. They mainly differ in which
query components are initialized. Query
instances may be constructed at any time
before a PersistenceManager
is
closed.
The following PersistenceManager
method constructs an empty
Query
instance with none of the
components initialized:
Query newQuery( );
The following PersistenceManager
methods construct a
Query
instance with an Extent
as the collection of candidate
instances:
Query newQuery(Extent candidates); Query newQuery(Extent candidates, String filter);
The candidate class is initialized with the class of the Extent
. The second method also initializes the
query filter. We used this second method when we constructed the
Query
on line [3] in our example.
Alternatively, a collection can serve as the set of candidate
instances in a query. The following PersistenceManager
methods construct a
Query
instance with a Collection
as the set of candidate
instances:
Query newQuery(Class candidateClass, Collection candidates); Query newQuery(Class candidateClass, Collection candidates, String filter);
When performing a query on a collection, it is necessary to specify the class of the candidate instances explicitly.
The elements in the collection should be persistent instances
associated with the same PersistenceManager
as the Query
instance. If the collection contains
instances associated with another PersistenceManager
, a JDOUserException ...
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.