|
Project Wonder 5.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecter.extensions.eof.ERXFetchSpecificationBatchIterator
public class ERXFetchSpecificationBatchIterator
The goal of the fetch specification batch iterator is to have the ability to
iterate through a fetch specification that might fetch one million enterprise
objects. Fetching all of the objects into a single editing context is
prohibitive in the amount of memory needed and in the time taken to process
all of the rows.
The iterator allows one to iterate through the fetched objects only hydrating
those objects need in small bite size pieces. The iterator also allows you to
swap out editing contexts between calls to nextBatch(), which will
allow the garbage collector to collect the old editing context and the
previous batch of enterprise objects.
For your convenience, this class also implements Iterator and Enumeration, so
you can use it as such.
Be aware that the batch size is primarily intended to govern the number of
objects requested from the database at once, and may differ from the number
of objects returned by nextBatch(), for instance if the batch size is
changed after fetching, or if filtersBatches() is set to true.
Field Summary | |
---|---|
protected int |
batchSize
holds the selected batch size |
protected com.webobjects.foundation.NSMutableArray |
cachedBatch
holds array of fetched but not-yet-returned objects; used by the Iterator and Enumeration interfaces |
protected int |
currentObjectFetchCount
holds the number of objects fetched |
static int |
DefaultBatchSize
holds the default batch size, any bigger than this an Oracle has a fit |
protected com.webobjects.eocontrol.EOEditingContext |
editingContext
holds a reference to the selected editing context |
protected com.webobjects.eocontrol.EOFetchSpecification |
fetchSpecification
holds a reference to the fetch spec to iterate over |
static org.apache.log4j.Logger |
log
logging support |
protected java.lang.String |
primaryKeyAttributeName
holds the name of the primary key attribute corresponding to the entity being iterated over |
protected com.webobjects.foundation.NSArray |
primaryKeys
holds an array of primary key values to iterate through |
protected boolean |
shouldFilterBatches
determines whether we should re-apply the original qualifier to each batch of objects fetched |
Constructor Summary | |
---|---|
ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification)
Constructs a fetch specification iterator for a given fetch specification with the default batch size. |
|
ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification,
com.webobjects.eocontrol.EOEditingContext ec)
Constructs a fetch specification iterator for a given fetch specification with the default batch size. |
|
ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification,
com.webobjects.eocontrol.EOEditingContext ec,
int batchSize)
Constructs a fetch specification iterator for a given fetch specification and a batch size. |
|
ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification,
com.webobjects.foundation.NSArray pkeys,
com.webobjects.eocontrol.EOEditingContext ec,
int batchSize)
Constructs a fetch specification iterator for a fetch specification, an optional set of pre-fetched primary keys and a batch size. |
Method Summary | |
---|---|
protected com.webobjects.foundation.NSArray |
_fetchNextBatch()
Fetches the next batch unconditionally. |
protected boolean |
_hasMoreToFetch()
|
int |
batchCount()
Gets the number of batches for a given iterator. |
protected com.webobjects.eocontrol.EOFetchSpecification |
batchFetchSpecificationForQualifier(com.webobjects.eocontrol.EOQualifier qualifier)
|
int |
batchSize()
Gets the batch size. |
com.webobjects.foundation.NSArray |
batchWithIndex(int index)
Returns the batch corresponding to the given index, that is, the batch beginning at batchSize() * index. |
com.webobjects.foundation.NSArray |
batchWithRange(com.webobjects.foundation.NSRange requestedRange)
Returns the batch corresponding to the given range. |
int |
count()
Gets the number of objects. |
int |
currentBatchIndex()
Gets the current batch index. |
int |
currentObjectFetchCount()
Gets the current number of objects fetched thus far. |
com.webobjects.eocontrol.EOEditingContext |
editingContext()
Gets the currently set editing context. |
boolean |
filtersBatches()
If true, each batch will be filtered based on the original qualifier. |
boolean |
hasMoreElements()
Implementation of the Enumeration interface |
boolean |
hasNext()
Implementation of the Iterator interface |
boolean |
hasNextBatch()
Determines if the iterator has another batch. |
java.lang.Object |
next()
Implementation of the Iterator interface |
com.webobjects.foundation.NSArray |
nextBatch()
Gets the next batch of enterprise objects for the given fetch specification. |
java.lang.Object |
nextElement()
Implementation of the Enumeration interface |
protected com.webobjects.foundation.NSArray |
primaryKeys()
Method used to fetch the primary keys of the objects for the given fetch specification. |
void |
remove()
Implementation of the Iterator interface |
void |
reset()
Resets the batch iterator so it will refetch its primary keys again. |
void |
setBatchSize(int batchSize)
Sets the batch size. |
void |
setEditingContext(com.webobjects.eocontrol.EOEditingContext ec)
Sets the editing context used to fetch objects against. |
void |
setFiltersBatches(boolean newValue)
If set to true, each batch fetched will be filtered based on the qualifier attached to the original fetch specification. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DefaultBatchSize
public static final org.apache.log4j.Logger log
protected int batchSize
protected com.webobjects.eocontrol.EOEditingContext editingContext
protected com.webobjects.eocontrol.EOFetchSpecification fetchSpecification
protected java.lang.String primaryKeyAttributeName
protected com.webobjects.foundation.NSArray primaryKeys
protected com.webobjects.foundation.NSMutableArray cachedBatch
protected int currentObjectFetchCount
protected boolean shouldFilterBatches
Constructor Detail |
---|
public ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification)
fetchSpecification
- to iterate throughpublic ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification, com.webobjects.eocontrol.EOEditingContext ec)
fetchSpecification
- to iterate throughec
- editing context to fetch againstpublic ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification, com.webobjects.eocontrol.EOEditingContext ec, int batchSize)
fetchSpecification
- to iterate throughec
- editing context to fetch againstbatchSize
- number of objects to fetch in a given batchpublic ERXFetchSpecificationBatchIterator(com.webobjects.eocontrol.EOFetchSpecification fetchSpecification, com.webobjects.foundation.NSArray pkeys, com.webobjects.eocontrol.EOEditingContext ec, int batchSize)
Note: if no ec is supplied a new one is initialized.
fetchSpecification
- to iterate throughpkeys
- primary keys to iterate throughec
- editing context to fetch againstbatchSize
- number of objects to fetch in a given batchMethod Detail |
---|
public int batchSize()
public int currentBatchIndex()
public int batchCount()
public int count()
public int currentObjectFetchCount()
public void setBatchSize(int batchSize)
batchSize
- to be set.public boolean filtersBatches()
setFiltersBatches(boolean)
public void setFiltersBatches(boolean newValue)
nextBatch()
, and null may be returned
from next()
and nextElement()
.
Note that not all qualifiers can be applied in-memory, so this should not bet set
to true if such a qualifier is being used.
Defaults to false.
newValue
- whether batches should be re-filteredpublic com.webobjects.eocontrol.EOEditingContext editingContext()
public void setEditingContext(com.webobjects.eocontrol.EOEditingContext ec)
ec
- editing context used to fetch againstpublic boolean hasNextBatch()
nextBatch()
protected boolean _hasMoreToFetch()
public com.webobjects.foundation.NSArray nextBatch()
next()
or nextElement()
,
this method may return a partial batch of already-cached
objects, in the editing context which was in place at the
time they were fetched.)
protected com.webobjects.foundation.NSArray _fetchNextBatch()
nextBatch()
, to get
automatic support for the Iterator and Enumeration interfaces.
public com.webobjects.foundation.NSArray batchWithIndex(int index)
batchSize()
* index.
Note that if the batch size has been changed after fetching, the
batches return by nextBatch()
may not line up with the
batches returned by this method.
Calling this method does not affect the position of the iterator.
index
- index of batch to retrieve
public com.webobjects.foundation.NSArray batchWithRange(com.webobjects.foundation.NSRange requestedRange)
requestedRange
- range of batch to retrieve
protected com.webobjects.eocontrol.EOFetchSpecification batchFetchSpecificationForQualifier(com.webobjects.eocontrol.EOQualifier qualifier)
protected com.webobjects.foundation.NSArray primaryKeys()
public void reset()
public boolean hasNext()
hasNext
in interface java.util.Iterator
public java.lang.Object next()
next
in interface java.util.Iterator
public void remove()
remove
in interface java.util.Iterator
public boolean hasMoreElements()
hasMoreElements
in interface java.util.Enumeration
public java.lang.Object nextElement()
nextElement
in interface java.util.Enumeration
|
Last updated: Tue, Feb 21, 2017 05:45 PM CET | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |