Project Wonder 2.0

er.extensions
Class ERXFetchSpecificationBatchIterator

java.lang.Object
  extended byer.extensions.ERXFetchSpecificationBatchIterator

public class ERXFetchSpecificationBatchIterator
extends Object

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 singel 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.


Field Summary
protected  int batchSize
          holds the selected batch size
protected  int currentBatchIndex
          holds the current batch index
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 ERXLogger log
          logging support
protected  NSArray primaryKeys
          holds an array of primary key values to iterate through
 
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
 int batchCount()
          Gets the number of batches for a given iterator.
 int batchSize()
          Gets the batch size.
 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.
protected  void fetchPrimaryKeys()
          Method used to fetch the primary keys of the objects for the given fetch specification.
protected  boolean hasFetchedPrimaryKeys()
          Determines if the primary keys have been fetched yet for the given fetch specification.
 boolean hasNextBatch()
          Determines if the iterator has another batch.
 NSArray nextBatch()
          Gets the next batch of enterprise objects for the given fetch specification.
 void reset()
          Resets the batch iterator so it will refetch it's primary keys again.
 void setBatchSize(int batchSize)
          Sets the batch size.
 void setEditingContext(EOEditingContext ec)
          Sets the editing context used to fetch objects against.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DefaultBatchSize

public static final int DefaultBatchSize
holds the default batch size, any bigger than this an Oracle has a fit

See Also:
Constant Field Values

log

public static final ERXLogger log
logging support


batchSize

protected int batchSize
holds the selected batch size


editingContext

protected EOEditingContext editingContext
holds a reference to the selected editing context


fetchSpecification

protected EOFetchSpecification fetchSpecification
holds a reference to the fetch spec to iterate over


primaryKeys

protected NSArray primaryKeys
holds an array of primary key values to iterate through


currentBatchIndex

protected int currentBatchIndex
holds the current batch index


currentObjectFetchCount

protected int currentObjectFetchCount
holds the number of objects fetched

Constructor Detail

ERXFetchSpecificationBatchIterator

public ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecication)
Constructs a fetch specification iterator for a given fetch specification with the default batch size. Note you will have to set an editingContext on the iterator before calling the nextBatch method.

Parameters:
fetchSpecication - to iterate through

ERXFetchSpecificationBatchIterator

public ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
                                          EOEditingContext ec)
Constructs a fetch specification iterator for a given fetch specification with the default batch size. All objects will be fetched from the given editing context. Note that you can switch out different editing contexts between calls to nextBatch

Parameters:
ec - editing context to fetch against

ERXFetchSpecificationBatchIterator

public ERXFetchSpecificationBatchIterator(EOFetchSpecification fetchSpecification,
                                          EOEditingContext ec,
                                          int batchSize)
Constructs a fetch specification iterator for a given fetch specification and a batch size. All objects will be fetched from the given editing context. Note that you can switch out different editing contexts between calls to nextBatch

Parameters:
ec - editing context to fetch against
batchSize - number of objects to fetch in a given batch

ERXFetchSpecificationBatchIterator

public 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. All objects will be fetched from the given editing context. Note that you can switch out different editing contexts between calls to nextBatch

Parameters:
pkeys - primary keys to iterate through
ec - editing context to fetch against
batchSize - number of objects to fetch in a given batch
Method Detail

batchSize

public int batchSize()
Gets the batch size.

Returns:
number of enterprise objects to fetch a batch.

currentBatchIndex

public int currentBatchIndex()
Gets the current batch index.

Returns:
number of batches fetched thus far

batchCount

public int batchCount()
Gets the number of batches for a given iterator.

Returns:
number of objects / batch size rounded up

currentObjectFetchCount

public int currentObjectFetchCount()
Gets the current number of objects fetched thus far.

Returns:
current number of objects fetched.

setBatchSize

public void setBatchSize(int batchSize)
Sets the batch size.

Parameters:
batchSize - to be set.

editingContext

public EOEditingContext editingContext()
Gets the currently set editing context.

Returns:
editing context used to fetch against

setEditingContext

public void setEditingContext(EOEditingContext ec)
Sets the editing context used to fetch objects against. It is perfectly fine to change editing contexts between fetching the next batch.

Parameters:
ec - editing context used to fetch against

hasNextBatch

public boolean hasNextBatch()
Determines if the iterator has another batch.

Returns:
if calling nextBatch will have any effect

nextBatch

public NSArray nextBatch()
Gets the next batch of enterprise objects for the given fetch specification. Note that the editing context that is set will be used to fetch against. You can swap out a different editing context before calling this method to reduce memory consumption.


hasFetchedPrimaryKeys

protected boolean hasFetchedPrimaryKeys()
Determines if the primary keys have been fetched yet for the given fetch specification.

Returns:
if the primary keys array has been populated

fetchPrimaryKeys

protected void fetchPrimaryKeys()
Method used to fetch the primary keys of the objects for the given fetch specification. Note the sort orderings for the fetch specification are respected.


reset

public void reset()
Resets the batch iterator so it will refetch it's primary keys again.


Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.