T
- the type of entity bean in the iterationpublic interface QueryIterator<T> extends Iterator<T>, Closeable
This can be used when you want to process a very large number of results and means that you don't have to hold all the results in memory at once (unlike findList(), findSet() etc where all the beans are held in the List or Set etc).
Note that findIterate (and findEach and findEachWhile) uses a "per graph" persistence context scope and adjusts jdbc fetch buffer size for large queries. As such it is better to use findList for small queries.
Remember that with QueryIterator
you must call close()
when you have finished iterating the results. Use "try with resources" or ensure it
is closed in a finally block.
Query<Customer> query = server.find(Customer.class)
.where().gt("id", 0)
.orderBy("id")
.setMaxRows(2);
QueryIterator<Customer> it = query.findIterate();
try {
while (it.hasNext()) {
Customer customer = it.next();
// do something with customer ...
}
} finally {
// close the underlying resources
it.close();
}
// try with resources
try (QueryIterator<Customer> it = query.findIterate()) {
while (it.hasNext()) {
Customer customer = it.next();
// do something with customer ...
}
}
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the underlying resources held by this iterator.
|
boolean |
hasNext()
Returns true if the iteration has more elements.
|
T |
next()
Returns the next element in the iteration.
|
void |
remove()
Remove is not allowed.
|
forEachRemaining
boolean hasNext()
void close()
close
in interface AutoCloseable
close
in interface Closeable
Copyright © 2019. All rights reserved.