Package org.eclnt.ccee.datacontext
Class DataContext<HOMEOBJECTCLASS,CONTENTTYPECLASS>
java.lang.Object
org.eclnt.ccee.datacontext.DataContext<HOMEOBJECTCLASS,CONTENTTYPECLASS>
- Direct Known Subclasses:
DataContextDOFW
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
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static interface
static interface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(DataContext.IListener<CONTENTTYPECLASS> listener) protected final void
addListObject
(CONTENTTYPECLASS contentType, int index, Object o) protected final void
addListObject
(CONTENTTYPECLASS contentType, Object o) protected boolean
boolean
protected final boolean
checkIfLoaded
(CONTENTTYPECLASS contentType) protected abstract boolean
Method to be implemented by extensions: the method must check in the database if the object is available.void
clear()
protected final void
clearList
(CONTENTTYPECLASS contentType) protected abstract void
This method is called for completely removing the whole object - with all its sub-object.protected abstract void
protected abstract void
This is the method for actually removing one object that is part of the data context.protected abstract void
This is the method for actually saving one object that is part of the data context.final void
delete()
protected void
protected abstract void
protected CONTENTTYPECLASS[]
protected DataContext<?,
?> getChildDataContext
(Object bean) Inner method to access the child context for a bean.protected Class
protected Object
protected final Object
getContent
(CONTENTTYPECLASS contentType, boolean readIfNotAvailable) Central method for accessing data - which is loaded if not yet available.DataContext<?,
?> <OBJTYPE extends DataContext<?,
?>>
OBJTYPEgetCreateChildDataContext
(Object bean, Class<OBJTYPE> dcClass) Gets or creates the child data context that is managed for a specific bean.final HOMEOBJECTCLASS
protected abstract CONTENTTYPECLASS
protected List<CONTENTTYPECLASS>
When saving then all objects that are loaded in the content are checked for updates and saved if required.protected Set<CONTENTTYPECLASS>
protected final Object
getObject
(CONTENTTYPECLASS contentType) Default read method: read content and load if not yet loaded.protected final Object
getObject
(CONTENTTYPECLASS contentType, boolean readIfNotAvailable) protected final List<?>
getObjects
(CONTENTTYPECLASS contentType) Returns a list of objects for the contentType.protected List<?>
getObjects
(CONTENTTYPECLASS contentType, boolean readIfNotAvailable, boolean originalList) DataContext<?,
?> 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.DataContext<?,
?> Returns top data context of data context hierarchy.boolean
isNew()
Information if objects it "new" (i.e. not available in database).protected void
protected void
protected void
protected abstract Object
readContent
(CONTENTTYPECLASS contentType) protected final void
registerHomeObject
(HOMEOBJECTCLASS homeObject, HOMEOBJECTCLASS readBeanHomeObject) 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.void
removeListener
(DataContext.IListener<CONTENTTYPECLASS> listener) protected final void
removeListObject
(CONTENTTYPECLASS contentType, Object o) save()
protected void
Actual persisting of objects - which is called during thesave()
method.protected void
Part of processing insaveLoadedObjects()
.protected final void
setObject
(CONTENTTYPECLASS contentType, Object o) Registers a new object in the content.protected final void
setObject
(CONTENTTYPECLASS contentType, Object o, boolean asNewObject) This is a special version ofsetObject(Object, Object)
which should only be used in special situations, e.g. in method#registerHomeObjectInContent(Object)
.protected <HOMEOBJECTCLASS>
voidupdateHomeObjectRegistrationByReadBean
(HOMEOBJECTCLASS readBean) protected void
writeChangeLog
(DataContextChangeLog changeLog)
-
Constructor Details
-
DataContext
-
-
Method Details
-
addListener
-
removeListener
-
clear
public void clear() -
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
-
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
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
Returns top data context of data context hierarchy. -
getHomeObject
-
getAllHomeObjectsCascadingUp
-
executeInTransaction
-
dbDeleteHomeObject
protected abstract void dbDeleteHomeObject() -
getClassForChildDataContext
-
readAllContent
protected void readAllContent() -
getAllContainedContentTypes
-
getChildDataContext
Inner method to access the child context for a bean. Returns null if there is no child data context available. - Use methodgetCreateChildDataContext(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
Registers a new object in the content. -
setObject
This is a special version ofsetObject(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
-
addListObject
-
removeListObject
-
clearList
-
checkIfLoaded
-
getLoadedContentTypes
-
getObject
Default read method: read content and load if not yet loaded. -
getObject
-
getObjects
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 thesave()
method. Extend this method in order to implement some own saving logic for all objects within the DataContext. -
saveLoadedObjects
Part of processing insaveLoadedObjects()
. Each object type is processed, this method executes the saving per object type. -
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
Central method for accessing data - which is loaded if not yet available. -
readContent
-
dbSaveObject
This is the method for actually saving one object that is part of the data context. Override this method following your persistence management. -
dbRemoveObject
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
-
checkIfContainedObjectIsNew
-
postProcessSetObject
protected void postProcessSetObject() -
postProcessAddListObject
protected void postProcessAddListObject() -
executeFunctionOnAllRegisteredObjects
-
writeChangeLog
-
getClonedReadObject
-