public interface Cursor<S>
Query
's fetch
operation. Cursors must be closed promptly when no longer
needed. Failure to do so may result in excessive resource consumption or
deadlock. As a convenience, the close operation is automatically performed
when the end is reached or when an exception is thrown.
Note: because a Cursor manages resources, it is inapproprate to create a long-lived one and pass it around in your code. A cursor is expected to live close to the Query which vended it. To discourage inappropriate retention, the cursor does not implement methods (like "getQuery" or "reset") which would make it more convenient to operate on in isolation.
Similarly, it is difficult to guarantee that the results of a cursor will
be the same in case of a "reset" or reverse iteration. For this reason,
neither is supported; if you need to iterate the same set of objects twice,
simply retain the query object and reissue it. Be aware that the results may
not be identical, if any relevant objects are added to or removed the
repository in the interim. To guard against this, operate within a
serializable isolation level
.
Cursor instances are mutable and not guaranteed to be thread-safe. Only one thread should ever operate on a cursor instance.
Modifier and Type | Method and Description |
---|---|
void |
close()
Call close to release any resources being held by this cursor.
|
int |
copyInto(java.util.Collection<? super S> c)
Copies all remaining next elements into the given collection.
|
int |
copyInto(java.util.Collection<? super S> c,
int limit)
Copies a limited amount of remaining next elements into the given
collection.
|
boolean |
hasNext()
Returns true if this cursor has more elements.
|
S |
next()
Returns the next element from this cursor.
|
int |
skipNext(int amount)
Skips forward by the specified amount of elements, returning the actual
amount skipped.
|
java.util.List<S> |
toList()
Copies all remaining next elements into a new modifiable list.
|
java.util.List<S> |
toList(int limit)
Copies a limited amount of remaining next elements into a new modifiable
list.
|
void close() throws FetchException
FetchException
boolean hasNext() throws FetchException
next
would return an element rather than throwing
an exception.FetchException
- if storage layer throws an exceptionS next() throws FetchException
FetchException
- if storage layer throws an exceptionjava.util.NoSuchElementException
- if the cursor has no next element.int skipNext(int amount) throws FetchException
amount
- maximum amount of elements to skipFetchException
- if storage layer throws an exceptionjava.lang.IllegalArgumentException
- if amount is negativeint copyInto(java.util.Collection<? super S> c) throws FetchException
Cursor cursor; ... while (cursor.hasNext()) { c.add(cursor.next()); }
As a side-effect of calling this method, the cursor is closed.
FetchException
- if storage layer throws an exceptionint copyInto(java.util.Collection<? super S> c, int limit) throws FetchException
Cursor cursor; ... while (--limit >= 0 && cursor.hasNext()) { c.add(cursor.next()); }
limit
- maximum amount of elements to copyFetchException
- if storage layer throws an exceptionjava.lang.IllegalArgumentException
- if limit is negativejava.util.List<S> toList() throws FetchException
Cursor<S> cursor; ... List<S> list = new ... cursor.copyInto(list);
As a side-effect of calling this method, the cursor is closed.
FetchException
- if storage layer throws an exceptionjava.util.List<S> toList(int limit) throws FetchException
Cursor<S> cursor; ... List<S> list = new ... cursor.copyInto(list, limit);
limit
- maximum amount of elements to copyFetchException
- if storage layer throws an exceptionjava.lang.IllegalArgumentException
- if limit is negativeCopyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.