Class EntityListIterator

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.util.Iterator<GenericValue>, java.util.ListIterator<GenericValue>

    public class EntityListIterator
    extends java.lang.Object
    implements java.lang.AutoCloseable, java.util.ListIterator<GenericValue>
    Generic Entity Cursor List Iterator for Handling Cursored DB Results
    • Field Detail

      • module

        public static final java.lang.String module
        Module Name Used for debugging
      • resultSet

        protected java.sql.ResultSet resultSet
      • selectFields

        protected java.util.List<ModelField> selectFields
      • closed

        protected boolean closed
      • haveMadeValue

        protected boolean haveMadeValue
      • distinctQuery

        protected boolean distinctQuery
    • Method Detail

      • setDelegator

        public void setDelegator​(Delegator 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.
      • 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 java.util.Iterator<GenericValue>
        Specified by:
        hasNext in interface java.util.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 java.util.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 java.util.Iterator<GenericValue>
        Specified by:
        next in interface java.util.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 java.util.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 java.util.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 java.util.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.
      • getPartialList

        public java.util.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 java.util.ListIterator<GenericValue>
      • remove

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

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