|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfri.util.database.jpa.tree.AbstractTreeDao<ClosureTableTreeNode>
fri.util.database.jpa.tree.closuretable.ClosureTableTreeDao
public class ClosureTableTreeDao
Data-access-object for a hierarchical representation of records (nodes), using two database tables, having no parent reference in children. This closure-table tree will maintain child positions, meaning children lists have a defined order which can only be changed by a move(). For better performance this can be turned off by a constructor parameter.
This DAO manages the tree structure of any entity type that implements ClosureTableTreeNode. You don't need to save or delete the ClosureTableTreeNode separately, this is done here. The "closure table" method acts on two database tables, thus it needs two entity types for its operations:
ClosureTableTreeNode
,
TreeDao
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 | |
---|---|
ClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass,
java.lang.Class<? extends TreePath> treePathsEntityClass,
boolean orderIndexMatters,
DbSession session)
|
|
ClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass,
java.lang.String treeNodeEntity,
java.lang.Class<? extends TreePath> treePathEntityClass,
java.lang.String treePathEntity,
boolean orderIndexMatters,
DbSession session)
|
Method Summary | |
---|---|
ClosureTableTreeNode |
addChild(ClosureTableTreeNode parent,
ClosureTableTreeNode child)
Adds to end of children of given parent. |
ClosureTableTreeNode |
addChildAt(ClosureTableTreeNode parent,
ClosureTableTreeNode child,
int position)
Adds at specified position to children of given parent. |
ClosureTableTreeNode |
addChildBefore(ClosureTableTreeNode sibling,
ClosureTableTreeNode child)
Adds to children before given sibling, sibling is pushed backwards in children list. |
protected void |
beforeFindQuery(java.lang.String tableAlias,
java.lang.StringBuilder queryText,
java.util.List<java.lang.Object> parameters,
boolean whereWasAppended)
Does nothing. |
ClosureTableTreeNode |
copy(ClosureTableTreeNode node,
ClosureTableTreeNode parent,
ClosureTableTreeNode copiedNodeTemplate)
Copies the given node to end of children list of parent. |
ClosureTableTreeNode |
copyBefore(ClosureTableTreeNode node,
ClosureTableTreeNode sibling,
ClosureTableTreeNode copiedNodeTemplate)
Copies the given node to position of given sibling, pushing sibling backwards in list. |
ClosureTableTreeNode |
copyTo(ClosureTableTreeNode node,
ClosureTableTreeNode parent,
int position,
ClosureTableTreeNode copiedNodeTemplate)
Copies the given node to given position in children list of parent. |
ClosureTableTreeNode |
copyToBeRoot(ClosureTableTreeNode child,
ClosureTableTreeNode copiedNodeTemplate)
Copies a tree to be a root. |
ClosureTableTreeNode |
createRoot(ClosureTableTreeNode root)
Creates a tree root node. |
java.util.List<ClosureTableTreeNode> |
find(ClosureTableTreeNode parent,
java.util.Map<java.lang.String,java.lang.Object> criteria)
Convenience finder method. |
ClosureTableTreeNode |
find(java.io.Serializable id)
|
java.util.List<ClosureTableTreeNode> |
findDirectChildren(java.util.List<ClosureTableTreeNode> subNodes)
Finds direct children in a cached list of tree nodes, parent is first in that cached list. |
java.util.List<ClosureTableTreeNode> |
findSubTree(ClosureTableTreeNode parent,
java.util.List<ClosureTableTreeNode> subNodes)
Finds a sub-tree list in a cached list of tree nodes under given parent. |
int |
getChildCount(ClosureTableTreeNode parent)
|
java.util.List<ClosureTableTreeNode> |
getChildren(ClosureTableTreeNode parent)
Gives the children of passed parent. |
int |
getLevel(ClosureTableTreeNode node)
|
ClosureTableTreeNode |
getParent(ClosureTableTreeNode child)
|
java.util.List<ClosureTableTreeNode> |
getPath(ClosureTableTreeNode node)
|
protected java.util.List<? extends TreePath> |
getPathsToRemove(ClosureTableTreeNode node)
|
ClosureTableTreeNode |
getRoot(ClosureTableTreeNode node)
|
java.util.List<ClosureTableTreeNode> |
getRoots()
|
java.util.List<ClosureTableTreeNode> |
getTree(ClosureTableTreeNode parent)
Reads a tree or sub-tree, including all children. |
java.util.List<ClosureTableTreeNode> |
getTreeCacheable(ClosureTableTreeNode parent)
Reads a tree or sub-tree, including all children, which can be cached and passed back into findSubTree() or findDirectChildren() . |
TreePath |
getTreePathEntity(ClosureTableTreeNode node)
This is for the case when the provided TreePath implementation contains additional properties concerning the node. |
boolean |
isChildOf(ClosureTableTreeNode child,
ClosureTableTreeNode parent)
|
boolean |
isEqualToOrChildOf(ClosureTableTreeNode child,
ClosureTableTreeNode parent)
|
boolean |
isLeaf(ClosureTableTreeNode node)
|
boolean |
isRemoveReferencedNodes()
|
boolean |
isRoot(ClosureTableTreeNode node)
|
void |
move(ClosureTableTreeNode node,
ClosureTableTreeNode parent)
Moves the given node to end of children list of parent. |
void |
moveBefore(ClosureTableTreeNode node,
ClosureTableTreeNode sibling)
Moves the given node to position of given sibling, pushing sibling backwards in list. |
void |
moveTo(ClosureTableTreeNode node,
ClosureTableTreeNode parent,
int position)
Moves the given node to given position in children list of parent. |
void |
moveToBeRoot(ClosureTableTreeNode child)
Moves a sub-tree to be a root. |
protected fri.util.database.jpa.tree.closuretable.CacheableTreeList |
newCacheableTreeList(ClosureTableTreeNode parent,
java.util.List<TreePath> breadthFirstTree)
Factory method for new CacheableTreeList. |
protected TreePath |
newTreePathInstance()
Creates a new TreePath instance from treePathEntityClass. |
protected java.lang.String |
pathEntityName()
Overridden to return the name of TreePaths entity. |
void |
remove(ClosureTableTreeNode node)
Removes the tree under given node, including the node. |
void |
removeAll()
Removes all roots, including the nodes below them. |
protected void |
removeNode(ClosureTableTreeNode nodeToRemove)
Called from remove() for all sub-nodes of removed tree. |
protected void |
removePath(TreePath path)
Called from remove() for all sub-nodes of removed tree. |
protected void |
removeTree(ClosureTableTreeNode parent)
Called from remove() after locking tree. |
protected java.lang.Object |
save(TreePath path)
Saves the given path to session. |
void |
setRemoveReferencedNodes(boolean removeReferencedNodes)
Set this to true when driving no more than one tree over a node table. |
protected boolean |
shouldCloseGapOnRemove()
Called from remove(). |
int |
size(ClosureTableTreeNode parent)
|
void |
update(ClosureTableTreeNode node)
Updates the given persistent object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass, java.lang.Class<? extends TreePath> treePathsEntityClass, boolean orderIndexMatters, DbSession session)
treeNodeEntityClass
- the persistence class representing the tree, implementing ClosureTableTreeNode.
Its simpleName will be used as table name for queries.treePathsEntityClass
- the persistence class representing ancestor-child relations, implementing TreePaths.
Its simpleName will be used as table name for queries.orderIndexMatters
- true when position of nodes should be managed, false if position does not matter (makes operations a little faster).public ClosureTableTreeDao(java.lang.Class<? extends ClosureTableTreeNode> treeNodeEntityClass, java.lang.String treeNodeEntity, java.lang.Class<? extends TreePath> treePathEntityClass, java.lang.String treePathEntity, boolean orderIndexMatters, DbSession session)
treeNodeEntityClass
- the persistence class representing the tree, implementing ClosureTableTreeNode.treeNodeEntity
- the JPQL entity name of the database table to be used for node queries.treePathEntityClass
- the persistence class representing ancestor-child relations, implementing TreePaths.treePathEntity
- the JPQL entity name of the database table to be used for path queries.orderIndexMatters
- true when position of nodes should be managed, false if position does not matter (makes operations a little faster).Method Detail |
---|
public boolean isRemoveReferencedNodes()
public void setRemoveReferencedNodes(boolean removeReferencedNodes)
public TreePath getTreePathEntity(ClosureTableTreeNode node)
node
- the node for which TreePath information is requested.
public ClosureTableTreeNode find(java.io.Serializable id)
public void update(ClosureTableTreeNode node) throws UniqueConstraintViolationException
checkUniqueConstraintsOnUpdate
is true (default is false).
UniqueConstraintViolationException
- when given entity is not unique.public final boolean isRoot(ClosureTableTreeNode node)
public ClosureTableTreeNode createRoot(ClosureTableTreeNode root) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when uniqueness would be violated.public java.util.List<ClosureTableTreeNode> getRoots()
public void removeAll()
public java.util.List<ClosureTableTreeNode> getTree(ClosureTableTreeNode parent)
findSubTree()
or findDirectChildren()
!
parent
- the parent of the tree to read, can also be root of the tree.
public java.util.List<ClosureTableTreeNode> getTreeCacheable(ClosureTableTreeNode parent)
findSubTree()
or findDirectChildren()
.
Mind that any cached tree could be out-of-sync with database when another client performs changes.
parent
- the parent of the tree to read, can also be root of the tree.
protected fri.util.database.jpa.tree.closuretable.CacheableTreeList newCacheableTreeList(ClosureTableTreeNode parent, java.util.List<TreePath> breadthFirstTree)
public java.util.List<ClosureTableTreeNode> findSubTree(ClosureTableTreeNode parent, java.util.List<ClosureTableTreeNode> subNodes)
getTreeCacheable()
.
Mind that any cached tree could be out-of-sync with database when another client performs changes.
parent
- the parent node to search a sub-tree for, contained somewhere in the given list of nodes.subNodes
- a list of nodes from which to extract a sub-tree, also containing given parent.
public java.util.List<ClosureTableTreeNode> findDirectChildren(java.util.List<ClosureTableTreeNode> subNodes)
getTreeCacheable()
or findSubTree()
.
Mind that any cached tree could be out-of-sync with database when another client performs changes.
subNodes
- a list of nodes from which to extract the direct child list, parent at head of list.
public int getChildCount(ClosureTableTreeNode parent)
public java.util.List<ClosureTableTreeNode> getChildren(ClosureTableTreeNode parent)
public ClosureTableTreeNode getRoot(ClosureTableTreeNode node)
public ClosureTableTreeNode getParent(ClosureTableTreeNode child)
public java.util.List<ClosureTableTreeNode> getPath(ClosureTableTreeNode node)
public int getLevel(ClosureTableTreeNode node)
public int size(ClosureTableTreeNode parent)
public boolean isLeaf(ClosureTableTreeNode node)
public boolean isEqualToOrChildOf(ClosureTableTreeNode child, ClosureTableTreeNode parent)
public boolean isChildOf(ClosureTableTreeNode child, ClosureTableTreeNode parent)
public ClosureTableTreeNode addChild(ClosureTableTreeNode parent, ClosureTableTreeNode child) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when uniqueness would be violated.public ClosureTableTreeNode addChildAt(ClosureTableTreeNode parent, ClosureTableTreeNode child, int position) throws UniqueConstraintViolationException
position
- -1 for append, else target position in child list.
UniqueConstraintViolationException
- when uniqueness would be violated.public ClosureTableTreeNode addChildBefore(ClosureTableTreeNode sibling, ClosureTableTreeNode child) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when uniqueness would be violated.public void remove(ClosureTableTreeNode node)
public void move(ClosureTableTreeNode node, ClosureTableTreeNode parent) throws UniqueConstraintViolationException
UniqueConstraintViolationException
public void moveTo(ClosureTableTreeNode node, ClosureTableTreeNode parent, int position) throws UniqueConstraintViolationException
UniqueConstraintViolationException
public void moveBefore(ClosureTableTreeNode node, ClosureTableTreeNode sibling) throws UniqueConstraintViolationException
UniqueConstraintViolationException
public void moveToBeRoot(ClosureTableTreeNode child) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when unique constraint(s) for roots would be violated.public ClosureTableTreeNode copy(ClosureTableTreeNode node, ClosureTableTreeNode parent, ClosureTableTreeNode copiedNodeTemplate) throws UniqueConstraintViolationException
node
- the node to be copied.copiedNodeTemplate
- a template for the copied node containing altered properties, can be null.
UniqueConstraintViolationException
- when uniqueness would be violated.public ClosureTableTreeNode copyTo(ClosureTableTreeNode node, ClosureTableTreeNode parent, int position, ClosureTableTreeNode copiedNodeTemplate) throws UniqueConstraintViolationException
node
- the node to be copied.parent
- the parent-node of the children the node should be copied into.position
- the 0-n index the node should obtain within children of parent.copiedNodeTemplate
- a template for the copied node containing altered properties, can be null.
UniqueConstraintViolationException
- when uniqueness would be violated.public ClosureTableTreeNode copyBefore(ClosureTableTreeNode node, ClosureTableTreeNode sibling, ClosureTableTreeNode copiedNodeTemplate) throws UniqueConstraintViolationException
node
- the node to be copied.sibling
- the target node the copied node should push backwards in children list.copiedNodeTemplate
- a template for the copied node containing altered properties, can be null.
UniqueConstraintViolationException
- when uniqueness would be violated.public ClosureTableTreeNode copyToBeRoot(ClosureTableTreeNode child, ClosureTableTreeNode copiedNodeTemplate) throws UniqueConstraintViolationException
child
- the node to copy to be a root.copiedNodeTemplate
- a template for the copied node containing altered properties, can be null.
UniqueConstraintViolationException
- when unique constraint(s) for roots would be violated.public java.util.List<ClosureTableTreeNode> find(ClosureTableTreeNode parent, java.util.Map<java.lang.String,java.lang.Object> criteria)
parent
- the parent under which to search, can be null.criteria
- a name/value mapping for the nodes to be found under given tree.
protected void beforeFindQuery(java.lang.String tableAlias, java.lang.StringBuilder queryText, java.util.List<java.lang.Object> parameters, boolean whereWasAppended)
protected java.lang.String pathEntityName()
pathEntityName
in class AbstractTreeDao<ClosureTableTreeNode>
protected TreePath newTreePathInstance()
protected java.lang.Object save(TreePath path)
protected boolean shouldCloseGapOnRemove()
protected void removeTree(ClosureTableTreeNode parent)
protected void removePath(TreePath path)
protected void removeNode(ClosureTableTreeNode nodeToRemove)
protected final java.util.List<? extends TreePath> getPathsToRemove(ClosureTableTreeNode node)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |