Package org.apache.torque.manager
Class AbstractBaseManager<T extends Persistent>
java.lang.Object
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 1917245 2024-04-21 14:06:23Z tv $
- Author:
- John McNally
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionused to cache the om objects. cache is set by the region propertyprotected org.apache.commons.jcs3.access.GroupCacheAccess<MethodCacheKey, Object> used to cache the method result objects. cache is set by the region propertyprotected static final org.apache.logging.log4j.Loggerthe logprotected MethodResultCachemethod results cache -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCacheListenerImpl(CacheListener<?> listener) Add a new listenerprotected voidaddValidField(Column... columns) Add variable number of fields to the list potentially monitored by a listenerprotected TGet an object from cacheprotected voidClears the cachevoiddispose()Disposes of the manager.Get the classname to instantiate for getInstance()Get the object usable for result cachingGet the Class instanceprotected TGet a fresh instance of an omprotected TgetOMInstance(ObjectKey<?> id) Return an instance of an om based on the idprotected TgetOMInstance(ObjectKey<?> key, boolean fromCache) Return an instance of an om based on the idGets a list of om's based on id's.Gets a list of om's based on id's.Gets a list of om's based on id's.Get the cache region used for JCS.protected <TT extends Persistent>
voidnotifyListeners(Column column, TT oldOm, TT om) Notify all listeners associated to the column that an object has changedprotected TputInstanceImpl(ObjectKey<?> key, T om) Put an object into the cacheprotected TputInstanceImpl(T om) Put an object into the cacheprotected voidNoOp version.protected TremoveInstanceImpl(ObjectKey<?> key) Remove an object from the cacheprotected abstract TretrieveStoredOM(ObjectKey<?> id) Retrieve an object from persistent storageretrieveStoredOMs(List<? extends ObjectKey<?>> ids) Gets a list of om's based on id's.voidSet the classname to instantiate for getInstance()protected voidsetOMClass(Class<T> omClass) Set the Class that will be instantiated by this managervoidSet the cache region used for JCS.
-
Field Details
-
log
protected static final org.apache.logging.log4j.Logger logthe log -
cache
protected transient org.apache.commons.jcs3.access.CacheAccess<ObjectKey<?>,T extends Persistent> cacheused to cache the om objects. cache is set by the region property -
groupCache
protected transient org.apache.commons.jcs3.access.GroupCacheAccess<MethodCacheKey,Object> groupCacheused to cache the method result objects. cache is set by the region property -
mrCache
method results cache
-
-
Constructor Details
-
AbstractBaseManager
public AbstractBaseManager()
-
-
Method Details
-
getOMClass
Get the Class instance- Returns:
- the om class
-
setOMClass
Set the Class that will be instantiated by this manager- Parameters:
omClass- the om class
-
addValidField
Add variable number of fields to the list potentially monitored by a listener- Parameters:
columns- array of columns
-
getOMInstance
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
Get the classname to instantiate for getInstance()- Returns:
- value of className.
-
setClassName
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
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
Return an instance of an om based on the id- Parameters:
key- the primary key of the objectfromCache- 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
Get an object from cache- Parameters:
key- the primary key of the object- Returns:
- the object from cache
-
clearImpl
Clears the cache- Throws:
TorqueException- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
dispose
public void dispose()Disposes of the manager. 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
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
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
Put an object into the cache- Parameters:
key- the cache key for the objectom- 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
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
Gets a list of om's based on id's.- Parameters:
ids- a number of object ids- Returns:
- a
Listof objects - Throws:
TorqueException- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
getOMs
Gets a list of om's based on id's.- Parameters:
ids- aListofObjectKey's- Returns:
- a
Listvalue - 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- aListofObjectKey's.fromCache- boolean flag if we are to use the cache- Returns:
- a
Listvalue, not null. - 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- aListofObjectKey's- Returns:
- a
Listvalue - Throws:
TorqueException- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
getRegion
Get the cache region used for JCS.- Returns:
- the cache region used for JCS.
-
setRegion
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
Get the object usable for result caching- 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
Add a new listener- Parameters:
listener- A new listener for cache events.
-
notifyListeners
Notify all listeners associated to the column that an object has changed- Type Parameters:
TT- column type class- Parameters:
column- the column related to the listenersoldOm- the previous object, null if the object has been addedom- the new object, null if the object has been removed
-