V
- type of the objects contained in the result set.public abstract class AbstractObjectResultSet<V> extends Object implements ObjectResultSet<V>
Abstract base class for classes that implement the ObjectResultSet
interface. This base class handles most of the complexity involved in writing
an implementation of ObjectResultSet
. Child classes only have to
implement the fetchNextPage()
method for a complete implementation
of the ObjectResultSet
interface.
Like indicated for the ObjectResultSet
interface, this class is
not thread safe.
ObjectResultSet.ObjectResultSetIterator<V>
Constructor and Description |
---|
AbstractObjectResultSet() |
Modifier and Type | Method and Description |
---|---|
List<V> |
all()
Returns all remaining objects in this object result-set as a list.
|
ListenableFuture<Void> |
fetchMoreResults()
Forces fetching the next page of object for this object result-set.
|
protected abstract ListenableFuture<Iterator<V>> |
fetchNextPage()
Fetches the next page of objects.
|
int |
getAvailableWithoutFetching()
Returns the number of objects that can be retrieved from this object
result-set without blocking to fetch.
|
boolean |
isExhausted()
Tells whether this object result-set has more objects.
|
boolean |
isFullyFetched()
Tells whether all objects from this object result set have been fetched
from the database.
|
Iterator<V> |
iterator()
Returns an iterator over the objects contained in this object result-set.
|
V |
one()
Returns the next object from this object result-set.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public List<V> all()
ObjectResultSet
Returns all remaining objects in this object result-set as a list.
Calls to this method will block until all objects have been retrieved from the database.
Note that, contrary to iterator()
or successive calls to
one()
, this method forces fetching the full content of the object
result-set at once, holding it all in memory in particular. It is thus
recommended to prefer iterations through iterator()
when
possible, especially if the result set can be big.
all
in interface ObjectResultSet<V>
public ListenableFuture<Void> fetchMoreResults()
ObjectResultSet
Forces fetching the next page of object for this object result-set.
The use of this method is entirely optional. It will be called
automatically while the result set is consumed (through ObjectResultSet.one()
,
ObjectResultSet.all()
or iteration) when needed (i.e. when
getAvailableWithoutFetching() == 0
and
isFullyFetched() == false
).
You can however call this method manually to force the fetching of the next page of objects. This can allow to prefetch objects before they are strictly needed.
This method is not blocking. However, hasNext()
on the
iterator returned by ObjectResultSet.iterator()
or calling ObjectResultSet.one()
will
block until the fetch query returns if all objects that have been fetched
previously have already been returned.
Only one page of objects (for a given result set) can be fetched at any given time. If this method is called twice and the query triggered by the first call has not returned yet when the second one is performed, then the second call will simply return a future on the currently in progress query.
fetchMoreResults
in interface ObjectResultSet<V>
isFullyFetched() == true
), then the returned future
will return immediately (you should thus call
ObjectResultSet.isFullyFetched()
to know if calling this method can be
of any use}).public int getAvailableWithoutFetching()
ObjectResultSet
getAvailableWithoutFetching
in interface ObjectResultSet<V>
ObjectResultSet.isFullyFetched()
, this is the total number of objects
remaining in this result set (after which the result set will be
exhausted).public boolean isExhausted()
ObjectResultSet
Tells whether this object result-set has more objects.
Calls to this method may block if
getAvailableWithoutFetching() == 0
and
isFullyFetched() == false
.
isExhausted
in interface ObjectResultSet<V>
true
if this object result-set is exhausted (
one() == null
), false
if there are
objects left in this result set.public boolean isFullyFetched()
ObjectResultSet
Tells whether all objects from this object result set have been fetched from the database.
Note that if this method returns true
, then
ObjectResultSet.getAvailableWithoutFetching()
will return how many objects remain
in the result set before exhaustion. However, if this method returns
false
, this does not guarantee that the result set is not
exhausted (you should call ObjectResultSet.isExhausted()
to verify it).
isFullyFetched
in interface ObjectResultSet<V>
true
if all objects have been fetched,
false
if there might be more objects that have not
been loaded from the database yet.public Iterator<V> iterator()
ObjectResultSet
Returns an iterator over the objects contained in this object result-set.
Calls to the Iterator.hasNext()
method may block if
getAvailableWithoutFetching() == 0
and
isFullyFetched() == false
.
The Iterator.next()
method is equivalent to calling
ObjectResultSet.one()
. So this iterator will consume objects from this result
set and after a full iteration, the result set will be empty.
The returned iterator does not support the Iterator.remove()
method.
public V one()
ObjectResultSet
Returns the next object from this object result-set.
Calls to this method may block if
getAvailableWithoutFetching() == 0
and
isFullyFetched() == false
.
one
in interface ObjectResultSet<V>
null
if
this result set is exhausted.protected abstract ListenableFuture<Iterator<V>> fetchNextPage()
Fetches the next page of objects. This method must be implemented by child classes and its implementation must not block.
This method start the fetching of the next page of objects and returns a
future that provides access to the objects once they have been fetched.
If there are no more objects, the future returned by this method must
return null
.
The abstract base class guarantees that this method is only called when the future returned by an earlier call is done and has yielded a non-null result.
null
if there are no more objects in the result set.Copyright © 2011–2016 aquenos GmbH. All rights reserved.