You can use annotated or inline methods
to query in-memory Java collections,
such as arrays,
classes that implement java.lang.Iterable, and classes that implement
java.util.Iterator.
With queries over collections,
you can use SQL to filter a set
of objects that are returned by a query on a database object. The
objects are materialized by a previous query against a connected data
source. You can use any SELECT statement that conforms to the SQL
92 standard.
For example, you run a query against the database
table CUSTOMER,
populating a List object with one Customer object
per record in the table. Then, you perform a query on the List object.
The second query is a query over a collection. For this second query
and all subsequent queries on the List object,
you no longer need the connection to the database because the content
of the List object resides in memory.
Attention: When you use Iterator objects, keep in mind
the following points:
- After you materialize the results of
the query in the Iterator
object, you must keep the connection to the database open until you
finish using that Iterator object.
- The act of examining the
contents of an object that implements
java.util.Iterator causes those contents to be consumed, and there
is no way to start over again at the beginning of the contents.
- Unless
an Iterator object is initially empty,
there is no way to know how many objects are in it until after a query
is complete.