org.apache.ojb.broker.cache
Class MaterializationCache

java.lang.Object
  extended by org.apache.ojb.broker.cache.MaterializationCache
All Implemented Interfaces:
ObjectCache, ObjectCacheInternal

public class MaterializationCache
extends Object
implements ObjectCacheInternal

A wrapper class for ObjectCache implementations used to materialize object graphs and push the fully materialized object to the real object cache. To avoid passing of partial materialized objects to cache this class act as a temporary storage for unmaterialized (new read or refreshed) objects.

Version:
$Id: MaterializationCache.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
Author:
Armin Waibel

Field Summary
 
Fields inherited from interface org.apache.ojb.broker.cache.ObjectCacheInternal
TYPE_CACHED_READ, TYPE_NEW_MATERIALIZED, TYPE_TEMP, TYPE_UNKNOWN, TYPE_WRITE
 
Method Summary
 void cache(Identity oid, Object obj)
          Used to cache objects by it's Identity.
 boolean cacheIfNew(Identity oid, Object obj)
          For internal use within ObjectCache implementations or to build two-level caches.
 void clear()
          Clear the cache.
 void disableMaterializationCache()
           
 void doInternalCache(Identity oid, Object obj, int type)
          For internal use.
 void doLocalClear()
          Clears the internal used cache for object materialization.
 Object doLocalLookup(Identity oid)
           
 void doLocalRemove(Identity oid)
           
 void enableMaterializationCache()
          For internal use only! Helper method to guarantee that only full materialized objects will be pushed to the application cache regardless if an local PB transaction is running or not.
 boolean isEnabledMaterialisationCache()
          Returns true if the materialisation cache is enabled, otherwise false.
 Object lookup(Identity oid)
          Lookup object with Identity 'oid' in cache.
 void remove(Identity oid)
          Removes an Object from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEnabledMaterialisationCache

public boolean isEnabledMaterialisationCache()
Returns true if the materialisation cache is enabled, otherwise false.


enableMaterializationCache

public void enableMaterializationCache()
For internal use only! Helper method to guarantee that only full materialized objects will be pushed to the application cache regardless if an local PB transaction is running or not. When a complex object is materialized there will be nested calls to the same PB instance methods, e.g. materialization of a referenced object which itself have several references, ...
This method and disableMaterializationCache() are used to delimit nested calls and to detect the end of an object materialization and avoid endless loops on circular references.
If an code block with 'enabledMaterializationCache' throws an exception, in catch-block method doLocalClear() have to be called.


disableMaterializationCache

public void disableMaterializationCache()
See Also:
enableMaterializationCache()

doInternalCache

public void doInternalCache(Identity oid,
                            Object obj,
                            int type)
Description copied from interface: ObjectCacheInternal
For internal use. This method have to be used by all OJB classes to cache objects. It allows to decide if an object should be cached or not. Useful for two level caches to reduce object copy costs.

Specified by:
doInternalCache in interface ObjectCacheInternal

cache

public void cache(Identity oid,
                  Object obj)
Description copied from interface: ObjectCache
Used to cache objects by it's Identity.

Specified by:
cache in interface ObjectCache
Parameters:
oid - Identity of the object to cache.
obj - The object to cache.

cacheIfNew

public boolean cacheIfNew(Identity oid,
                          Object obj)
Description copied from interface: ObjectCacheInternal
For internal use within ObjectCache implementations or to build two-level caches. Handle with care.

Used to cache new objects (not already cached) by it's Identity. This method was used to cache new materialized objects and should work as a "atomic" method (the check and the put of the object should be atomic) to avoid concurrency problems.

Currently it's not mandatory that all ObjectCache implementations support this method, so in some cases it's allowed to delegate this method call to the standard cache.

Specified by:
cacheIfNew in interface ObjectCacheInternal
Parameters:
oid - Identity of the object to cache.
obj - The object to cache.
Returns:
If object was added true, else false.
See Also:
ObjectCacheInternal.cacheIfNew(org.apache.ojb.broker.Identity, Object)

lookup

public Object lookup(Identity oid)
Description copied from interface: ObjectCache
Lookup object with Identity 'oid' in cache.

Specified by:
lookup in interface ObjectCache
Parameters:
oid - Identity of the object to search for.
Returns:
The cached object or null if no matching object for specified Identity is found.

doLocalLookup

public Object doLocalLookup(Identity oid)

remove

public void remove(Identity oid)
Description copied from interface: ObjectCache
Removes an Object from the cache.

Specified by:
remove in interface ObjectCache
Parameters:
oid - Identity of the object to be removed.

doLocalRemove

public void doLocalRemove(Identity oid)

doLocalClear

public void doLocalClear()
Clears the internal used cache for object materialization.


clear

public void clear()
Description copied from interface: ObjectCache
Clear the cache.

Specified by:
clear in interface ObjectCache


Copyright © 2004-2012 The Kuali Foundation. All Rights Reserved.