Class AbstractBaseManager<T extends Persistent>

  • 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 1870542 2019-11-28 09:32:40Z tv $
    Author:
    John McNally
    See Also:
    Serialized Form
    • Field Detail

      • log

        protected static final org.apache.logging.log4j.Logger log
        the log
      • cache

        protected transient org.apache.commons.jcs.access.CacheAccess<ObjectKey<?>,​T extends Persistent> cache
        used to cache the om objects. cache is set by the region property
      • groupCache

        protected transient org.apache.commons.jcs.access.GroupCacheAccess<MethodCacheKey,​Object> groupCache
        used to cache the method result objects. cache is set by the region property
    • 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
      • addValidField

        protected void addValidField​(Column... columns)
        Add variable number of fields to the list potentially monitored by a listener
        Parameters:
        columns - array of columns
      • 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​(ObjectKey<?> 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 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

        protected T removeInstanceImpl​(ObjectKey<?> 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​(ObjectKey<?> 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 number of object ids
        Returns:
        a List of objects
        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.
        fromCache - boolean flag if we are to use the cache
        Returns:
        a List value, 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 - 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()
        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

        public void addCacheListenerImpl​(CacheListener<?> listener)
        Add a new listener
        Parameters:
        listener - A new listener for cache events.
      • notifyListeners

        protected <TT extends Persistent> void notifyListeners​(Column column,
                                                               TT oldOm,
                                                               TT om)
        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 listeners
        oldOm - the previous object, null if the object has been added
        om - the new object, null if the object has been removed