org.apache.ojb.broker.cache
Class CacheDistributor

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

 class CacheDistributor
extends Object
implements ObjectCacheInternal

A intern used AbstractMetaCache implementation acting as distributor of ObjectCache implementations declared in configuration metadata.

Reads the name of the used ObjectCache implementation
a) from class-descriptor, or if not found
b) from jdbc-connection-descriptor, or if not found
use a given standard ObjectCache implementation (given by constructor argument).

Version:
$Id: CacheDistributor.java,v 1.1 2007-08-24 22:17:29 ewestfal Exp $
Author:
Matthew Baird (mattbaird@yahoo.com), Armin Waibel

Nested Class Summary
(package private) static class CacheDistributor.ObjectCacheInternalWrapper
          Wrapper class used to make existing ObjectCache implementations work with ObjectCacheInternal.
 
Field Summary
private  PersistenceBroker broker
           
static String CACHE_EXCLUDES_STRING
           
private  Map caches
          map, represents used cache implementations
private static String DELIMITER_FOR_EXCLUDE
           
private static String DESCRIPTOR_BASED_CACHES
           
private  boolean descriptorBasedCaches
          If true the class name of the object is used to find a per class ObjectCache implementation.
private static ObjectCacheInternal DUMMY_CACHE
           
private  List excludedPackages
           
private static Logger log
           
 
Fields inherited from interface org.apache.ojb.broker.cache.ObjectCacheInternal
TYPE_CACHED_READ, TYPE_NEW_MATERIALIZED, TYPE_TEMP, TYPE_UNKNOWN, TYPE_WRITE
 
Constructor Summary
CacheDistributor(PersistenceBroker broker)
          public Default Constructor
 
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.
private  List createExcludedPackagesList(String theList)
           
 void doInternalCache(Identity oid, Object obj, int type)
          For internal use.
 ObjectCacheInternal getCache(Class targetClass)
           
private  boolean isExcluded(Class targetClass)
           
 Object lookup(Identity oid)
          Lookup object with Identity 'oid' in cache.
private  ObjectCacheInternal lookupCache(Object key)
           
private  ObjectCacheInternal prepareAndAddCache(Object key, ObjectCacheDescriptor ocd)
           
 void remove(Identity oid)
          Removes an Object from the cache.
protected  ObjectCacheDescriptor searchInClassDescriptor(Class targetClass)
          Try to lookup ObjectCacheDescriptor in ClassDescriptor.
protected  ObjectCacheDescriptor searchInJdbcConnectionDescriptor()
          Lookup ObjectCacheDescriptor in JdbcConnectionDescriptor.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static Logger log

DESCRIPTOR_BASED_CACHES

private static final String DESCRIPTOR_BASED_CACHES
See Also:
Constant Field Values

CACHE_EXCLUDES_STRING

public static final String CACHE_EXCLUDES_STRING
See Also:
Constant Field Values

DELIMITER_FOR_EXCLUDE

private static final String DELIMITER_FOR_EXCLUDE
See Also:
Constant Field Values

DUMMY_CACHE

private static final ObjectCacheInternal DUMMY_CACHE

caches

private Map caches
map, represents used cache implementations


excludedPackages

private List excludedPackages

broker

private final PersistenceBroker broker

descriptorBasedCaches

private boolean descriptorBasedCaches
If true the class name of the object is used to find a per class ObjectCache implementation. If set false the ObjectCacheDescriptor instance is used as key to find a per class ObjectCache.

Constructor Detail

CacheDistributor

public CacheDistributor(PersistenceBroker broker)
public Default Constructor

Method Detail

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.

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.

clear

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

Specified by:
clear in interface ObjectCache

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

getCache

public ObjectCacheInternal getCache(Class targetClass)

prepareAndAddCache

private ObjectCacheInternal prepareAndAddCache(Object key,
                                               ObjectCacheDescriptor ocd)

lookupCache

private ObjectCacheInternal lookupCache(Object key)

createExcludedPackagesList

private List createExcludedPackagesList(String theList)

isExcluded

private boolean isExcluded(Class targetClass)

searchInClassDescriptor

protected ObjectCacheDescriptor searchInClassDescriptor(Class targetClass)
Try to lookup ObjectCacheDescriptor in ClassDescriptor.

Parameters:
targetClass -
Returns:
Returns the found ObjectCacheDescriptor or null if none was found.

searchInJdbcConnectionDescriptor

protected ObjectCacheDescriptor searchInJdbcConnectionDescriptor()
Lookup ObjectCacheDescriptor in JdbcConnectionDescriptor.

Returns:
Returns the found ObjectCacheDescriptor or null if none was found.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2007-2011 The Kuali Foundation. All Rights Reserved.