Class EntityListIterator

java.lang.Object
org.apache.ofbiz.entity.util.EntityListIterator
All Implemented Interfaces:
AutoCloseable, Iterator<GenericValue>, ListIterator<GenericValue>

public class EntityListIterator extends Object implements AutoCloseable, ListIterator<GenericValue>
Generic Entity Cursor List Iterator for Handling Cursored DB Results
  • Constructor Details

  • Method Details

    • setDelegator

      public void setDelegator(Delegator delegator)
      Sets delegator.
      Parameters:
      delegator - the delegator
    • afterLast

      public void afterLast() throws GenericEntityException
      Sets the cursor position to just after the last result so that previous() will return the last result.
      Throws:
      GenericEntityException - if a database error occurs.
    • beforeFirst

      public void beforeFirst() throws GenericEntityException
      Sets the cursor position to just before the first result so that next() will return the first result.
      Throws:
      GenericEntityException - if a database error occurs.
    • last

      public boolean last() throws GenericEntityException
      Sets the cursor position to last result.
      Returns:
      true if the result set is not empty.
      Throws:
      GenericEntityException - if a database error occurs.
    • first

      public boolean first() throws GenericEntityException
      Sets the cursor position to first result.
      Returns:
      true if the result set is not empty.
      Throws:
      GenericEntityException - in case of a database error.
    • close

      public void close() throws GenericEntityException
      Closes the iterator.
      Specified by:
      close in interface AutoCloseable
      Throws:
      GenericEntityException - if the EntityListIterator cannot be closed.
    • currentGenericValue

      public GenericValue currentGenericValue() throws GenericEntityException
      NOTE: Calling this method does return the current value, but so does calling next() or previous() So calling one of those AND this method will cause the value to be created twice.
      Throws:
      GenericEntityException
    • currentIndex

      public int currentIndex() throws GenericEntityException
      Determines the current index of the cursor position.
      Returns:
      the current index, 0 if there is none.
      Throws:
      GenericEntityException - if an error with the database access occurs.
    • absolute

      public boolean absolute(int rowNum) throws GenericEntityException
      performs the same function as the ResultSet.absolute(int) method. if rowNum is positive, goes to that position relative to the beginning of the list; if rowNum is negative, goes to that position relative to the end of the list; a rowNum of 1 is the same as first(); a rowNum of -1 is the same as last()
      Parameters:
      rowNum - the index of the row to set the cursor to.
      Returns:
      true if the cursor moved to a row within the result set, false if it is on the row before or after.
      Throws:
      GenericEntityException - if an error with the database access occurs.
    • relative

      public boolean relative(int rows) throws GenericEntityException
      performs the same function as the ResultSet.relative(int) method. if rows is positive, goes forward relative to the current position; if rows is negative, goes backward relative to the current position;
      Parameters:
      rows - the amount of rows to move.
      Returns:
      true if the cursor is on a row.
      Throws:
      GenericEntityException - in case of an error related to the database.
    • hasNext

      public boolean hasNext()
      PLEASE NOTE: Because of the nature of the JDBC ResultSet interface this method can be very inefficient. It is much better to just use next() until it returns null For example, you could use the following to iterate through the results in an EntityListIterator: GenericValue nextValue = null; while ((nextValue = (GenericValue) this.next()) != null) { ... }
      Specified by:
      hasNext in interface Iterator<GenericValue>
      Specified by:
      hasNext in interface ListIterator<GenericValue>
    • hasPrevious

      public boolean hasPrevious()
      PLEASE NOTE: Because of the nature of the JDBC ResultSet interface this method can be very inefficient. It is much better to just use previous() until it returns null.
      Specified by:
      hasPrevious in interface ListIterator<GenericValue>
    • next

      public GenericValue next()
      Moves the cursor to the next position and returns the value for that position; For example, you could use the following to iterate through the results in an EntityListIterator: GenericValue nextValue = null; while ((nextValue = (GenericValue) this.next()) != null) { ... }
      Specified by:
      next in interface Iterator<GenericValue>
      Specified by:
      next in interface ListIterator<GenericValue>
      Returns:
      the next element or null, if there is no next element.
    • nextIndex

      public int nextIndex()
      Returns the index of the next result, but does not guarantee that there will be a next result.
      Specified by:
      nextIndex in interface ListIterator<GenericValue>
    • previous

      public GenericValue previous()
      Moves the cursor to the previous position and returns the GenericValue object for that position; if there is no previous, returns null.
      Specified by:
      previous in interface ListIterator<GenericValue>
    • previousIndex

      public int previousIndex()
      Returns the index of the previous result, but does not guarantee that there will be a previous result.
      Specified by:
      previousIndex in interface ListIterator<GenericValue>
    • setFetchSize

      public void setFetchSize(int rows) throws GenericEntityException
      Sets the fetch size of the result set to the given value.
      Parameters:
      rows - the fetch size
      Throws:
      GenericEntityException - if a database error occurs.
    • getCompleteList

      public List<GenericValue> getCompleteList() throws GenericEntityException
      Gets all the elements of the EntityListIterator as a list.
      Returns:
      a list of the elements.
      Throws:
      GenericEntityException - if there is a problem with the database.
    • getPartialList

      public List<GenericValue> getPartialList(int start, int number) throws GenericEntityException
      Gets a partial list of results starting at start and containing at most number elements. Start is a one based value, i.e. 1 is the first element.
      Parameters:
      start - the index from which on the elements should be retrieved. Is one based.
      number - the maximum number of elements to get after the start index.
      Returns:
      A list with the retrieved elements, with the size of number or less if the result set does not contain enough values. Empty list in case of no values or an invalid start index.
      Throws:
      GenericEntityException - if there is an issue with the database.
    • getResultsSizeAfterPartialList

      public int getResultsSizeAfterPartialList() throws GenericEntityException
      Determines the possible result size. If a GenericDAO is known, the result size will be counted by the database. Otherwise the result size is the last index of the EntityListIterator.
      Returns:
      the result size or 0 if the result set is empty.
      Throws:
      GenericEntityException - if there is an issue with the call to the database.
    • add

      public void add(GenericValue obj)
      Unsupported ListIterator.add(Object) method.
      Specified by:
      add in interface ListIterator<GenericValue>
    • remove

      public void remove()
      Unsupported ListIterator.remove() method.
      Specified by:
      remove in interface Iterator<GenericValue>
      Specified by:
      remove in interface ListIterator<GenericValue>
    • set

      public void set(GenericValue obj)
      Unsupported ListIterator.set(Object) method.
      Specified by:
      set in interface ListIterator<GenericValue>