Class DataContext<HOMEOBJECTCLASS,CONTENTTYPECLASS>

java.lang.Object
org.eclnt.ccee.datacontext.DataContext<HOMEOBJECTCLASS,CONTENTTYPECLASS>
Direct Known Subclasses:
DataContextDOFW

public abstract class DataContext<HOMEOBJECTCLASS,CONTENTTYPECLASS> extends Object
Management of objects that belong to a dedicated processing context and which need to be processed as unique instances throughout a certain processing.

The data context is managing objects - either single objects or list of objects - in a map. The idea behind is that data that is changed is loaded from persistence and the managed in the data map, so that everyone changing/accessing the data accesses this data through the data context (and not by reading it in parallel).

The data context registers the changes to its contained data - and saves all changes data when calling the save() method.
  • Constructor Details

  • Method Details

    • addListener

      public void addListener(DataContext.IListener<CONTENTTYPECLASS> listener)
    • removeListener

      public void removeListener(DataContext.IListener<CONTENTTYPECLASS> listener)
    • clear

      public void clear()
    • save

      public DataContextChangeLog save()
    • delete

      public final void delete()
    • checkIfContentWasChanged

      public boolean checkIfContentWasChanged()
    • isNew

      public boolean isNew()
      Information if objects it "new" (i.e. not available in database). In case of saving the status of a "new" object will change from true to false.
    • getCreateChildDataContext

      public DataContext<?,?> getCreateChildDataContext(Object bean)
    • getCreateChildDataContext

      public <OBJTYPE extends DataContext<?, ?>> OBJTYPE getCreateChildDataContext(Object bean, Class<OBJTYPE> dcClass)
      Gets or creates the child data context that is managed for a specific bean.
    • getParentDataContext

      public DataContext<?,?> getParentDataContext()
      If the data context is part of another data context, then this method returns the owning parent data context. - Otherwise the result returned is null.
    • getRootDataContext

      public DataContext<?,?> getRootDataContext()
      Returns top data context of data context hierarchy.
    • getHomeObject

      public final HOMEOBJECTCLASS getHomeObject()
    • getAllHomeObjectsCascadingUp

      public List getAllHomeObjectsCascadingUp()
    • executeInTransaction

      protected abstract void executeInTransaction(Runnable r)
    • dbDeleteHomeObject

      protected abstract void dbDeleteHomeObject()
    • getClassForChildDataContext

      protected Class getClassForChildDataContext(Object bean)
    • readAllContent

      protected void readAllContent()
    • getAllContainedContentTypes

      protected CONTENTTYPECLASS[] getAllContainedContentTypes()
    • getChildDataContext

      protected DataContext<?,?> getChildDataContext(Object bean)
      Inner method to access the child context for a bean. Returns null if there is no child data context available. - Use method getCreateChildDataContext(Object, Class) to implicitly create a child data context if not available.
    • updateHomeObjectRegistrationByReadBean

      protected <HOMEOBJECTCLASS> void updateHomeObjectRegistrationByReadBean(HOMEOBJECTCLASS readBean)
    • registerHomeObject

      protected final void registerHomeObject(HOMEOBJECTCLASS homeObject, HOMEOBJECTCLASS readBeanHomeObject)
    • registerHomeObjectInContent

      protected final void registerHomeObjectInContent(HOMEOBJECTCLASS homeObject, HOMEOBJECTCLASS readBeanHomeObject)
      A home object is either registered as new or as existing object - dependent from the fact if it as already available in the database.
    • checkIfObjectExistsInDB

      protected abstract boolean checkIfObjectExistsInDB()
      Method to be implemented by extensions: the method must check in the database if the object is available. Dependent on the result the data context will treat the home object as new object or as already existing object.
    • setObject

      protected final void setObject(CONTENTTYPECLASS contentType, Object o)
      Registers a new object in the content.
    • setObject

      protected final void setObject(CONTENTTYPECLASS contentType, Object o, boolean asNewObject)
      This is a special version of setObject(Object, Object) which should only be used in special situations, e.g. in method #registerHomeObjectInContent(Object).
      Parameters:
      asNewObject - By default is set to be set to true - the object that is set is a new object and needs to be registered accordingly. In some situations, e.g. when registering an existing home object you need to set this parameter to false.
    • addListObject

      protected final void addListObject(CONTENTTYPECLASS contentType, Object o)
    • addListObject

      protected final void addListObject(CONTENTTYPECLASS contentType, int index, Object o)
    • removeListObject

      protected final void removeListObject(CONTENTTYPECLASS contentType, Object o)
    • clearList

      protected final void clearList(CONTENTTYPECLASS contentType)
    • checkIfLoaded

      protected final boolean checkIfLoaded(CONTENTTYPECLASS contentType)
    • getLoadedContentTypes

      protected Set<CONTENTTYPECLASS> getLoadedContentTypes()
    • getObject

      protected final Object getObject(CONTENTTYPECLASS contentType)
      Default read method: read content and load if not yet loaded.
    • getObject

      protected final Object getObject(CONTENTTYPECLASS contentType, boolean readIfNotAvailable)
    • getObjects

      protected final List<?> getObjects(CONTENTTYPECLASS contentType)
      Returns a list of objects for the contentType. The list is not the original list! Any update operation has to be done through corresponding methods, e.g. addListObject, removeListObject.
    • getObjects

      protected List<?> getObjects(CONTENTTYPECLASS contentType, boolean readIfNotAvailable, boolean originalList)
      Parameters:
      originalList - If true then the original list with objects is returned - otherwise a copied list so that adding/removing items from the list by the application is not affecting the original list.
    • saveLoadedObjects

      protected void saveLoadedObjects()
      Actual persisting of objects - which is called during the save() method. Extend this method in order to implement some own saving logic for all objects within the DataContext.
    • saveLoadedObjects

      protected void saveLoadedObjects(CONTENTTYPECLASS key)
      Part of processing in saveLoadedObjects(). Each object type is processed, this method executes the saving per object type.
    • getKeySequenceForUpdate

      protected List<CONTENTTYPECLASS> getKeySequenceForUpdate()
      When saving then all objects that are loaded in the content are checked for updates and saved if required. Here the sequence of object types in the content is defined. By default the home object is first! Reason: sometimes the key of the home object is populated at point of time of saving (e.g. keys which are auto-incremented by the database. In this case the home object must be saved first and then they key might be drilled down to all other elements.
    • getContent

      protected final Object getContent(CONTENTTYPECLASS contentType, boolean readIfNotAvailable)
      Central method for accessing data - which is loaded if not yet available.
    • readContent

      protected abstract Object readContent(CONTENTTYPECLASS contentType)
    • dbSaveObject

      protected abstract void dbSaveObject(Object o)
      This is the method for actually saving one object that is part of the data context. Override this method following your persistence management.
    • dbRemoveObject

      protected abstract void dbRemoveObject(Object o)
      This is the method for actually removing one object that is part of the data context. Override this method following your persistence management.
    • dbDeleteAll

      protected abstract void dbDeleteAll()
      This method is called for completely removing the whole object - with all its sub-object. It MUST be implemented! The data context only manages these beans that are loaded in its content, so a deletion "bean by bean by bean" is not possible (without previously loading all objects...).
    • getHomeObjectContentType

      protected abstract CONTENTTYPECLASS getHomeObjectContentType()
    • checkIfContainedObjectIsNew

      protected boolean checkIfContainedObjectIsNew(Object o)
    • postProcessSetObject

      protected void postProcessSetObject()
    • postProcessAddListObject

      protected void postProcessAddListObject()
    • executeFunctionOnAllRegisteredObjects

      protected void executeFunctionOnAllRegisteredObjects(DataContext.IExecuteOnObject exoo)
    • writeChangeLog

      protected void writeChangeLog(DataContextChangeLog changeLog)
    • getClonedReadObject

      protected Object getClonedReadObject(Object o)