SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

com.solarmetric.kodo.runtime.datacache.query
Class QueryCacheImpl

java.lang.Object
  |
  +--com.solarmetric.kodo.runtime.datacache.query.QueryCacheImpl
All Implemented Interfaces:
ClassChangeListener, Configurable, QueryCache

public class QueryCacheImpl
extends Object
implements QueryCache, Configurable, ClassChangeListener


Constructor Summary
QueryCacheImpl()
           
 
Method Summary
 void classesChanged(Set classes)
          Invoked when objects of the types in the classes set have been changed.
 void clear()
          Remove all data from this cache.
 void close()
          Close this cache, dropping all hard references and releasing any resources that this cache maintains.
 void endConfiguration()
          Invoked upon completion of configuration of this object
 List get(QueryKey qk)
          Return a list of OIDs for the given query key.
 CacheMap getCacheMap()
          Returns the underlying CacheMap that this QueryCacheImpl is using.
 int getCacheSize()
          Returns the maximum number of unpinned objects to keep hard references to.
 com.solarmetric.util.Listener getExpirationListener()
          Returns this query cache's expiration listener.
protected  CacheMap newCacheMap()
          Returns a new CacheMap for use as the underlying data cache.
 void notifyChangedClasses(Set classes)
          Tells the cache that all the classes in the classes set have been changed.
 boolean pin(QueryKey qk)
          Pin the value stored under qk into the cache.
 List put(QueryKey qk, List oids)
          Set the list of OIDs for the given query key.
 void registerClassChangeListener(ClassChangeListener ccl)
          Register ccl with this cache.
 List remove(QueryKey qk)
          Remove the value stored under the given query key.
 void setCacheSize(int size)
          Sets the maximum number of unpinned objects to keep hard references to.
 void startConfiguration()
          Invoked before configuration is begun on this object
 boolean unpin(QueryKey qk)
          Unpin the value stored under key into the cache.
 void unregisterClassChangeListener(ClassChangeListener ccl)
          Unregister ccl from the set of listeners managed by this cache.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryCacheImpl

public QueryCacheImpl()
Method Detail

getCacheMap

public CacheMap getCacheMap()

Returns the underlying CacheMap that this QueryCacheImpl is using. This is not an unmodifiable view on the map, so care should be taken with this reference. Implementations should probably not mess with the contents of the cache, but should only use this reference to obtain cache metrics. Additionally, this map may contain expired data. Removal of timed-out data is done in a lazy fashion, so the actual size of the map may be greater than the number of non-expired query results in cache.

Methods that manipulate the cache map should synchronize on the map.


setCacheSize

public void setCacheSize(int size)
Sets the maximum number of unpinned objects to keep hard references to. If the map contains more unpinned objects than size, then this method will result in the cache flushing old values.

getCacheSize

public int getCacheSize()
Returns the maximum number of unpinned objects to keep hard references to.

newCacheMap

protected CacheMap newCacheMap()
Returns a new CacheMap for use as the underlying data cache. This implementation returns a CacheMap. To implement a more sophisticated caching strategy, override this method to return a subclass of CacheMap.

notifyChangedClasses

public void notifyChangedClasses(Set classes)
Description copied from interface: QueryCache

Tells the cache that all the classes in the classes set have been changed. This could mean that items have been updated, deleted, or added. This limits the QueryCache to only be able to invalidate cached queries -- because the cache is not notified of actual changes, it cannot recompute query results.

After this method is invoked, all cached results that correspond to queries that use one of the classes in classes will be dropped.

Specified by:
notifyChangedClasses in interface QueryCache
Following copied from interface: com.solarmetric.kodo.runtime.datacache.query.QueryCache
Parameters:
classes - a Set of Class objects that correspond to instances that have changed

registerClassChangeListener

public void registerClassChangeListener(ClassChangeListener ccl)
Description copied from interface: QueryCache
Register ccl with this cache.
Specified by:
registerClassChangeListener in interface QueryCache

unregisterClassChangeListener

public void unregisterClassChangeListener(ClassChangeListener ccl)
Description copied from interface: QueryCache
Unregister ccl from the set of listeners managed by this cache.
Specified by:
unregisterClassChangeListener in interface QueryCache

classesChanged

public void classesChanged(Set classes)
Description copied from interface: ClassChangeListener

Invoked when objects of the types in the classes set have been changed. This could mean that items have been updated, deleted, or added.

Specified by:
classesChanged in interface ClassChangeListener
Following copied from interface: com.solarmetric.kodo.runtime.datacache.query.ClassChangeListener
Parameters:
classes - a Set of Class objects that correspond to instances that have changed

get

public List get(QueryKey qk)
Description copied from interface: QueryCache

Return a list of OIDs for the given query key. This is an unmodifiable list.

Specified by:
get in interface QueryCache
Following copied from interface: com.solarmetric.kodo.runtime.datacache.query.QueryCache
Returns:
the query results matching the given key, or null if none.

put

public List put(QueryKey qk,
                List oids)
Description copied from interface: QueryCache

Set the list of OIDs for the given query key. A reference to the given list will be stored in the query cache, so the list should not be modified after invoking this method.

Specified by:
put in interface QueryCache
Following copied from interface: com.solarmetric.kodo.runtime.datacache.query.QueryCache
Returns:
The previously cached value, or null if the key was not previously cached. See Map.put(java.lang.Object, java.lang.Object) for more information.

remove

public List remove(QueryKey qk)
Description copied from interface: QueryCache

Remove the value stored under the given query key.

This method is typically not invoked directly from outside the QueryCache class. Instead, the cache should be updated by invoking #notifyChanges, which will result in all queries that may be invalid being dropped.

Specified by:
remove in interface QueryCache
Following copied from interface: com.solarmetric.kodo.runtime.datacache.query.QueryCache
Returns:
The previously cached value, or null if the key was not previously cached. See Map.remove(java.lang.Object) for more information.

clear

public void clear()
Description copied from interface: QueryCache

Remove all data from this cache.

Specified by:
clear in interface QueryCache

pin

public boolean pin(QueryKey qk)
Description copied from interface: QueryCache
Pin the value stored under qk into the cache. This method guarantees that qk's value will not be expired if the cache exceeds its capacity. It causes this data to be ignored when determining whether or not the cache is full, effectively increasing the total amount of data stored in the cache. This method does not affect the behavior of QueryCache.remove(com.solarmetric.kodo.runtime.datacache.query.QueryKey) or #notifyChanges.
Specified by:
pin in interface QueryCache
Following copied from interface: com.solarmetric.kodo.runtime.datacache.query.QueryCache
Returns:
true if key's value was pinned into the cache; false if the key is not in the cache.

unpin

public boolean unpin(QueryKey qk)
Description copied from interface: QueryCache
Unpin the value stored under key into the cache. This method reverses a previous invocation of QueryCache.pin(com.solarmetric.kodo.runtime.datacache.query.QueryKey). This method does not remove anything from the cache; it merely makes key's value a candidate for flushing from the cache.
Specified by:
unpin in interface QueryCache
Following copied from interface: com.solarmetric.kodo.runtime.datacache.query.QueryCache
Returns:
true if key's value was unpinned from the cache; false if the key is not in the cache.

close

public void close()
Description copied from interface: QueryCache
Close this cache, dropping all hard references and releasing any resources that this cache maintains.
Specified by:
close in interface QueryCache

getExpirationListener

public com.solarmetric.util.Listener getExpirationListener()
Description copied from interface: QueryCache
Returns this query cache's expiration listener.
Specified by:
getExpirationListener in interface QueryCache

startConfiguration

public void startConfiguration()
Description copied from interface: Configurable
Invoked before configuration is begun on this object
Specified by:
startConfiguration in interface Configurable

endConfiguration

public void endConfiguration()
Description copied from interface: Configurable
Invoked upon completion of configuration of this object
Specified by:
endConfiguration in interface Configurable

SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.