fri.util.database.jpa.tree.nestedsets
Class TemporalNestedSetsTreeDao

java.lang.Object
  extended by fri.util.database.jpa.tree.AbstractTreeDao<NestedSetsTreeNode>
      extended by fri.util.database.jpa.tree.nestedsets.NestedSetsTreeDao
          extended by fri.util.database.jpa.tree.nestedsets.TemporalNestedSetsTreeDao
All Implemented Interfaces:
TemporalTreeDao<NestedSetsTreeNode>, TreeDao<NestedSetsTreeNode>

public class TemporalNestedSetsTreeDao
extends NestedSetsTreeDao
implements TemporalTreeDao<NestedSetsTreeNode>

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, 12.10.2011

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
TemporalNestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> targetEntityClass, java.lang.String validFromPropertyName, java.lang.String validToPropertyName, DbSession session)
          
TemporalNestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> targetEntityClass, java.lang.String targetEntityName, java.lang.String validFromPropertyName, java.lang.String validToPropertyName, DbSession session)
          
 
Method Summary
protected  void assignInvalidity(java.lang.String tableAlias, java.lang.StringBuilder updateText, java.util.List<java.lang.Object> parameters)
          Called when removing nodes.
protected  void assignValidity(java.lang.String tableAlias, java.lang.StringBuilder updateText, java.util.List<java.lang.Object> parameters)
          Called when unremoving nodes.
protected  void beforeFindQuery(java.lang.String tableAlias, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters, boolean whereWasAppended)
          Overridden to search only nodes that were not historicized.
 java.util.List<NestedSetsTreeNode> findRemoved(NestedSetsTreeNode parent, java.util.Map<java.lang.String,java.lang.Object> criteria)
          
 java.util.List<NestedSetsTreeNode> findValidDirectChildren(java.util.List<NestedSetsTreeNode> subNodes)
          Use this to retrieve children lists that do not contain removed nodes from trees returned by getFullTreeCacheable().
 java.util.List<NestedSetsTreeNode> getAllRoots()
          
protected  java.util.List<NestedSetsTreeNode> getChildListForInsertion(NestedSetsTreeNode parent)
          Overridden to return children including invalid ones.
 java.util.List<NestedSetsTreeNode> getChildren(NestedSetsTreeNode parent)
          Overridden because super.getChildren() would not work with a sub-tree list that contains nodes with left/right indexes that have gaps because historicized nodes are not contained.
 java.util.List<NestedSetsTreeNode> getFullTreeCacheable(NestedSetsTreeNode node)
          
protected  java.util.List<NestedSetsTreeNode> getSubTreeDepthFirstForCopy(NestedSetsTreeNode nodeToCopy)
          Overridden to include removed nodes into copy-list, else inconsistent left/right numbers would occur.
protected  java.lang.String getValidFromPropertyName()
          Temporal extension.
protected  java.lang.String getValidToPropertyName()
          Temporal extension.
 boolean isLeaf(NestedSetsTreeNode node)
          Overridden to read the subtree when super returns false, because historicized nodes occupy left and right indexes.
protected  boolean isNextChild(int nextChildLeft, NestedSetsTreeNode node, int currentChildRight, java.util.List<NestedSetsTreeNode> subNodes, int currentIndex)
          Overridden to bridge index gaps that occur when nodes have been historicized.
protected  boolean isValidFilterChild(NestedSetsTreeNode node)
          Overridden to filter out historicized children on findDirectChildren().
protected  void remove(NestedSetsTreeNode node, int removedNodesCount)
          Overridden to historicize children.
 void removeAll()
          Overridden to historicize roots instead of removing them physically.
 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.
 void removePhysically(NestedSetsTreeNode node)
          Physically deletes the tree under given node, including the node itself.
 int size(NestedSetsTreeNode node)
          Overridden to always read the subtree, because historicized nodes occupy left and right indexes.
 void unremove(NestedSetsTreeNode node)
          Recovers the given removed (historicized) node, including all sub-nodes.
 
Methods inherited from class fri.util.database.jpa.tree.nestedsets.NestedSetsTreeDao
addChild, addChildAt, addChildBefore, copy, copyBefore, copyOrMovePreconditions, copyTo, copyToBeRoot, createRoot, find, find, findDirectChildren, findSubTree, getChildCount, getLevel, getParent, getPath, getRoot, getRoots, getTree, getTreeCacheable, isChildOf, isEqualToOrChildOf, isRoot, move, moveBefore, moveTo, moveToBeRoot, remove, update
 
Methods inherited from class fri.util.database.jpa.tree.AbstractTreeDao
appendInvalidityCondition, appendValidityCondition, applyCopiedNodeRenamer, assertUpdate, beforeFindQuery, buildAliasedPropertyName, buildIndexedPlaceHolder, checkUniqueConstraint, checkUniqueness, equal, getUniqueTreeConstraint, isPersistent, isValid, nodeEntityName, pathEntityName, 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, getLevel, getParent, getPath, getRoot, getRoots, getTree, getTreeCacheable, isChildOf, isEqualToOrChildOf, isPersistent, isRoot, move, moveBefore, moveTo, moveToBeRoot, remove, setCheckUniqueConstraintOnUpdate, setCopiedNodeRenamer, setUniqueTreeConstraint, update
 

Constructor Detail

TemporalNestedSetsTreeDao

public TemporalNestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> targetEntityClass,
                                 java.lang.String validFromPropertyName,
                                 java.lang.String validToPropertyName,
                                 DbSession session)

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

TemporalNestedSetsTreeDao

public TemporalNestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> targetEntityClass,
                                 java.lang.String targetEntityName,
                                 java.lang.String validFromPropertyName,
                                 java.lang.String validToPropertyName,
                                 DbSession session)

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

size

public int size(NestedSetsTreeNode node)
Overridden to always read the subtree, because historicized nodes occupy left and right indexes.

Specified by:
size in interface TreeDao<NestedSetsTreeNode>
Overrides:
size in class NestedSetsTreeDao
Returns:
the count of all nodes of any depth below given node, including itself.

isLeaf

public boolean isLeaf(NestedSetsTreeNode node)
Overridden to read the subtree when super returns false, because historicized nodes occupy left and right indexes.

Specified by:
isLeaf in interface TreeDao<NestedSetsTreeNode>
Overrides:
isLeaf in class NestedSetsTreeDao
Returns:
true when given node has no children, i.e. is not a container-node.

getChildren

public java.util.List<NestedSetsTreeNode> getChildren(NestedSetsTreeNode parent)
Overridden because super.getChildren() would not work with a sub-tree list that contains nodes with left/right indexes that have gaps because historicized nodes are not contained.

Specified by:
getChildren in interface TreeDao<NestedSetsTreeNode>
Overrides:
getChildren in class NestedSetsTreeDao
Returns:
the ordered list of direct children under given parent.

removeAll

public void removeAll()
Overridden to historicize roots instead of removing them physically.

Specified by:
removeAll in interface TreeDao<NestedSetsTreeNode>
Overrides:
removeAll in class NestedSetsTreeDao

findRemoved

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

Specified by:
findRemoved in interface TemporalTreeDao<NestedSetsTreeNode>

getAllRoots

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

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

getFullTreeCacheable

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

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

unremove

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

Specified by:
unremove in interface TemporalTreeDao<NestedSetsTreeNode>

removeHistoricizedTreesPhysically

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

Specified by:
removeHistoricizedTreesPhysically in interface TemporalTreeDao<NestedSetsTreeNode>

removeAllPhysically

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

Specified by:
removeAllPhysically in interface TemporalTreeDao<NestedSetsTreeNode>

removePhysically

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

Specified by:
removePhysically in interface TemporalTreeDao<NestedSetsTreeNode>

findValidDirectChildren

public java.util.List<NestedSetsTreeNode> findValidDirectChildren(java.util.List<NestedSetsTreeNode> 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<NestedSetsTreeNode>
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.

beforeFindQuery

protected final void beforeFindQuery(java.lang.String tableAlias,
                                     java.lang.StringBuilder queryText,
                                     java.util.List<java.lang.Object> parameters,
                                     boolean whereWasAppended)
Overridden to search only nodes that were not historicized.

Overrides:
beforeFindQuery in class NestedSetsTreeDao

getSubTreeDepthFirstForCopy

protected java.util.List<NestedSetsTreeNode> getSubTreeDepthFirstForCopy(NestedSetsTreeNode nodeToCopy)
Overridden to include removed nodes into copy-list, else inconsistent left/right numbers would occur.

Overrides:
getSubTreeDepthFirstForCopy in class NestedSetsTreeDao
Returns:
the tree under given node when copying, to be overridden.

isValidFilterChild

protected final boolean isValidFilterChild(NestedSetsTreeNode node)
Overridden to filter out historicized children on findDirectChildren().

Overrides:
isValidFilterChild in class NestedSetsTreeDao

getChildListForInsertion

protected final java.util.List<NestedSetsTreeNode> getChildListForInsertion(NestedSetsTreeNode parent)
Overridden to return children including invalid ones.

Overrides:
getChildListForInsertion in class NestedSetsTreeDao
Returns:
children list of given parent, called from insertionParameters(), to be overridden by subclasses.

remove

protected final void remove(NestedSetsTreeNode node,
                            int removedNodesCount)
Overridden to historicize children.

Overrides:
remove in class NestedSetsTreeDao

isNextChild

protected boolean isNextChild(int nextChildLeft,
                              NestedSetsTreeNode node,
                              int currentChildRight,
                              java.util.List<NestedSetsTreeNode> subNodes,
                              int currentIndex)
Overridden to bridge index gaps that occur when nodes have been historicized.

Overrides:
isNextChild in class NestedSetsTreeDao
Returns:
true if node-left is nextChildLeft. Override this when left-indexes have gaps.

assignInvalidity

protected void assignInvalidity(java.lang.String tableAlias,
                                java.lang.StringBuilder updateText,
                                java.util.List<java.lang.Object> parameters)
Called when removing nodes. Appends the (temporal) invalidity assignment to passed JPQL statement, something like "t.validTo = ?", where validTo is taken from . Override this to use other invalidity assignments than valid-to property.

Parameters:
tableAlias - the alias of the table containing the validTo property, without trailing dot.
updateText - the pending JPQL query text removing invalid nodes.
parameters - the positional arguments for the pending query.

assignValidity

protected void assignValidity(java.lang.String tableAlias,
                              java.lang.StringBuilder updateText,
                              java.util.List<java.lang.Object> parameters)
Called when unremoving nodes. Appends the (temporal) validity assignment to passed JPQL statement, which is "t.validTo = null". Override for using another unremove-date. Override this to use other validity assignments.

Parameters:
tableAlias - the alias of the table containing the validTo property, without trailing dot.
updateText - the pending JPQL query text unremoving nodes.
parameters - the positional arguments for the pending query.

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<NestedSetsTreeNode>

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<NestedSetsTreeNode>