|
Project Wonder 5.0.0.8795 | |||||||||
| 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 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 EOEditingContext |
editingContext
holds a reference to the selected editing context |
protected EOFetchSpecification |
fetchSpecification
holds a reference to the fetch spec to iterate over |
static Logger |
log
logging support |
protected String |
primaryKeyAttributeName
holds the name of the primary key attribute corresponding to the entity being iterated over |
protected 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(EOFetchSpecification fetchSpecication)
Constructs a fetch specification iterator for a given fetch specification with the default batch size. |
|
ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
EOEditingContext ec)
Constructs a fetch specification iterator for a given fetch specification with the default batch size. |
|
ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
EOEditingContext ec,
int batchSize)
Constructs a fetch specification iterator for a given fetch specification and a batch size. |
|
ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
NSArray pkeys,
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 NSArray |
_fetchNextBatch()
Fetches the next batch unconditionally. |
protected boolean |
_hasMoreToFetch()
|
int |
batchCount()
Gets the number of batches for a given iterator. |
protected EOFetchSpecification |
batchFetchSpecificationForQualifier(EOQualifier qualifier)
|
int |
batchSize()
Gets the batch size. |
NSArray |
batchWithIndex(int index)
Returns the batch corresponding to the given index, that is, the batch beginning at batchSize() * index. |
NSArray |
batchWithRange(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. |
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. |
Object |
next()
Implementation of the Iterator interface |
NSArray |
nextBatch()
Gets the next batch of enterprise objects for the given fetch specification. |
Object |
nextElement()
Implementation of the Enumeration interface |
protected 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(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 Logger log
protected int batchSize
protected EOEditingContext editingContext
protected EOFetchSpecification fetchSpecification
protected String primaryKeyAttributeName
protected NSArray primaryKeys
protected NSMutableArray cachedBatch
protected int currentObjectFetchCount
protected boolean shouldFilterBatches
| Constructor Detail |
|---|
public ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecication)
fetchSpecication - to iterate through
public ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
EOEditingContext ec)
fetchSpecification - to iterate throughec - editing context to fetch against
public ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
EOEditingContext ec,
int batchSize)
fetchSpecification - to iterate throughec - editing context to fetch againstbatchSize - number of objects to fetch in a given batch
public ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
NSArray pkeys,
EOEditingContext ec,
int batchSize)
fetchSpecification - to iterate throughpkeys - primary keys to iterate throughec - editing context to fetch againstbatchSize - number of objects to fetch in a given batch| Method 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 EOEditingContext editingContext()
public void setEditingContext(EOEditingContext ec)
ec - editing context used to fetch againstpublic boolean hasNextBatch()
nextBatch()protected boolean _hasMoreToFetch()
public NSArray nextBatch()
nextBatch()
with calls to 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 NSArray _fetchNextBatch()
nextBatch(), to get
automatic support for the Iterator and Enumeration interfaces.
public 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 postion of the iterator.
index - index of batch to retrieve
public NSArray batchWithRange(NSRange requestedRange)
requestedRange - range of batch to retrieve
protected EOFetchSpecification batchFetchSpecificationForQualifier(EOQualifier qualifier)
protected NSArray primaryKeys()
public void reset()
public boolean hasNext()
hasNext in interface Iteratorpublic Object next()
next in interface Iteratorpublic void remove()
remove in interface Iteratorpublic boolean hasMoreElements()
hasMoreElements in interface Enumerationpublic Object nextElement()
nextElement in interface Enumeration
|
Last updated: Fri, Jan 9, 2009 04:35 AM EST | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||