Project Wonder 5.0

er.extensions.batching
Class ERXBatchingDisplayGroup<T>

java.lang.Object
  extended by com.webobjects.appserver.WODisplayGroup
      extended by er.extensions.appserver.ERXDisplayGroup<T>
          extended by er.extensions.batching.ERXBatchingDisplayGroup<T>
All Implemented Interfaces:
com.webobjects.eocontrol.EOKeyValueArchiving, com.webobjects.eocontrol.EOKeyValueArchiving.Awaking, com.webobjects.foundation.NSDisposable, com.webobjects.foundation.NSKeyValueCoding, com.webobjects.foundation.NSKeyValueCoding.ErrorHandling, java.io.Serializable

public class ERXBatchingDisplayGroup<T>
extends ERXDisplayGroup<T>

Extends WODisplayGroup in order to provide real batching. This is done by adding database specific code to the select statement from the EOFetchSpecification from the WODisplayGroup's EODataSource which must be an EODatabaseDataSource. If used with other datasources, it reverts to the default behaviour.

See Also:
Serialized Form
Author:
dt first version, ak gross hacks, made functional and usable.

Nested Class Summary
static class ERXBatchingDisplayGroup.FakeArray
          Dummy array class that is used to provide a certain number of entries.
 
Nested classes/interfaces inherited from class com.webobjects.appserver.WODisplayGroup
com.webobjects.appserver.WODisplayGroup.Delegate
 
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCoding
com.webobjects.foundation.NSKeyValueCoding._BooleanFieldBinding, com.webobjects.foundation.NSKeyValueCoding._BooleanMethodBinding, com.webobjects.foundation.NSKeyValueCoding._FieldBinding, com.webobjects.foundation.NSKeyValueCoding._ForwardingBinding, com.webobjects.foundation.NSKeyValueCoding._KeyBinding, com.webobjects.foundation.NSKeyValueCoding._KeyBindingCreation, com.webobjects.foundation.NSKeyValueCoding._MethodBinding, com.webobjects.foundation.NSKeyValueCoding._NumberFieldBinding, com.webobjects.foundation.NSKeyValueCoding._NumberMethodBinding, com.webobjects.foundation.NSKeyValueCoding._ReflectionKeyBindingCreation, com.webobjects.foundation.NSKeyValueCoding.DefaultImplementation, com.webobjects.foundation.NSKeyValueCoding.ErrorHandling, com.webobjects.foundation.NSKeyValueCoding.Null, com.webobjects.foundation.NSKeyValueCoding.UnknownKeyException, com.webobjects.foundation.NSKeyValueCoding.Utility, com.webobjects.foundation.NSKeyValueCoding.ValueAccessor
 
Nested classes/interfaces inherited from interface com.webobjects.eocontrol.EOKeyValueArchiving
com.webobjects.eocontrol.EOKeyValueArchiving._NullValueSupport, com.webobjects.eocontrol.EOKeyValueArchiving._NumberSupport, com.webobjects.eocontrol.EOKeyValueArchiving._TimestampSupport, com.webobjects.eocontrol.EOKeyValueArchiving.Awaking, com.webobjects.eocontrol.EOKeyValueArchiving.FinishInitialization, com.webobjects.eocontrol.EOKeyValueArchiving.Support
 
Field Summary
protected  int _batchCount
          total number of batches
protected  com.webobjects.foundation.NSArray<T> _displayedObjects
          cache for the displayed objects
protected  java.lang.Boolean _isBatching
          cache batching flag
protected  com.webobjects.foundation.NSArray<java.lang.String> _prefetchingRelationshipKeyPaths
           
protected  int _rowCount
           
protected  boolean _shouldRememberRowCount
           
 
Fields inherited from class com.webobjects.appserver.WODisplayGroup
DisplayGroupWillFetchNotification
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding
_CLASS, NullValue
 
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding.ErrorHandling
_CLASS
 
Fields inherited from interface com.webobjects.foundation.NSDisposable
_CLASS
 
Fields inherited from interface com.webobjects.eocontrol.EOKeyValueArchiving
_CLASS
 
Fields inherited from interface com.webobjects.eocontrol.EOKeyValueArchiving.Awaking
_CLASS
 
Constructor Summary
ERXBatchingDisplayGroup()
          Creates a new ERXBatchingDisplayGroup.
 
Method Summary
 int batchCount()
          Overridden to return the pre-calculated number of batches
static java.lang.Object decodeWithKeyValueUnarchiver(com.webobjects.eocontrol.EOKeyValueUnarchiver unarchiver)
          Decodes an ERXBatchingDisplayGroup from the given unarchiver.
 com.webobjects.foundation.NSArray<T> displayedObjects()
          Overridden method in order to fetch -only- the rows that are needed.
 java.lang.Object fetch()
          Overridden to fetch only within displayed limits.
protected  com.webobjects.eocontrol.EOFetchSpecification fetchSpecification()
          Utility to get the fetch spec from the datasource and the filter qualifier.
 com.webobjects.foundation.NSArray<T> filteredObjects()
          Overridden to return allObjects() when batching, as we can't qualify in memory.
 boolean hasMultipleBatches()
          Overridden to refetchIfNecessary() first to ensure we get a correct result in cases where this is called before displayedObjects().
protected  boolean isBatching()
          Determines if batching is possible.
 boolean isRawRowsForCustomQueries()
          Returns whether or not fetch specification with custom queries should use raw rows.
protected  com.webobjects.foundation.NSArray<T> objectsInRange(int start, int end)
          Utility to fetch the object in a given range.
 com.webobjects.foundation.NSArray<java.lang.String> prefetchingRelationshipKeyPaths()
          Returns the prefetching key paths overriding those in the underlying fetch spec.
protected  void refetch()
          Utility that does the actual fetching, if a qualifier() is set, it adds it to the dataSource() fetch qualifier.
protected  void refetchIfNecessary()
          If we're batching and the displayed objects have not been fetched, do a refetch() of them.
 int rowCount()
          Utility to get at the number of rows when batching.
 java.lang.Object selectFilteredObjects()
          Selects the visible objects, overridden to fetch all objects.
 void setCurrentBatchIndex(int index)
          Overriden to clear out our array of fetched objects.
 void setDataSource(com.webobjects.eocontrol.EODataSource eodatasource)
          Overridden to set the isBatching flag to true if we have an EODatabaseDataSource.
 void setNumberOfObjectsPerBatch(int count)
          Overriden to clear out our array of fetched objects.
 void setObjectArray(com.webobjects.foundation.NSArray objects)
          Overridden to update the batch count.
 void setPrefetchingRelationshipKeyPaths(com.webobjects.foundation.NSArray<java.lang.String> prefetchingRelationshipKeyPaths)
          Sets the prefetching key paths to override those in the underlying fetch spec.
 void setQualifier(com.webobjects.eocontrol.EOQualifier aEoqualifier)
          Overridden to trigger a refetch.
 void setRawRowsForCustomQueries(boolean rawRowsForCustomQueries)
          Sets whether or not fetch specification with custom queries should use raw rows.
 void setRowCount(int rowCount)
          Override the number of rows of results (if you can provide a better estimate than the default behavior).
 void setShouldRememberRowCount(boolean shouldRememberRowCount)
          Set to true to retain the rowCount() after it is determined once for a particular qualifier.
 void setSortOrderings(com.webobjects.foundation.NSArray nsarray)
          Overridden to preserve the selected objects.
 boolean shouldRememberRowCount()
           
protected  void updateBatchCount()
           
 void updateDisplayedObjects()
           
 
Methods inherited from class er.extensions.appserver.ERXDisplayGroup
allObjects, allQualifierOperators, clearExtraQualifiers, displayNextBatch, displayPreviousBatch, indexOfFirstDisplayedObject, indexOfLastDisplayedObject, qualifierFromQueryValues, selectedObject, selectedObjects, setQualifierForKey, setSelectedObjects, setSelectionIndexes, sortedObjects, sortOrderings
 
Methods inherited from class com.webobjects.appserver.WODisplayGroup
_beginObserverNotification, _deleteObject, _insertObjectAtIndex, _lastObserverNotified, awakeFromKeyValueUnarchiver, clearSelection, currentBatchIndex, dataSource, defaultStringMatchFormat, defaultStringMatchOperator, delegate, delete, deleteObjectAtIndex, deleteSelection, detailKey, displayBatchContainingSelectedObject, dispose, editingContextPresentErrorMessage, encodeWithCoder, encodeWithKeyValueArchiver, endEditing, fetchesOnLoad, finishInitialization, globalDefaultForValidatesChangesImmediately, globalDefaultStringMatchFormat, globalDefaultStringMatchOperator, handleQueryWithUnboundKey, handleTakeValueForUnboundKey, hasDetailDataSource, initWithCoder, inQueryMode, insert, insertedObjectDefaultValues, insertNewObjectAtIndex, insertObjectAtIndex, localKeys, masterObject, numberOfObjectsPerBatch, objectsChangedInEditingContext, objectsInvalidatedInEditingContext, qualifier, qualifyDataSource, qualifyDisplayGroup, queryBindings, queryMatch, queryMax, queryMin, queryOperator, redisplay, relationalQualifierOperators, selectionIndexes, selectNext, selectObject, selectObjectsIdenticalTo, selectObjectsIdenticalToSelectFirstOnNoMatch, selectPrevious, selectsFirstObjectAfterFetch, setDefaultStringMatchFormat, setDefaultStringMatchOperator, setDelegate, setDetailKey, setFetchesOnLoad, setGlobalDefaultForValidatesChangesImmediately, setGlobalDefaultStringMatchFormat, setGlobalDefaultStringMatchOperator, setInQueryMode, setInsertedObjectDefaultValues, setLocalKeys, setMasterObject, setSelectedObject, setSelectsFirstObjectAfterFetch, setValidatesChangesImmediately, stringQualifierOperators, takeValueForKey, toString, unableToSetNullForKey, undoManager, validatesChangesImmediately, valueForKey, willChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_batchCount

protected int _batchCount
total number of batches


_displayedObjects

protected com.webobjects.foundation.NSArray<T> _displayedObjects
cache for the displayed objects


_isBatching

protected java.lang.Boolean _isBatching
cache batching flag


_prefetchingRelationshipKeyPaths

protected com.webobjects.foundation.NSArray<java.lang.String> _prefetchingRelationshipKeyPaths

_rowCount

protected int _rowCount

_shouldRememberRowCount

protected boolean _shouldRememberRowCount
Constructor Detail

ERXBatchingDisplayGroup

public ERXBatchingDisplayGroup()
Creates a new ERXBatchingDisplayGroup.

Method Detail

setRawRowsForCustomQueries

public void setRawRowsForCustomQueries(boolean rawRowsForCustomQueries)
Sets whether or not fetch specification with custom queries should use raw rows. Defaults to true for backwards compatibility.

Parameters:
rawRowsForCustomQueries - whether or not fetch specification with custom queries should use raw rows

isRawRowsForCustomQueries

public boolean isRawRowsForCustomQueries()
Returns whether or not fetch specification with custom queries should use raw rows.

Returns:
whether or not fetch specification with custom queries should use raw rows

decodeWithKeyValueUnarchiver

public static java.lang.Object decodeWithKeyValueUnarchiver(com.webobjects.eocontrol.EOKeyValueUnarchiver unarchiver)
Decodes an ERXBatchingDisplayGroup from the given unarchiver.

Parameters:
unarchiver - the unarchiver to construct this display group with
Returns:
the corresponding batching display group

refetchIfNecessary

protected void refetchIfNecessary()
If we're batching and the displayed objects have not been fetched, do a refetch() of them.


isBatching

protected boolean isBatching()
Determines if batching is possible.

Returns:
true if dataSource is an instance of EODatabaseDataSource

setDataSource

public void setDataSource(com.webobjects.eocontrol.EODataSource eodatasource)
Overridden to set the isBatching flag to true if we have an EODatabaseDataSource.

Overrides:
setDataSource in class ERXDisplayGroup<T>

batchCount

public int batchCount()
Overridden to return the pre-calculated number of batches

Overrides:
batchCount in class com.webobjects.appserver.WODisplayGroup

setCurrentBatchIndex

public void setCurrentBatchIndex(int index)
Overriden to clear out our array of fetched objects.

Overrides:
setCurrentBatchIndex in class com.webobjects.appserver.WODisplayGroup

setNumberOfObjectsPerBatch

public void setNumberOfObjectsPerBatch(int count)
Overriden to clear out our array of fetched objects.

Overrides:
setNumberOfObjectsPerBatch in class ERXDisplayGroup<T>

displayedObjects

public com.webobjects.foundation.NSArray<T> displayedObjects()
Overridden method in order to fetch -only- the rows that are needed. This is different to the editors methods because a WODisplayGroup would always fetch from the start until the end of the objects from the fetch limit.

Overrides:
displayedObjects in class ERXDisplayGroup<T>
Returns:
the objects that should be diplayed.

hasMultipleBatches

public boolean hasMultipleBatches()
Overridden to refetchIfNecessary() first to ensure we get a correct result in cases where this is called before displayedObjects(). See http://issues.objectstyle.org/jira/browse/WONDER-381

Overrides:
hasMultipleBatches in class com.webobjects.appserver.WODisplayGroup

filteredObjects

public com.webobjects.foundation.NSArray<T> filteredObjects()
Overridden to return allObjects() when batching, as we can't qualify in memory.

Overrides:
filteredObjects in class ERXDisplayGroup<T>

setQualifier

public void setQualifier(com.webobjects.eocontrol.EOQualifier aEoqualifier)
Overridden to trigger a refetch.

Overrides:
setQualifier in class com.webobjects.appserver.WODisplayGroup

setSortOrderings

public void setSortOrderings(com.webobjects.foundation.NSArray nsarray)
Overridden to preserve the selected objects.

Overrides:
setSortOrderings in class ERXDisplayGroup<T>

setPrefetchingRelationshipKeyPaths

public void setPrefetchingRelationshipKeyPaths(com.webobjects.foundation.NSArray<java.lang.String> prefetchingRelationshipKeyPaths)
Sets the prefetching key paths to override those in the underlying fetch spec.

Parameters:
prefetchingRelationshipKeyPaths - the prefetching key paths to override those in the underlying fetch spec

prefetchingRelationshipKeyPaths

public com.webobjects.foundation.NSArray<java.lang.String> prefetchingRelationshipKeyPaths()
Returns the prefetching key paths overriding those in the underlying fetch spec.

Returns:
the prefetching key paths overriding those in the underlying fetch spec

fetchSpecification

protected com.webobjects.eocontrol.EOFetchSpecification fetchSpecification()
Utility to get the fetch spec from the datasource and the filter qualifier.


rowCount

public int rowCount()
Utility to get at the number of rows when batching.


setRowCount

public void setRowCount(int rowCount)
Override the number of rows of results (if you can provide a better estimate than the default behavior). If you guess too low, you will never get more than what you set, but if you guess too high, it will adjust. Call with -1 to have the rows counted again.

Parameters:
rowCount - the number of rows of results

shouldRememberRowCount

public boolean shouldRememberRowCount()
Returns:
true if the rowCount() should be remembered after being determined or false if rowCount() should be re-calculated when the batch changes

setShouldRememberRowCount

public void setShouldRememberRowCount(boolean shouldRememberRowCount)
Set to true to retain the rowCount() after it is determined once for a particular qualifier. Set to false to have rowCount() re-calculated when the batch changes. The default is true.

Parameters:
shouldRememberRowCount - the shouldRememberRowCount to set

objectsInRange

protected com.webobjects.foundation.NSArray<T> objectsInRange(int start,
                                                              int end)
Utility to fetch the object in a given range.

Parameters:
start -
end -

refetch

protected void refetch()
Utility that does the actual fetching, if a qualifier() is set, it adds it to the dataSource() fetch qualifier.


updateBatchCount

protected void updateBatchCount()

setObjectArray

public void setObjectArray(com.webobjects.foundation.NSArray objects)
Overridden to update the batch count.

Overrides:
setObjectArray in class com.webobjects.appserver.WODisplayGroup

fetch

public java.lang.Object fetch()
Overridden to fetch only within displayed limits.

Overrides:
fetch in class ERXDisplayGroup<T>

updateDisplayedObjects

public void updateDisplayedObjects()
Overrides:
updateDisplayedObjects in class com.webobjects.appserver.WODisplayGroup

selectFilteredObjects

public java.lang.Object selectFilteredObjects()
Selects the visible objects, overridden to fetch all objects. Note that this makes sense only when there are only a "few" objects in the list.

Overrides:
selectFilteredObjects in class ERXDisplayGroup<T>

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.