Package org.apache.ofbiz.entity.util
Class EntityListIterator
java.lang.Object
org.apache.ofbiz.entity.util.EntityListIterator
- All Implemented Interfaces:
AutoCloseable
,Iterator<GenericValue>
,ListIterator<GenericValue>
Generic Entity Cursor List Iterator for Handling Cursored DB Results
-
Constructor Summary
ConstructorDescriptionEntityListIterator
(ResultSet resultSet, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader) EntityListIterator
(SQLProcessor sqlp, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader) EntityListIterator
(SQLProcessor sqlp, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader, GenericDAO genericDAO, EntityCondition whereCondition, EntityCondition havingCondition, boolean distinctQuery) -
Method Summary
Modifier and TypeMethodDescriptionboolean
absolute
(int rowNum) performs the same function as theResultSet.absolute(int)
method.void
add
(GenericValue obj) UnsupportedListIterator.add(Object)
method.void
Sets the cursor position to just after the last result so that previous() will return the last result.void
Sets the cursor position to just before the first result so that next() will return the first result.void
close()
Closes the iterator.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.int
Determines the current index of the cursor position.boolean
first()
Sets the cursor position to first result.Gets all the elements of theEntityListIterator
as a list.getPartialList
(int start, int number) Gets a partial list of results starting at start and containing at most number elements.int
Determines the possible result size.boolean
hasNext()
PLEASE NOTE: Because of the nature of the JDBC ResultSet interface this method can be very inefficient.boolean
PLEASE NOTE: Because of the nature of the JDBC ResultSet interface this method can be very inefficient.boolean
last()
Sets the cursor position to last result.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) { ...int
Returns the index of the next result, but does not guarantee that there will be a next result.previous()
Moves the cursor to the previous position and returns the GenericValue object for that position; if there is no previous, returns null.int
Returns the index of the previous result, but does not guarantee that there will be a previous result.boolean
relative
(int rows) performs the same function as theResultSet.relative(int)
method.void
remove()
UnsupportedListIterator.remove()
method.void
set
(GenericValue obj) UnsupportedListIterator.set(Object)
method.void
setDelegator
(Delegator delegator) Sets delegator.void
setFetchSize
(int rows) Sets the fetch size of the result set to the given value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
EntityListIterator
public EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader) -
EntityListIterator
public EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader, GenericDAO genericDAO, EntityCondition whereCondition, EntityCondition havingCondition, boolean distinctQuery) -
EntityListIterator
public EntityListIterator(ResultSet resultSet, ModelEntity modelEntity, List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader)
-
-
Method Details
-
setDelegator
Sets delegator.- Parameters:
delegator
- the delegator
-
afterLast
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
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
Sets the cursor position to last result.- Returns:
- true if the result set is not empty.
- Throws:
GenericEntityException
- if a database error occurs.
-
first
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
Closes the iterator.- Specified by:
close
in interfaceAutoCloseable
- Throws:
GenericEntityException
- if theEntityListIterator
cannot be closed.
-
currentGenericValue
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
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
performs the same function as theResultSet.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
performs the same function as theResultSet.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 interfaceIterator<GenericValue>
- Specified by:
hasNext
in interfaceListIterator<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 interfaceListIterator<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 interfaceIterator<GenericValue>
- Specified by:
next
in interfaceListIterator<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 interfaceListIterator<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 interfaceListIterator<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 interfaceListIterator<GenericValue>
-
setFetchSize
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
Gets all the elements of theEntityListIterator
as a list.- Returns:
- a list of the elements.
- Throws:
GenericEntityException
- if there is a problem with the database.
-
getPartialList
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
Determines the possible result size. If aGenericDAO
is known, the result size will be counted by the database. Otherwise the result size is the last index of theEntityListIterator
.- 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
UnsupportedListIterator.add(Object)
method.- Specified by:
add
in interfaceListIterator<GenericValue>
-
remove
public void remove()UnsupportedListIterator.remove()
method.- Specified by:
remove
in interfaceIterator<GenericValue>
- Specified by:
remove
in interfaceListIterator<GenericValue>
-
set
UnsupportedListIterator.set(Object)
method.- Specified by:
set
in interfaceListIterator<GenericValue>
-