org.apache.torque.manager
Class AbstractBaseManager<T extends Persistent>

java.lang.Object
  extended by org.apache.torque.manager.AbstractBaseManager<T>
Type Parameters:
T - the class of the database object managed by this class.
All Implemented Interfaces:
Serializable

public abstract class AbstractBaseManager<T extends Persistent>
extends Object
implements Serializable

This class contains common functionality of a Manager for instantiating OM's.

Version:
$Id: AbstractBaseManager.java 1379317 2012-08-31 06:56:48Z tfischer $
Author:
John McNally
See Also:
Serialized Form

Field Summary
protected  org.apache.jcs.access.GroupCacheAccess cache
          used to cache the om objects.
protected  Map<String,org.apache.commons.collections.FastArrayList> listenersMap
          The listeners for this manager.
protected static org.apache.commons.logging.Log log
          the log
protected  MethodResultCache mrCache
          method results cache
protected  Map<String,?> validFields
          The fields which are valid fields of interest for a listener.
 
Constructor Summary
AbstractBaseManager()
           
 
Method Summary
 void addCacheListenerImpl(CacheListener<? extends Persistent> listener)
           
protected  T cacheGet(Serializable key)
          Get an object from cache
protected  void clearImpl()
          Clears the cache
 void dispose()
          Disposes of the cache.
 String getClassName()
          Get the classname to instantiate for getInstance()
 MethodResultCache getMethodResultCache()
           
protected  Class<T> getOMClass()
          Get the Class instance
protected  T getOMInstance()
          Get a fresh instance of an om
protected  T getOMInstance(ObjectKey id)
          Return an instance of an om based on the id
protected  T getOMInstance(ObjectKey key, boolean fromCache)
          Return an instance of an om based on the id
protected  List<T> getOMs(List<? extends ObjectKey> ids)
          Gets a list of om's based on id's.
protected  List<T> getOMs(List<? extends ObjectKey> ids, boolean fromCache)
          Gets a list of om's based on id's.
protected  List<T> getOMs(ObjectKey[] ids)
          Gets a list of om's based on id's.
 String getRegion()
          Get the cache region used for JCS.
protected
<TT extends Persistent>
void
notifyListeners(List<WeakReference<CacheListener<TT>>> listeners, TT oldOm, TT om)
           
protected  T putInstanceImpl(Serializable key, T om)
          Put an object into the cache
protected  T putInstanceImpl(T om)
          Put an object into the cache
protected  void registerAsListener()
          NoOp version.
protected  T removeInstanceImpl(Serializable key)
          Remove an object from the cache
protected abstract  T retrieveStoredOM(ObjectKey id)
          Retrieve an object from persistent storage
protected abstract  List<T> retrieveStoredOMs(List<? extends ObjectKey> ids)
          Gets a list of om's based on id's.
 void setClassName(String v)
          Set the classname to instantiate for getInstance()
protected  void setOMClass(Class<T> omClass)
          Set the Class that will be instantiated by this manager
 void setRegion(String v)
          Set the cache region used for JCS.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
the log


cache

protected transient org.apache.jcs.access.GroupCacheAccess cache
used to cache the om objects. cache is set by the region property


mrCache

protected MethodResultCache mrCache
method results cache


validFields

protected Map<String,?> validFields
The fields which are valid fields of interest for a listener.


listenersMap

protected Map<String,org.apache.commons.collections.FastArrayList> listenersMap
The listeners for this manager.

Constructor Detail

AbstractBaseManager

public AbstractBaseManager()
Method Detail

getOMClass

protected Class<T> getOMClass()
Get the Class instance

Returns:
the om class

setOMClass

protected void setOMClass(Class<T> omClass)
Set the Class that will be instantiated by this manager

Parameters:
omClass - the om class

getOMInstance

protected T getOMInstance()
                                      throws TorqueException
Get a fresh instance of an om

Returns:
an instance of the om class
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getClassName

public String getClassName()
Get the classname to instantiate for getInstance()

Returns:
value of className.

setClassName

public void setClassName(String v)
                  throws TorqueException
Set the classname to instantiate for getInstance()

Parameters:
v - Value to assign to className.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getOMInstance

protected T getOMInstance(ObjectKey id)
                                      throws TorqueException
Return an instance of an om based on the id

Parameters:
id - the primary key of the object
Returns:
the object from persistent storage or from cache
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getOMInstance

protected T getOMInstance(ObjectKey key,
                          boolean fromCache)
                                      throws TorqueException
Return an instance of an om based on the id

Parameters:
key - the primary key of the object
fromCache - true if the object should be retrieved from cache
Returns:
the object from persistent storage or from cache
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

cacheGet

protected T cacheGet(Serializable key)
Get an object from cache

Parameters:
key - the primary key of the object
Returns:
the object from cache

clearImpl

protected void clearImpl()
                  throws TorqueException
Clears the cache

Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

dispose

public void dispose()
Disposes of the cache. This triggers a shutdown of the connected cache instances. This method should only be used during shutdown of Torque. The manager instance will not cache anymore after this call.


removeInstanceImpl

protected T removeInstanceImpl(Serializable key)
                                           throws TorqueException
Remove an object from the cache

Parameters:
key - the cache key for the object
Returns:
the object one last time
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

putInstanceImpl

protected T putInstanceImpl(T om)
                                        throws TorqueException
Put an object into the cache

Parameters:
om - the object
Returns:
if an object with the same key already is in the cache this object will be returned, else null
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

putInstanceImpl

protected T putInstanceImpl(Serializable key,
                            T om)
                                        throws TorqueException
Put an object into the cache

Parameters:
key - the cache key for the object
om - the object
Returns:
if an object with this key already is in the cache this object will be returned, else null
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

retrieveStoredOM

protected abstract T retrieveStoredOM(ObjectKey id)
                                                  throws TorqueException
Retrieve an object from persistent storage

Parameters:
id - the primary key of the object
Returns:
the object
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getOMs

protected List<T> getOMs(ObjectKey[] ids)
                                     throws TorqueException
Gets a list of om's based on id's.

Parameters:
ids - a ObjectKey[] value
Returns:
a List value
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getOMs

protected List<T> getOMs(List<? extends ObjectKey> ids)
                                     throws TorqueException
Gets a list of om's based on id's.

Parameters:
ids - a List of ObjectKey's
Returns:
a List value
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getOMs

protected List<T> getOMs(List<? extends ObjectKey> ids,
                         boolean fromCache)
                                     throws TorqueException
Gets a list of om's based on id's.

Parameters:
ids - a List of ObjectKey's
Returns:
a List value
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

retrieveStoredOMs

protected abstract List<T> retrieveStoredOMs(List<? extends ObjectKey> ids)
                                                         throws TorqueException
Gets a list of om's based on id's. This method must be implemented in the derived class

Parameters:
ids - a List of ObjectKey's
Returns:
a List value
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getRegion

public String getRegion()
Get the cache region used for JCS.

Returns:
the cache region used for JCS.

setRegion

public void setRegion(String v)
               throws TorqueException
Set the cache region used for JCS.

Parameters:
v - Value to assign to region.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getMethodResultCache

public MethodResultCache getMethodResultCache()
Returns:
The cache instance.

registerAsListener

protected void registerAsListener()
NoOp version. Managers should override this method to notify other managers that they are interested in CacheEvents.


addCacheListenerImpl

public void addCacheListenerImpl(CacheListener<? extends Persistent> listener)
Parameters:
listener - A new listener for cache events.

notifyListeners

protected <TT extends Persistent> void notifyListeners(List<WeakReference<CacheListener<TT>>> listeners,
                                                       TT oldOm,
                                                       TT om)
Parameters:
listeners -
oldOm -
om -


Copyright © 2000-2013 The Apache Software Foundation. All Rights Reserved.