Project Wonder 5.0

er.extensions.eof
Class ERXEnterpriseObjectArrayCache<T extends com.webobjects.eocontrol.EOEnterpriseObject>

java.lang.Object
  extended by er.extensions.eof.ERXEnterpriseObjectArrayCache<T>
Direct Known Subclasses:
ERCEnterpriseObjectArrayCache

public class ERXEnterpriseObjectArrayCache<T extends com.webobjects.eocontrol.EOEnterpriseObject>
extends java.lang.Object

Caches objects of one entity by a given key. Listens to EOEditingContextDidSaveChanges notifications to track changes. Typically you'd fetch values by:

 ERXEnterpriseObjectArrayCache<HelpText> helpTextCache = new ERXEnterpriseObjectArrayCache<HelpText>("HelpText") {
    protected void handleUnsuccessfullQueryForKey(Object key) {
       NSArray helpTexts = ... fetch from somewhere
       setObjectsForKey(helpTexts, key);
   }
 };
 ...
 NSArray<HelpText> helpTexts = helpTextCache.objectsForKey(ec, "AllTexts");
 ...
 
You can supply a timeout after which the cache is to get cleared and all the objects refetched. Note that this implementation only caches the global IDs, not the actual data.

Author:
ak

Nested Class Summary
static class ERXEnterpriseObjectArrayCache.NotFoundArray
           
 
Field Summary
protected static com.webobjects.foundation.NSArray NOT_FOUND_MARKER
           
 
Constructor Summary
ERXEnterpriseObjectArrayCache(java.lang.Class c)
          Creates the cache for the given entity name and the given keypath.
ERXEnterpriseObjectArrayCache(java.lang.String entityName)
          Creates the cache for the given entity name and the given keypath.
ERXEnterpriseObjectArrayCache(java.lang.String entityName, long timeout)
          Creates the cache for the given entity, keypath and timeout value in milliseconds.
 
Method Summary
protected  com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOGlobalID> cachedArrayForKey(java.lang.Object key)
           
 void clearCaches(com.webobjects.foundation.NSNotification n)
          Handler for the clearCaches notification.
 void editingContextDidSaveChanges(com.webobjects.foundation.NSNotification n)
          Handler for the editingContextDidSaveChanges notification.
protected  java.lang.String entityName()
           
protected static java.lang.String entityNameForClass(java.lang.Class c)
           
protected  long fetchTime()
           
protected  void handleUnsuccessfullQueryForKey(java.lang.Object key)
          Called when a query hasn't found an entry in the cache.
protected  boolean isNotFound(com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOGlobalID> gids)
           
 com.webobjects.foundation.NSArray<T> objectsForKey(com.webobjects.eocontrol.EOEditingContext ec, java.lang.Object key)
          Retrieves a list of EOs that matches the given key or null if no match is in the cache.
protected  void registerForNotifications()
           
 void reset()
          Resets the cache by clearing the internal map.
protected  void setCachedArrayForKey(com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOGlobalID> gids, java.lang.Object key)
           
 void setObjectsForKey(com.webobjects.foundation.NSArray<? extends com.webobjects.eocontrol.EOEnterpriseObject> bugs, java.lang.Object key)
          Add a list of objects to the cache with the given key.
protected  long timeout()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOT_FOUND_MARKER

protected static final com.webobjects.foundation.NSArray NOT_FOUND_MARKER
Constructor Detail

ERXEnterpriseObjectArrayCache

public ERXEnterpriseObjectArrayCache(java.lang.String entityName)
Creates the cache for the given entity name and the given keypath. No timeout value is used.

Parameters:
entityName -

ERXEnterpriseObjectArrayCache

public ERXEnterpriseObjectArrayCache(java.lang.Class c)
Creates the cache for the given entity name and the given keypath. No timeout value is used.


ERXEnterpriseObjectArrayCache

public ERXEnterpriseObjectArrayCache(java.lang.String entityName,
                                     long timeout)
Creates the cache for the given entity, keypath and timeout value in milliseconds.

Parameters:
entityName -
timeout -
Method Detail

entityNameForClass

protected static java.lang.String entityNameForClass(java.lang.Class c)

registerForNotifications

protected void registerForNotifications()

editingContextDidSaveChanges

public void editingContextDidSaveChanges(com.webobjects.foundation.NSNotification n)
Handler for the editingContextDidSaveChanges notification. Calls reset if and object of the given entity were changed.

Parameters:
n -

clearCaches

public void clearCaches(com.webobjects.foundation.NSNotification n)
Handler for the clearCaches notification. Calls reset if n.object is the entity name.

Parameters:
n -

entityName

protected java.lang.String entityName()

setObjectsForKey

public void setObjectsForKey(com.webobjects.foundation.NSArray<? extends com.webobjects.eocontrol.EOEnterpriseObject> bugs,
                             java.lang.Object key)
Add a list of objects to the cache with the given key. The object can be null.

Parameters:
bugs - array of objects

setCachedArrayForKey

protected void setCachedArrayForKey(com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOGlobalID> gids,
                                    java.lang.Object key)

cachedArrayForKey

protected com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOGlobalID> cachedArrayForKey(java.lang.Object key)

objectsForKey

public com.webobjects.foundation.NSArray<T> objectsForKey(com.webobjects.eocontrol.EOEditingContext ec,
                                                          java.lang.Object key)
Retrieves a list of EOs that matches the given key or null if no match is in the cache.

Parameters:
ec - editing context to get the objects into
key - key value under which the objects are registered

isNotFound

protected boolean isNotFound(com.webobjects.foundation.NSArray<com.webobjects.eocontrol.EOGlobalID> gids)

handleUnsuccessfullQueryForKey

protected void handleUnsuccessfullQueryForKey(java.lang.Object key)
Called when a query hasn't found an entry in the cache. This implementation puts a not-found marker in the cache so the next query will return null. You could override this method to create an EO with sensible default values and call setObjectsForKey(NSArray, Object) on it.

Parameters:
key -

reset

public void reset()
Resets the cache by clearing the internal map. When the next value is accessed, the objects are refetched.


timeout

protected long timeout()

fetchTime

protected long fetchTime()

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

Copyright © 2002 – 2007 Project Wonder.