systemic.sif.sbpframework.persist.dao
Class DOCacheDAO

java.lang.Object
  extended by systemic.sif.sbpframework.persist.dao.BaseDAO
      extended by systemic.sif.sbpframework.persist.dao.DOCacheDAO

public class DOCacheDAO
extends BaseDAO

Author:
Joerg Huber

Constructor Summary
DOCacheDAO()
           
 
Method Summary
 java.util.Set<DOCObject> getAlreadyCachedDependentObjects(java.lang.String sifObjectName, java.lang.String flatKey, java.lang.String applicationId, java.lang.String zoneId)
          This method returns a list of dependent objects that have already been cached for a given SIF Object.
 DOCObject getCachedDependentObject(DOCObject objectToTest)
          This method checks if the 'objectToTest' has already been cached for a requested.
 java.util.List<DOCache> getExpiredObjects(java.lang.String applicationId, java.lang.String agentId)
          This method returns all objects in the cache that have remaining dependencies but have an expiry date older than the current date and time.
 java.util.List<DOCObject> getNotYetRequestedObjects(java.lang.String sifObjectName, java.lang.String applicationId, java.lang.String zoneId)
          This method returns a list of DOC Objects.
 java.util.List<DOCache> getObjectsWithoutDependencies(java.lang.String sifObjectName, java.lang.String applicationId, java.lang.String agentId)
          This method gets all cached objects of a given type for a particular application and agent that have no remaining dependencies.
 void removeCachedObject(DOCache cacheObject)
          This method removes the given object and all its dependencies from the cache.
 void removeDependency(DOCObject docObject)
          This method removes the docObject from the DO cache.
 void removeDependentObject(DOCObject docObject)
          This method removes the given cached dependent object.
 DOCObject retrieve(DOCObject docObject)
           
 DOCache retrieveCachedObject(java.lang.String sifObjectName, java.lang.String flatKey, java.lang.String applicationId, java.lang.String zoneId, boolean loadAll)
          This method attempts to retrieve a cached SIF Object based on the object name, object key (flatten key) and the agentId.
 void save(DOCache cacheObject)
          This method saves the given object to the DB.
 void save(DOCObject docObject)
          This method saves the given object to the DB.
 
Methods inherited from class systemic.sif.sbpframework.persist.dao.BaseDAO
getCurrentSession, loadSubObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOCacheDAO

public DOCacheDAO()
Method Detail

retrieveCachedObject

public DOCache retrieveCachedObject(java.lang.String sifObjectName,
                                    java.lang.String flatKey,
                                    java.lang.String applicationId,
                                    java.lang.String zoneId,
                                    boolean loadAll)
                             throws java.lang.IllegalArgumentException,
                                    javax.persistence.PersistenceException
This method attempts to retrieve a cached SIF Object based on the object name, object key (flatten key) and the agentId. Since each object can only be provided from one zone the zoneID is irrelevant and is not required to determine if an object is already cached. If the object isn't cached then null is returned.

Parameters:
sifObjectName - the name of the SIF Object for which the cached object info shall be returned.
flatKey - A flattened key of the cached object that makes this object unique.
applicationId - The application ID for which the cached object shall be returned.
zoneId - The zone ID for which the cached object shall be returned.
loadAll - TRUE=>Load all children elements (lazy loading forced). FALSE no children objects are loaded.
Returns:
The DOCahce object if it exists in the cache already, null if it does not exist.
Throws:
IllegalArgumentException: - Any of the arguments is null.
PersistenceException: - There is an issue with the underlying database. An error is logged.
java.lang.IllegalArgumentException
javax.persistence.PersistenceException

save

public void save(DOCache cacheObject)
          throws java.lang.IllegalArgumentException,
                 javax.persistence.PersistenceException
This method saves the given object to the DB. all sub-elements are saved as well. After the save the cacheObject will have a new ID if it is a new object.

Parameters:
cacheObject - The object to save to the cache.
Throws:
java.lang.IllegalArgumentException - cacheObject parameter is null.
javax.persistence.PersistenceException - A database error occurred.

save

public void save(DOCObject docObject)
          throws java.lang.IllegalArgumentException,
                 javax.persistence.PersistenceException
This method saves the given object to the DB. all sub-elements are saved as well. After the save the cacheObject will have a new ID if it is a new object.

Parameters:
docObject - The object to save to the cache.
Throws:
java.lang.IllegalArgumentException - cacheObject parameter is null.
javax.persistence.PersistenceException - A database error occurred.

getCachedDependentObject

public DOCObject getCachedDependentObject(DOCObject objectToTest)
                                   throws java.lang.IllegalArgumentException,
                                          javax.persistence.PersistenceException
This method checks if the 'objectToTest' has already been cached for a requested. If so the object is returned so that it can be re-used in another's cached object dependent list. If the object has not yet been cached then null is returned. The 'objectToTest' must hold the following properties for this method to succeed: - sifObjectName - applicationId - objectKeyValue - zoneId If one of the above property is empty or null then a IllegalArgumentException is raised.

Parameters:
objectToTest - The object to find in the DOC.
Returns:
See description.
Throws:
java.lang.IllegalArgumentException - objectToTest is null or any of the properties listed above is empty or null.
javax.persistence.PersistenceException - A database error occurred.

getAlreadyCachedDependentObjects

public java.util.Set<DOCObject> getAlreadyCachedDependentObjects(java.lang.String sifObjectName,
                                                                 java.lang.String flatKey,
                                                                 java.lang.String applicationId,
                                                                 java.lang.String zoneId)
                                                          throws java.lang.IllegalArgumentException,
                                                                 javax.persistence.PersistenceException
This method returns a list of dependent objects that have already been cached for a given SIF Object. If there are no dependent objects that already been cached then an empty list is returned. If the object defined by its parameters is not cached at all then null is returned and an info message is logged.

Parameters:
sifObjectName - The object name for which the dependent object list with already cached objects shall be returned.
flatKey - The key of the above object.
applicationId - The application Id for which the object is registered in the cache.
zoneId - The zone Id for which the object is registered in the cache.
Returns:
See description
Throws:
IllegalArgumentException: - Any of the arguments is null.
PersistenceException: - There is an issue with the underlying database. An error is logged.
java.lang.IllegalArgumentException
javax.persistence.PersistenceException

removeDependency

public void removeDependency(DOCObject docObject)
                      throws java.lang.IllegalArgumentException,
                             javax.persistence.PersistenceException
This method removes the docObject from the DO cache. Since there can be many objects in the DO Cache that depend on the given object all these need to be updated accordingly. For this method to work, the following properties in the docObject must be set: - sifObjectName - applicationId - objectKeyValue - zoneId If the object is not cached as a dependent object then no action is taken.

Parameters:
docObject - The object for which the dependencies shall be returned.
Throws:
java.lang.IllegalArgumentException - docObject is null or any of the properties listed above is empty or null.
javax.persistence.PersistenceException - A database error occurred.

getNotYetRequestedObjects

public java.util.List<DOCObject> getNotYetRequestedObjects(java.lang.String sifObjectName,
                                                           java.lang.String applicationId,
                                                           java.lang.String zoneId)
                                                    throws java.lang.IllegalArgumentException,
                                                           javax.persistence.PersistenceException
This method returns a list of DOC Objects. The objects are those that have not been requested, yet (requested=false). Note: If an agent subscribes to more than one zone for the same sifObject then this method must be called separately for each zone by the agent. If there are no cached and not yet requested objects for the given parameters then an empty list is returned.

Parameters:
sifObjectName - The SIF Object names to search for (i.e StudentPersonal)
applicationId - Only return objects marked for this application.
zoneId - Only return objects marked for this zone.
Returns:
See description
Throws:
java.lang.IllegalArgumentException - Any of the parameters is null or empty.
javax.persistence.PersistenceException - A database error occurred.

getObjectsWithoutDependencies

public java.util.List<DOCache> getObjectsWithoutDependencies(java.lang.String sifObjectName,
                                                             java.lang.String applicationId,
                                                             java.lang.String agentId)
                                                      throws java.lang.IllegalArgumentException,
                                                             javax.persistence.PersistenceException
This method gets all cached objects of a given type for a particular application and agent that have no remaining dependencies. These are the candidates do be removed later and be processed by the appropriate subscriber. If there are no Cached Objects without dependencies then an empty list is returned.

Parameters:
sifObjectName - The type of cached objects to be returned.
applicationId - The application for which the objects shall be returned.
agentId - The agent for which to get the object list.
Returns:
See description.
Throws:
java.lang.IllegalArgumentException - Any of the parameters is null or empty.
javax.persistence.PersistenceException - A database error occurred. Error is logged.

getExpiredObjects

public java.util.List<DOCache> getExpiredObjects(java.lang.String applicationId,
                                                 java.lang.String agentId)
                                          throws java.lang.IllegalArgumentException,
                                                 javax.persistence.PersistenceException
This method returns all objects in the cache that have remaining dependencies but have an expiry date older than the current date and time. These are the candidates that need to either be removed or re-requested by the agent. If there are no expired objects then an empty list is returned.

Parameters:
applicationId - Only return expired objects for this application.
agentId - Only return expired object that were initially cached by this agent.
Returns:
See description.
Throws:
java.lang.IllegalArgumentException - Any of the parameters is null or empty.
javax.persistence.PersistenceException - A database error occurred. Error is logged.

removeDependentObject

public void removeDependentObject(DOCObject docObject)
                           throws javax.persistence.PersistenceException
This method removes the given cached dependent object. If the object is null then no action is taken. The object's id property must be set for this method to work.

Parameters:
docObject - The object to remove from the DOC_OBJECT table.
Throws:
javax.persistence.PersistenceException - A database error occurred.

removeCachedObject

public void removeCachedObject(DOCache cacheObject)
                        throws javax.persistence.PersistenceException
This method removes the given object and all its dependencies from the cache. If the object is null then no action is taken.

Parameters:
cacheObject - The object to remove from the DO Cache.
Throws:
javax.persistence.PersistenceException - A database error occurred.

retrieve

public DOCObject retrieve(DOCObject docObject)
                   throws java.lang.IllegalArgumentException,
                          javax.persistence.PersistenceException
Throws:
java.lang.IllegalArgumentException
javax.persistence.PersistenceException