ojb.broker.cache
Class MetaObjectCacheImpl

java.lang.Object
  |
  +--ojb.broker.cache.MetaObjectCacheImpl
All Implemented Interfaces:
ObjectCache

public class MetaObjectCacheImpl
extends java.lang.Object
implements ObjectCache

This cache makes it possible to have separate cache implementations for each class. When an object is cached / looked up the MetaObjectCacheImpl checks if a special ObjectCache has been set for this class. It recursively looks up the superclasses of the given object to look for a special cache. If no special cache is found it uses the ObjectCacheDefaultImpl to cache the object.
It is also possible to switch off caching for a specific class by setting the object cache to null.

Author:
rzj7l2

Constructor Summary
MetaObjectCacheImpl()
          Constructor for the MetaObjectCacheImpl object
 
Method Summary
 void cache(Identity oid, java.lang.Object obj)
          Caches the given object using the given Identity as key
 void cache(java.lang.Object obj)
          Caches the given Object
 void clear()
          Clears the cache
 java.lang.Object lookup(Identity oid)
          Looks up the object from the cache
 void remove(java.lang.Object obj)
          Removes the given object from the cache
protected  void removeByOID(Identity oid)
          Removes the object identified by the given Identity from the cache
 void setClassCache(java.lang.Class objectClass, ObjectCache cache)
          Sets the ObjectCache implementation to use for objects with the given type and subclasses
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetaObjectCacheImpl

public MetaObjectCacheImpl()
Constructor for the MetaObjectCacheImpl object

Method Detail

setClassCache

public void setClassCache(java.lang.Class objectClass,
                          ObjectCache cache)
Sets the ObjectCache implementation to use for objects with the given type and subclasses

Parameters:
objectClass - The object's class, use java.lang.Object to alter default caching for all objects which have no special caching defined
cache - The new ObjectCache implementation to use for this class and subclasses, null to switch off caching for the given class

cache

public void cache(java.lang.Object obj)
Caches the given Object

Specified by:
cache in interface ObjectCache
Parameters:
obj - The object to cache

cache

public void cache(Identity oid,
                  java.lang.Object obj)
Caches the given object using the given Identity as key

Specified by:
cache in interface ObjectCache
Parameters:
oid - The Identity key
obj - The object o cache

lookup

public java.lang.Object lookup(Identity oid)
Looks up the object from the cache

Specified by:
lookup in interface ObjectCache
Parameters:
oid - The Identity to look up the object for
Returns:
The object if found, otherwise null

removeByOID

protected void removeByOID(Identity oid)
Removes the object identified by the given Identity from the cache

Parameters:
oid - The identity of the object to remove

remove

public void remove(java.lang.Object obj)
Removes the given object from the cache

Specified by:
remove in interface ObjectCache
Parameters:
obj - The object to remove

clear

public void clear()
Clears the cache

Specified by:
clear in interface ObjectCache


Authors: Thomas Mahler and others. (C) 2000, 2001.
All rights reserved. Published under the Gnu Public License.
http://objectbridge.sourceforge.net
Version: 0.8.375, 2002-04-04