|
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.ERXEnterpriseObjectCache<T>
T
- the type of EOEnterpriseObject in this cachepublic class ERXEnterpriseObjectCache<T extends com.webobjects.eocontrol.EOEnterpriseObject>
Caches instances of one entity by a given key(path). Typically you'd have an "identifier" property
and you'd fetch values by:
You can supply a timeout after which individual objects (or all objects if fetchInitialValues
is
ERXEnterpriseObjectCache<HelpText> helpTextCache = new ERXEnterpriseObjectCache<HelpText>("HelpText", "pageConfiguration");
...
HelpText helpText = helpTextCache.objectForKey(ec, "ListHelpText");
true
) get cleared and re-fetched. This implementation can cache either only the global IDs,
or the global ID and a copy of the actual object. Caching the actual object ensures that the snapshot stays around
and thus prevent additional trips to the database.
Listens to EOEditingContextDidSaveChanges notifications to track changes to objects in the cache and ClearCachesNotification
for messages to purge the cache.
Field Summary | |
---|---|
static java.lang.String |
ClearCachesNotification
Other code can send this notification if it needs to have this cache discard all of the objects that it has. |
protected static com.webobjects.eocontrol.EOGlobalID |
NO_GID_MARKER
|
Constructor Summary | |
---|---|
ERXEnterpriseObjectCache(java.lang.Class c,
java.lang.String keyPath)
Creates the cache for the entity implemented by the passed class and the given keypath. |
|
ERXEnterpriseObjectCache(java.lang.String entityName,
java.lang.String keyPath)
Creates the cache for the given entity name and the given keypath. |
|
ERXEnterpriseObjectCache(java.lang.String entityName,
java.lang.String keyPath,
com.webobjects.eocontrol.EOQualifier qualifier,
long timeout)
Creates the cache for the given entity, keypath and timeout value in milliseconds. |
|
ERXEnterpriseObjectCache(java.lang.String entityName,
java.lang.String keyPath,
com.webobjects.eocontrol.EOQualifier qualifier,
long timeout,
boolean shouldRetainObjects,
boolean shouldFetchInitialValues)
Creates the cache for the given entity, keypath and timeout value in milliseconds. |
|
ERXEnterpriseObjectCache(java.lang.String entityName,
java.lang.String keyPath,
com.webobjects.eocontrol.EOQualifier qualifier,
long timeout,
boolean shouldRetainObjects,
boolean shouldFetchInitialValues,
boolean shouldReturnUnsavedObjects)
Creates the cache for the given entity, keypath and timeout value in milliseconds. |
|
ERXEnterpriseObjectCache(java.lang.String entityName,
java.lang.String keyPath,
long timeout)
Creates the cache for the given entity, keypath and timeout value in milliseconds. |
Method Summary | |
---|---|
void |
addObject(T eo)
Add an object to the cache using eo.valueForKeyPath(keyPath()) as the key. |
void |
addObjectForKey(T eo,
java.lang.Object key)
Add an object to the cache with the given key if it matches the qualifier, or if there is no qualifier. |
com.webobjects.foundation.NSArray<T> |
allObjects(com.webobjects.eocontrol.EOEditingContext ec)
Returns a list of all the objects currently in the cache and not yet expired. |
com.webobjects.foundation.NSArray<T> |
allObjects(com.webobjects.eocontrol.EOEditingContext ec,
com.webobjects.eocontrol.EOQualifier additionalQualifier)
Returns a list of all the objects currently in the cache and not yet expired which match additionalQualifier. |
protected ERXExpiringCache<java.lang.Object,er.extensions.eof.ERXEnterpriseObjectCache.EORecord<T>> |
cache()
Returns the backing cache. |
void |
clearCaches(com.webobjects.foundation.NSNotification n)
Handler for the clearCaches notification. |
protected er.extensions.eof.ERXEnterpriseObjectCache.EORecord<T> |
createRecord(com.webobjects.eocontrol.EOGlobalID gid,
T eo)
Created an EORecord instance representing eo using its EOGlobalID. |
protected ERXEC |
editingContext()
Returns the editing context that holds object that are in this cache. |
void |
editingContextDidSaveChanges(com.webobjects.foundation.NSNotification n)
Handler for the editingContextDidSaveChanges notification. |
protected java.lang.String |
entityName()
|
protected com.webobjects.foundation.NSArray<T> |
fetchObjectsForKey(com.webobjects.eocontrol.EOEditingContext editingContext,
java.lang.Object key)
Actually performs a fetch for the given key. |
protected com.webobjects.eocontrol.EOQualifier |
fetchObjectsQualifier(java.lang.Object key)
Returns the qualifier to use during for fetching: the value for keyPath matches key AND qualifier() (if not null). |
protected void |
handleUnsuccessfullQueryForKey(java.lang.Object key)
Called when a query hasn't found an entry in the cache. |
protected java.lang.String |
keyPath()
|
T |
objectForKey(com.webobjects.eocontrol.EOEditingContext ec,
java.lang.Object key)
Retrieves an EO that matches the given key. |
T |
objectForKey(com.webobjects.eocontrol.EOEditingContext ec,
java.lang.Object key,
boolean handleUnsuccessfulQueryForKey)
Retrieves an EO that matches the given key. |
protected void |
preLoadCacheIfNeeded()
Loads all relevant objects into the cache if set to fetch initial values. |
com.webobjects.eocontrol.EOQualifier |
qualifier()
Returns the additional qualifier for this cache. |
void |
removeObject(T eo)
Removes an object from the cache using eo.valueForKeyPath(keyPath()) as the key. |
void |
removeObjectForKey(T eo,
java.lang.Object key)
Removes the object associated with key from the cache. |
void |
reset()
Resets the cache by clearing the internal map. |
void |
setFetchInitialValues(boolean fetchInitialValues)
Sets whether or not the initial values should be fetched into this cache or whether it should lazy load. |
void |
setResetOnChange(boolean resetOnChange)
Sets whether or not the cache is cleared when any change occurs. |
void |
setRetainObjects(boolean retainObjects)
Sets whether or not the cached EO's themselves are retained versus just their GID's. |
void |
setReuseEditingContext(boolean reuseEditingContext)
Sets whether or not the editing context for this cache is reused for multiple requests. |
void |
start()
Call this to re-start cache updating after stop() is called. |
void |
stop()
Call this to stop cache updating. |
T |
unsavedMatchingObject(com.webobjects.eocontrol.EOEditingContext ec,
java.lang.Object key)
Looks in ec for an newly inserted (unsaved) EO that matches the given key. |
void |
updateObject(T eo)
Updates an object in the cache (adding if not present) using eo.valueForKeyPath(keyPath()) as the key. |
void |
updateObjectForKey(T eo,
java.lang.Object key)
Updates an object in the cache (adding if not present) with the given key if it matches the qualifier, or if there is no qualifier. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.lang.String ClearCachesNotification
protected static final com.webobjects.eocontrol.EOGlobalID NO_GID_MARKER
Constructor Detail |
---|
public ERXEnterpriseObjectCache(java.lang.String entityName, java.lang.String keyPath)
entityName
- name of the EOEntity to cachekeyPath
- key path to data uniquely identifying an instance of this entitypublic ERXEnterpriseObjectCache(java.lang.Class c, java.lang.String keyPath)
c
- Class used to identify which EOEntity this cache is forkeyPath
- key path to data uniquely identifying an instance of this entitypublic ERXEnterpriseObjectCache(java.lang.String entityName, java.lang.String keyPath, long timeout)
entityName
- name of the EOEntity to cachekeyPath
- key path to data uniquely identifying an instance of this entitytimeout
- time to live in milliseconds for an object in this cachepublic ERXEnterpriseObjectCache(java.lang.String entityName, java.lang.String keyPath, com.webobjects.eocontrol.EOQualifier qualifier, long timeout)
true
after this constructor. You will almost certainly want to call
setResetOnChange(false);
.
entityName
- name of the EOEntity to cachekeyPath
- key path to data uniquely identifying an instance of this entityqualifier
- EOQualifier restricting which instances are stored in this cachetimeout
- time to live in milliseconds for an object in this cachesetResetOnChange(boolean)
,
setFetchInitialValues(boolean)
public ERXEnterpriseObjectCache(java.lang.String entityName, java.lang.String keyPath, com.webobjects.eocontrol.EOQualifier qualifier, long timeout, boolean shouldRetainObjects, boolean shouldFetchInitialValues)
entityName
- name of the EOEntity to cachekeyPath
- key path to data uniquely identifying an instance of this entityqualifier
- EOQualifier restricting which instances are stored in this cachetimeout
- time to live in milliseconds for an object in this cacheshouldRetainObjects
- true if this cache should retain the cached objects, false to keep only the GIDshouldFetchInitialValues
- true if the cache should be fully populated on first accesssetResetOnChange(boolean)
,
setFetchInitialValues(boolean)
,
setRetainObjects(boolean)
public ERXEnterpriseObjectCache(java.lang.String entityName, java.lang.String keyPath, com.webobjects.eocontrol.EOQualifier qualifier, long timeout, boolean shouldRetainObjects, boolean shouldFetchInitialValues, boolean shouldReturnUnsavedObjects)
entityName
- name of the EOEntity to cachekeyPath
- key path to data uniquely identifying an instance of this entityqualifier
- EOQualifier restricting which instances are stored in this cachetimeout
- time to live in milliseconds for an object in this cacheshouldRetainObjects
- true if this cache should retain the cached objects, false to keep only the GIDshouldFetchInitialValues
- true if the cache should be fully populated on first accessshouldReturnUnsavedObjects
- true if unsaved matching objects should be returned, see unsavedMatchingObject(EOEditingContext, Object)
setResetOnChange(boolean)
,
setFetchInitialValues(boolean)
,
setRetainObjects(boolean)
Method Detail |
---|
public void start()
stop()
public void stop()
start()
protected ERXEC editingContext()
public void editingContextDidSaveChanges(com.webobjects.foundation.NSNotification n)
_resetOnChange
is true
, this
calls reset() to discard the entire cache contents if an object of the given entity has been changed.
If _resetOnChange
is false
, this updates the cache to reflect the added/changed/removed
objects.
n
- NSNotification with EOEditingContext as the object and a dictionary of changes in the userInfoEOEditingContext.ObjectsChangedInEditingContextNotification
,
reset()
public void clearCaches(com.webobjects.foundation.NSNotification n)
n
- protected java.lang.String entityName()
protected java.lang.String keyPath()
protected ERXExpiringCache<java.lang.Object,er.extensions.eof.ERXEnterpriseObjectCache.EORecord<T>> cache()
_fetchInitialValues
.
protected er.extensions.eof.ERXEnterpriseObjectCache.EORecord<T> createRecord(com.webobjects.eocontrol.EOGlobalID gid, T eo)
_retainObjects
,
this will also include an instance of the EO to ensure that the snapshot is retained.
gid
- EOGlobalID of eoeo
- the EO to make an EORecord for
protected void preLoadCacheIfNeeded()
public void addObject(T eo)
eo.valueForKeyPath(keyPath())
as the key.
eo
- the object to add to the cacheaddObjectForKey(EOEnterpriseObject, Object)
public void addObjectForKey(T eo, java.lang.Object key)
eo
- eo the object to add to the cachekey
- the key to add the object underpublic void removeObject(T eo)
eo.valueForKeyPath(keyPath())
as the key.
eo
- the object to remove from the cacheremoveObjectForKey(EOEnterpriseObject, Object)
public void removeObjectForKey(T eo, java.lang.Object key)
eo
- eo the object to remove from the cache (ignored)key
- the key to remove the object forpublic void updateObject(T eo)
eo.valueForKeyPath(keyPath())
as the key.
eo
- the object to update in the cacheupdateObjectForKey(EOEnterpriseObject, Object)
public void updateObjectForKey(T eo, java.lang.Object key)
qualifier()
is not null, the object
is removed from the cache if it does not match the qualifier.
eo
- eo the object to update in the cachekey
- the key of the object to updatepublic T objectForKey(com.webobjects.eocontrol.EOEditingContext ec, java.lang.Object key)
ec
- editing context to get the object intokey
- key value under which the object is registered
public T objectForKey(com.webobjects.eocontrol.EOEditingContext ec, java.lang.Object key, boolean handleUnsuccessfulQueryForKey)
_returnUnsavedObjects
is true
,
it attempts to find and return an unsaved object. If there is still no match
and handleUnsuccessfulQueryForKey
is true
,
it attempts to fetch the missing objects. Null is returned if
handleUnsuccessfulQueryForKey
is false
or no matching
object can be fetched.
ec
- editing context to get the object intokey
- key value under which the object is registeredhandleUnsuccessfulQueryForKey
- if false, a cache miss returns null rather than fetching
public T unsavedMatchingObject(com.webobjects.eocontrol.EOEditingContext ec, java.lang.Object key)
ec
- editing context to search for unsaved, matching objectskey
- key value to identify the unsaved object
public com.webobjects.foundation.NSArray<T> allObjects(com.webobjects.eocontrol.EOEditingContext ec)
ec
- editing context to get the objects into
public com.webobjects.foundation.NSArray<T> allObjects(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOQualifier additionalQualifier)
ec
- editing context to get the objects intoadditionalQualifier
- qualifier to restrict which objects are returned from the cache
protected void handleUnsuccessfullQueryForKey(java.lang.Object key)
_fetchInitialValues
is false
, it will attempt to fetch the missing object and
adds it to the cache if it is found.
call addObject(EOEnterpriseObject)
on it.
key
- the key of the object that was not found in the cacheprotected com.webobjects.foundation.NSArray<T> fetchObjectsForKey(com.webobjects.eocontrol.EOEditingContext editingContext, java.lang.Object key)
editingContext
- the editing context to fetch inkey
- the key to fetch with
public com.webobjects.eocontrol.EOQualifier qualifier()
protected com.webobjects.eocontrol.EOQualifier fetchObjectsQualifier(java.lang.Object key)
key
- the key to fetch
public void reset()
_fetchInitialValues
is true
, otherwise they are re-loaded on demand.
preLoadCacheIfNeeded()
public void setFetchInitialValues(boolean fetchInitialValues)
fetchInitialValues
- if true, the initial values are fetched into the cachepublic void setReuseEditingContext(boolean reuseEditingContext)
reuseEditingContext
- whether or not the editing context for this cache is reused for multiple requestspublic void setRetainObjects(boolean retainObjects)
retainObjects
- if true, the EO's are retainedpublic void setResetOnChange(boolean resetOnChange)
resetOnChange
- if true, the cache will clear on changes; if false, the cache will update on changes
|
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 |