Package org.apache.ofbiz.entity.util
Class EntityListIterator
- java.lang.Object
-
- org.apache.ofbiz.entity.util.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 Summary
Fields Modifier and Type Field Description protected boolean
closed
protected Delegator
delegator
protected boolean
distinctQuery
protected GenericDAO
genericDAO
protected boolean
haveMadeValue
protected EntityCondition
havingCondition
protected ModelEntity
modelEntity
protected ModelFieldTypeReader
modelFieldTypeReader
static java.lang.String
module
Module Name Used for debuggingprotected java.sql.ResultSet
resultSet
protected java.util.List<ModelField>
selectFields
protected SQLProcessor
sqlp
protected EntityCondition
whereCondition
-
Constructor Summary
Constructors Constructor Description EntityListIterator(java.sql.ResultSet resultSet, ModelEntity modelEntity, java.util.List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader)
EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, java.util.List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader)
EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, java.util.List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader, GenericDAO genericDAO, EntityCondition whereCondition, EntityCondition havingCondition, boolean distinctQuery)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
absolute(int rowNum)
performs the same function as theResultSet.absolute(int)
method.void
add(GenericValue obj)
UnsupportedListIterator.add(Object)
method.void
afterLast()
Sets the cursor position to just after the last result so that previous() will return the last result.void
beforeFirst()
Sets the cursor position to just before the first result so that next() will return the first result.void
close()
Closes the iterator.GenericValue
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.int
currentIndex()
Determines the current index of the cursor position.boolean
first()
Sets the cursor position to first result.java.util.List<GenericValue>
getCompleteList()
Gets all the elements of theEntityListIterator
as a list.java.util.List<GenericValue>
getPartialList(int start, int number)
Gets a partial list of results starting at start and containing at most number elements.int
getResultsSizeAfterPartialList()
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
hasPrevious()
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.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) { ...int
nextIndex()
Returns the index of the next result, but does not guarantee that there will be a next result.GenericValue
previous()
Moves the cursor to the previous position and returns the GenericValue object for that position; if there is no previous, returns null.int
previousIndex()
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)
void
setFetchSize(int rows)
Sets the fetch size of the result set to the given value.
-
-
-
Field Detail
-
module
public static final java.lang.String module
Module Name Used for debugging
-
sqlp
protected SQLProcessor sqlp
-
resultSet
protected java.sql.ResultSet resultSet
-
modelEntity
protected ModelEntity modelEntity
-
selectFields
protected java.util.List<ModelField> selectFields
-
modelFieldTypeReader
protected ModelFieldTypeReader modelFieldTypeReader
-
closed
protected boolean closed
-
haveMadeValue
protected boolean haveMadeValue
-
delegator
protected Delegator delegator
-
genericDAO
protected GenericDAO genericDAO
-
whereCondition
protected EntityCondition whereCondition
-
havingCondition
protected EntityCondition havingCondition
-
distinctQuery
protected boolean distinctQuery
-
-
Constructor Detail
-
EntityListIterator
public EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, java.util.List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader)
-
EntityListIterator
public EntityListIterator(SQLProcessor sqlp, ModelEntity modelEntity, java.util.List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader, GenericDAO genericDAO, EntityCondition whereCondition, EntityCondition havingCondition, boolean distinctQuery)
-
EntityListIterator
public EntityListIterator(java.sql.ResultSet resultSet, ModelEntity modelEntity, java.util.List<ModelField> selectFields, ModelFieldTypeReader modelFieldTypeReader)
-
-
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.
-
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 interfacejava.lang.AutoCloseable
- Throws:
GenericEntityException
- if theEntityListIterator
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 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
public boolean relative(int rows) throws GenericEntityException
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 interfacejava.util.Iterator<GenericValue>
- Specified by:
hasNext
in interfacejava.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 interfacejava.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 interfacejava.util.Iterator<GenericValue>
- Specified by:
next
in interfacejava.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 interfacejava.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 interfacejava.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 interfacejava.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.
-
getCompleteList
public java.util.List<GenericValue> getCompleteList() throws GenericEntityException
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
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 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
public void add(GenericValue obj)
UnsupportedListIterator.add(Object)
method.- Specified by:
add
in interfacejava.util.ListIterator<GenericValue>
-
remove
public void remove()
UnsupportedListIterator.remove()
method.- Specified by:
remove
in interfacejava.util.Iterator<GenericValue>
- Specified by:
remove
in interfacejava.util.ListIterator<GenericValue>
-
set
public void set(GenericValue obj)
UnsupportedListIterator.set(Object)
method.- Specified by:
set
in interfacejava.util.ListIterator<GenericValue>
-
-