Package de.esoco.entity
Klasse EntityIterator<E extends Entity>
java.lang.Object
de.esoco.entity.EntityIterator<E>
- Alle implementierten Schnittstellen:
de.esoco.lib.manage.Closeable
,AutoCloseable
,Iterator<E>
public class EntityIterator<E extends Entity>
extends Object
implements Iterator<E>, de.esoco.lib.manage.Closeable
An iterator implementation for the iteration over an entity query. Because
the methods of the
Iterator
interface don't support throwing
exceptions a occurring StorageException
will be converted into a
StorageRuntimeException
.
Important: because the iterator holds references to storage objects the
associated resources must be released after the iterator has been used by
invoking the close()
method. It is recommended to do that in a
try-with-resource block if possible.
-
Konstruktorübersicht
KonstruktorBeschreibungEntityIterator
(de.esoco.storage.QueryPredicate<E> entities) Creates a new instance that performs a certain query on the default storage for the queried entity type and current thread.EntityIterator
(de.esoco.storage.QueryPredicate<E> entities, boolean useNewStorage) Creates a new instance that performs a certain query. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungprotected void
Prepares the query of this iterator if not yet done.void
close()
Closes the query result and releases the storage.void
Invokes a function on each iterated entity and closes the storage afterwards.protected void
handleError
(de.esoco.storage.StorageException storage) Performs the error handling if an exception occurred in another iterator method.boolean
hasNext()
next()
void
setPosition
(int index, boolean relative) int
size()
Returns the size of the query result this iterator represents.Von Klasse geerbte Methoden java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Von Schnittstelle geerbte Methoden java.util.Iterator
forEachRemaining, remove
-
Konstruktordetails
-
EntityIterator
Creates a new instance that performs a certain query on the default storage for the queried entity type and current thread.- Parameter:
entities
- The entity query
-
EntityIterator
Creates a new instance that performs a certain query.- Parameter:
entities
- The entity query to performuseNewStorage
- TRUE to perform the query on a new storage instance (instead of the shared storage for the current thread)
-
-
Methodendetails
-
close
public void close()Closes the query result and releases the storage. This method must always be invoked after an entity iterator has been used to prevent resource leakage.- Angegeben von:
close
in SchnittstelleAutoCloseable
- Angegeben von:
close
in Schnittstellede.esoco.lib.manage.Closeable
-
forEach
Invokes a function on each iterated entity and closes the storage afterwards. Like in the iterator methods a storage exception that occurs will be wrapped into aStorageRuntimeException
.- Parameter:
action
- The function to invoke on each entity
-
hasNext
public boolean hasNext() -
next
-
setPosition
public void setPosition(int index, boolean relative) Sets the index of the next entity to be returned by the combination of calls tohasNext()
andnext()
. If the index is invalid for the current queryhasNext()
will return FALSE. This is based onQueryResult.setPosition(int, boolean)
, so the same limitations apply.- Parameter:
index
- The new position of this iteratorrelative
- TRUE to set the position relative to the current position, FALSE to set an absolute position relative to the full query
-
size
public int size()Returns the size of the query result this iterator represents.- Gibt zurück:
- The query size
- Siehe auch:
-
checkPrepareQuery
protected void checkPrepareQuery() throws de.esoco.storage.StorageExceptionPrepares the query of this iterator if not yet done.- Löst aus:
de.esoco.storage.StorageException
- If the storage access fails
-
handleError
protected void handleError(de.esoco.storage.StorageException storage) throws de.esoco.storage.StorageRuntimeException Performs the error handling if an exception occurred in another iterator method.- Parameter:
storage
- e The exception- Löst aus:
de.esoco.storage.StorageRuntimeException
- The converted exception
-