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

    Konstruktoren
    Konstruktor
    Beschreibung
    EntityIterator(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 Typ
    Methode
    Beschreibung
    protected void
    Prepares the query of this iterator if not yet done.
    void
    Closes the query result and releases the storage.
    void
    forEach(de.esoco.lib.expression.Action<E> action)
    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
    void
    setPosition(int index, boolean relative)
    Sets the index of the next entity to be returned by the combination of calls to hasNext() and next().
    int
    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

      public EntityIterator(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.
      Parameter:
      entities - The entity query
    • EntityIterator

      public EntityIterator(de.esoco.storage.QueryPredicate<E> entities, boolean useNewStorage)
      Creates a new instance that performs a certain query.
      Parameter:
      entities - The entity query to perform
      useNewStorage - 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 Schnittstelle AutoCloseable
      Angegeben von:
      close in Schnittstelle de.esoco.lib.manage.Closeable
    • forEach

      public void forEach(de.esoco.lib.expression.Action<E> action)
      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 a StorageRuntimeException.
      Parameter:
      action - The function to invoke on each entity
    • hasNext

      public boolean hasNext()
      Angegeben von:
      hasNext in Schnittstelle Iterator<E extends Entity>
    • next

      public E next()
      Angegeben von:
      next in Schnittstelle Iterator<E extends Entity>
    • setPosition

      public void setPosition(int index, boolean relative)
      Sets the index of the next entity to be returned by the combination of calls to hasNext() and next(). If the index is invalid for the current query hasNext() will return FALSE. This is based on QueryResult.setPosition(int, boolean), so the same limitations apply.
      Parameter:
      index - The new position of this iterator
      relative - 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:
      • Query.size()
    • checkPrepareQuery

      protected void checkPrepareQuery() throws de.esoco.storage.StorageException
      Prepares 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