fri.util.database.jpa.tree.closuretable
Class TemporalClosureTableTreeDao

java.lang.Object
  extended by fri.util.database.jpa.tree.AbstractTreeDao<ClosureTableTreeNode>
      extended by fri.util.database.jpa.tree.closuretable.ClosureTableTreeDao
          extended by fri.util.database.jpa.tree.closuretable.TemporalClosureTableTreeDao
All Implemented Interfaces:
TemporalTreeDao<ClosureTableTreeNode>, TreeDao<ClosureTableTreeNode>

public class TemporalClosureTableTreeDao
extends ClosureTableTreeDao
implements TemporalTreeDao<ClosureTableTreeNode>

DAO extension that allows to historicize entities instead of deleting them.

Following methods must be overridden for another historization-mechanism than the default validFrom and validTo properties:

Author:
Fritz Ritzberger, 02.11.2012

Nested Class Summary
 
Nested classes/interfaces inherited from interface fri.util.database.jpa.tree.TreeDao
TreeDao.CopiedNodeRenamer<N extends TreeNode>
 
Field Summary
 
Fields inherited from class fri.util.database.jpa.tree.AbstractTreeDao
session
 
Fields inherited from interface fri.util.database.jpa.tree.TreeDao
UNDEFINED_POSITION
 
Constructor Summary
TemporalClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass, java.lang.Class<? extends TreePath> treePathsEntityClass, boolean positionMatters, java.lang.String validFromPropertyName, java.lang.String validToPropertyName, DbSession session)
          
TemporalClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass, java.lang.String treeNodeEntity, java.lang.Class<? extends TreePath> treePathEntityClass, java.lang.String treePathEntity, boolean positionMatters, java.lang.String validFromPropertyName, java.lang.String validToPropertyName, DbSession session)
          
 
Method Summary
protected  void assignInvalidity(TreePath path)
          Called when removing paths.
protected  void assignValidity(TreePath path)
          Called when unremoving paths.
protected  void beforeFindQuery(java.lang.String tableAlias, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters, boolean whereWasAppended)
          Overridden to append temporal conditions.
 java.util.List<ClosureTableTreeNode> findRemoved(ClosureTableTreeNode parent, java.util.Map<java.lang.String,java.lang.Object> criteria)
          
 java.util.List<ClosureTableTreeNode> findValidDirectChildren(java.util.List<ClosureTableTreeNode> subNodes)
          Use this to retrieve children lists that do not contain removed nodes from trees returned by getFullTreeCacheable().
 java.util.List<ClosureTableTreeNode> getAllRoots()
          
 java.util.List<ClosureTableTreeNode> getFullTreeCacheable(ClosureTableTreeNode node)
          
protected  java.lang.String getValidFromPropertyName()
          Temporal extension.
protected  java.lang.String getValidToPropertyName()
          Temporal extension.
protected  fri.util.database.jpa.tree.closuretable.CacheableTreeList newCacheableTreeList(ClosureTableTreeNode parent, java.util.List<TreePath> breadthFirstTree)
          Factory method for new CacheableTreeList.
 void removeAll()
          Removes all roots, including the nodes below them.
 void removeAllPhysically()
          Physically deletes everything, all roots and the trees below them.
 void removeHistoricizedTreesPhysically()
          Physically deletes all historicized tree nodes in all roots, including their sub-nodes.
protected  void removeNode(ClosureTableTreeNode nodeToRemove)
          Overridden to do nothing as related paths are historicized.
protected  void removePath(TreePath path)
          Overridden to historicize path, using the historicizing date.
 void removePhysically(ClosureTableTreeNode node)
          Physically deletes the tree under given node, including the node itself.
protected  void removeTree(ClosureTableTreeNode parent)
          Overridden to set the historicizing date by calling validToOnRemove().
protected  boolean shouldCloseGapOnRemove()
          Overridden to return false to prevent closing a gap on remove and reordering siblings after historization.
 void unremove(ClosureTableTreeNode node)
          Recovers the given removed (historicized) node, including all sub-nodes.
 
Methods inherited from class fri.util.database.jpa.tree.closuretable.ClosureTableTreeDao
addChild, addChildAt, addChildBefore, copy, copyBefore, copyTo, copyToBeRoot, createRoot, find, find, findDirectChildren, findSubTree, getChildCount, getChildren, getLevel, getParent, getPath, getPathsToRemove, getRoot, getRoots, getTree, getTreeCacheable, getTreePathEntity, isChildOf, isEqualToOrChildOf, isLeaf, isRemoveReferencedNodes, isRoot, move, moveBefore, moveTo, moveToBeRoot, newTreePathInstance, pathEntityName, remove, save, setRemoveReferencedNodes, size, update
 
Methods inherited from class fri.util.database.jpa.tree.AbstractTreeDao
appendInvalidityCondition, appendValidityCondition, applyCopiedNodeRenamer, assertUpdate, beforeFindQuery, buildAliasedPropertyName, buildIndexedPlaceHolder, checkUniqueConstraint, checkUniqueness, copyOrMovePreconditions, equal, getUniqueTreeConstraint, isPersistent, isValid, nodeEntityName, refresh, save, setCheckUniqueConstraintOnUpdate, setCopiedNodeRenamer, setUniqueTreeConstraint, shouldCheckUniqueConstraintOnUpdate, validFrom, validTo, validToOnRemove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fri.util.database.jpa.tree.TreeDao
addChild, addChildAt, addChildBefore, checkUniqueConstraint, copy, copyBefore, copyTo, copyToBeRoot, createRoot, find, find, findDirectChildren, findSubTree, getChildCount, getChildren, getLevel, getParent, getPath, getRoot, getRoots, getTree, getTreeCacheable, isChildOf, isEqualToOrChildOf, isLeaf, isPersistent, isRoot, move, moveBefore, moveTo, moveToBeRoot, remove, setCheckUniqueConstraintOnUpdate, setCopiedNodeRenamer, setUniqueTreeConstraint, size, update
 

Constructor Detail

TemporalClosureTableTreeDao

public TemporalClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass,
                                   java.lang.Class<? extends TreePath> treePathsEntityClass,
                                   boolean positionMatters,
                                   java.lang.String validFromPropertyName,
                                   java.lang.String validToPropertyName,
                                   DbSession session)

Parameters:
validFromPropertyName - the name of the temporal valid-from property in TreePath, can be null.
validToPropertyName - the name of the temporal valid-to property in TreePath, can be null when append* and assign* are overridden.

TemporalClosureTableTreeDao

public TemporalClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass,
                                   java.lang.String treeNodeEntity,
                                   java.lang.Class<? extends TreePath> treePathEntityClass,
                                   java.lang.String treePathEntity,
                                   boolean positionMatters,
                                   java.lang.String validFromPropertyName,
                                   java.lang.String validToPropertyName,
                                   DbSession session)

Parameters:
validFromPropertyName - the name of the temporal valid-from property in TreePath, can be null.
validToPropertyName - the name of the temporal valid-to property in TreePath, can be null when append* and assign* are overridden.
Method Detail

getAllRoots

public java.util.List<ClosureTableTreeNode> getAllRoots()

Specified by:
getAllRoots in interface TemporalTreeDao<ClosureTableTreeNode>
Returns:
all roots, including removed (historicized) ones.

findRemoved

public java.util.List<ClosureTableTreeNode> findRemoved(ClosureTableTreeNode parent,
                                                        java.util.Map<java.lang.String,java.lang.Object> criteria)

Specified by:
findRemoved in interface TemporalTreeDao<ClosureTableTreeNode>

getFullTreeCacheable

public java.util.List<ClosureTableTreeNode> getFullTreeCacheable(ClosureTableTreeNode node)

Specified by:
getFullTreeCacheable in interface TemporalTreeDao<ClosureTableTreeNode>
Returns:
the full tree under given parent, including removed (historicized) nodes.

findValidDirectChildren

public java.util.List<ClosureTableTreeNode> findValidDirectChildren(java.util.List<ClosureTableTreeNode> subNodes)
Use this to retrieve children lists that do not contain removed nodes from trees returned by getFullTreeCacheable(). Use findDirectChildren() on a fullTreeCacheable to retrieve children lists that also contain removed nodes. The difference of both would be the removed children.

Specified by:
findValidDirectChildren in interface TemporalTreeDao<ClosureTableTreeNode>
Parameters:
subNodes - the sub-tree to retrieve children from, containing parent at first position.
Returns:
the children list of the first node in given subNodes list, NOT containing removed nodes.

removeAll

public void removeAll()
Removes all roots, including the nodes below them. Thus clears the table.

Specified by:
removeAll in interface TreeDao<ClosureTableTreeNode>
Overrides:
removeAll in class ClosureTableTreeDao

unremove

public void unremove(ClosureTableTreeNode node)
Recovers the given removed (historicized) node, including all sub-nodes.

Specified by:
unremove in interface TemporalTreeDao<ClosureTableTreeNode>

removeAllPhysically

public void removeAllPhysically()
Physically deletes everything, all roots and the trees below them.

Specified by:
removeAllPhysically in interface TemporalTreeDao<ClosureTableTreeNode>

removePhysically

public void removePhysically(ClosureTableTreeNode node)
Physically deletes the tree under given node, including the node itself. Node can also be a root.

Specified by:
removePhysically in interface TemporalTreeDao<ClosureTableTreeNode>

removeHistoricizedTreesPhysically

public void removeHistoricizedTreesPhysically()
Physically deletes all historicized tree nodes in all roots, including their sub-nodes.

Specified by:
removeHistoricizedTreesPhysically in interface TemporalTreeDao<ClosureTableTreeNode>

newCacheableTreeList

protected fri.util.database.jpa.tree.closuretable.CacheableTreeList newCacheableTreeList(ClosureTableTreeNode parent,
                                                                                         java.util.List<TreePath> breadthFirstTree)
Factory method for new CacheableTreeList. Overridden for temporal variant.

Overrides:
newCacheableTreeList in class ClosureTableTreeDao

assignInvalidity

protected void assignInvalidity(TreePath path)
Called when removing paths. Assigns invalidity to passed domain object. Override this to use other invalidity assignments than valid-to property.

Parameters:
path - the tree-path to historicize.

assignValidity

protected void assignValidity(TreePath path)
Called when unremoving paths. Assigns validity to passed domain object. Override this to use other validity assignments than valid-to property.

Parameters:
path - the tree-path to unremove.

beforeFindQuery

protected final void beforeFindQuery(java.lang.String tableAlias,
                                     java.lang.StringBuilder queryText,
                                     java.util.List<java.lang.Object> parameters,
                                     boolean whereWasAppended)
Overridden to append temporal conditions.

Overrides:
beforeFindQuery in class ClosureTableTreeDao

shouldCloseGapOnRemove

protected boolean shouldCloseGapOnRemove()
Overridden to return false to prevent closing a gap on remove and reordering siblings after historization.

Overrides:
shouldCloseGapOnRemove in class ClosureTableTreeDao
Returns:
true for closing a gap and reordering siblings after physical remove.

removeTree

protected void removeTree(ClosureTableTreeNode parent)
Overridden to set the historicizing date by calling validToOnRemove().

Overrides:
removeTree in class ClosureTableTreeDao

removeNode

protected final void removeNode(ClosureTableTreeNode nodeToRemove)
Overridden to do nothing as related paths are historicized.

Overrides:
removeNode in class ClosureTableTreeDao

removePath

protected final void removePath(TreePath path)
Overridden to historicize path, using the historicizing date.

Overrides:
removePath in class ClosureTableTreeDao

getValidFromPropertyName

protected final java.lang.String getValidFromPropertyName()
Description copied from class: AbstractTreeDao
Temporal extension. Override this in temporal DAOs. Throws RuntimeException.

Overrides:
getValidFromPropertyName in class AbstractTreeDao<ClosureTableTreeNode>

getValidToPropertyName

protected final java.lang.String getValidToPropertyName()
Description copied from class: AbstractTreeDao
Temporal extension. Override this in temporal DAOs. Throws RuntimeException.

Overrides:
getValidToPropertyName in class AbstractTreeDao<ClosureTableTreeNode>