|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfri.util.database.jpa.tree.AbstractTreeDao<NestedSetsTreeNode>
fri.util.database.jpa.tree.nestedsets.NestedSetsTreeDao
public class NestedSetsTreeDao
Data-access-object for a hierarchical representation of records (nodes), using one database table, having no parent reference in children. A nested-sets tree will always maintain child positions, meaning children lists have a defined order which can only be changed by a move().
A nested-sets tree maintains its structure by "left" and "right" indexes on every node. The left index represents the depth-first traversal order. The right index is (left + 1) for a leaf child, for a folder it is (right + 1) of the child it follows according to depth-first traversal. For a root, left index is 1, right index is (number of nodes * 2). See links in TreeDao for more information. Note: as the temporal derivation obtains a state, all write-methods here are synchronized.
NestedSetsTreeNode
,
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 | |
---|---|
NestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> entityClass,
DbSession session)
|
|
NestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> entityClass,
java.lang.String entityName,
DbSession session)
|
Method Summary | |
---|---|
NestedSetsTreeNode |
addChild(NestedSetsTreeNode parent,
NestedSetsTreeNode child)
Adds to end of children of given parent. |
NestedSetsTreeNode |
addChildAt(NestedSetsTreeNode parent,
NestedSetsTreeNode child,
int position)
Adds at specified position to children of given parent. |
NestedSetsTreeNode |
addChildBefore(NestedSetsTreeNode sibling,
NestedSetsTreeNode 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. |
NestedSetsTreeNode |
copy(NestedSetsTreeNode node,
NestedSetsTreeNode parent,
NestedSetsTreeNode copiedNodeTemplate)
Copies the given node to end of children list of parent. |
NestedSetsTreeNode |
copyBefore(NestedSetsTreeNode node,
NestedSetsTreeNode sibling,
NestedSetsTreeNode copiedNodeTemplate)
Copies the given node to position of given sibling, pushing sibling backwards in list. |
protected void |
copyOrMovePreconditions(NestedSetsTreeNode relativeNode,
NestedSetsTreeNode nodeToMove)
Throws IllegalArgumentException when copy or move could not performed, checks if tree would be copied/moved into itself. |
NestedSetsTreeNode |
copyTo(NestedSetsTreeNode node,
NestedSetsTreeNode parent,
int position,
NestedSetsTreeNode copiedNodeTemplate)
Copies the given node to given position in children list of parent. |
NestedSetsTreeNode |
copyToBeRoot(NestedSetsTreeNode child,
NestedSetsTreeNode copiedNodeTemplate)
Copies a tree to be a root. |
NestedSetsTreeNode |
createRoot(NestedSetsTreeNode root)
Creates a tree root node. |
java.util.List<NestedSetsTreeNode> |
find(NestedSetsTreeNode parent,
java.util.Map<java.lang.String,java.lang.Object> criteria)
Convenience finder method. |
NestedSetsTreeNode |
find(java.io.Serializable id)
|
java.util.List<NestedSetsTreeNode> |
findDirectChildren(java.util.List<NestedSetsTreeNode> subNodes)
Finds a children list from a predefined list of nodes under a parent which is first in list. |
java.util.List<NestedSetsTreeNode> |
findSubTree(NestedSetsTreeNode parent,
java.util.List<NestedSetsTreeNode> tree)
Finds a sub-tree list from a predefined list of nodes under a parent. |
int |
getChildCount(NestedSetsTreeNode parent)
|
protected java.util.List<NestedSetsTreeNode> |
getChildListForInsertion(NestedSetsTreeNode parent)
|
java.util.List<NestedSetsTreeNode> |
getChildren(NestedSetsTreeNode parent)
Gives the children of passed parent. |
int |
getLevel(NestedSetsTreeNode node)
|
NestedSetsTreeNode |
getParent(NestedSetsTreeNode node)
|
java.util.List<NestedSetsTreeNode> |
getPath(NestedSetsTreeNode node)
|
NestedSetsTreeNode |
getRoot(NestedSetsTreeNode node)
|
java.util.List<NestedSetsTreeNode> |
getRoots()
|
protected java.util.List<NestedSetsTreeNode> |
getSubTreeDepthFirstForCopy(NestedSetsTreeNode nodeToCopy)
|
java.util.List<NestedSetsTreeNode> |
getTree(NestedSetsTreeNode parent)
Reads a tree or sub-tree, including all children. |
java.util.List<NestedSetsTreeNode> |
getTreeCacheable(NestedSetsTreeNode parent)
Reads a tree or sub-tree, including all children, which can be cached and passed back into findSubTree() or findDirectChildren() . |
boolean |
isChildOf(NestedSetsTreeNode child,
NestedSetsTreeNode parent)
|
boolean |
isEqualToOrChildOf(NestedSetsTreeNode child,
NestedSetsTreeNode parent)
|
boolean |
isLeaf(NestedSetsTreeNode node)
|
protected boolean |
isNextChild(int nextChildLeft,
NestedSetsTreeNode node,
int currentChildRight,
java.util.List<NestedSetsTreeNode> subNodes,
int currentIndex)
|
boolean |
isRoot(NestedSetsTreeNode entity)
|
protected boolean |
isValidFilterChild(NestedSetsTreeNode entity)
Called by filterChildren() from getChildren(). |
void |
move(NestedSetsTreeNode node,
NestedSetsTreeNode newParent)
Moves the given node to end of children list of parent. |
void |
moveBefore(NestedSetsTreeNode node,
NestedSetsTreeNode sibling)
Moves the given node to position of given sibling, pushing sibling backwards in list. |
void |
moveTo(NestedSetsTreeNode node,
NestedSetsTreeNode parent,
int position)
Moves the given node to given position in children list of parent. |
void |
moveToBeRoot(NestedSetsTreeNode child)
Moves a sub-tree to be a root. |
void |
remove(NestedSetsTreeNode node)
Removes the tree under given node, including the node. |
protected void |
remove(NestedSetsTreeNode node,
int removedNodesCount)
Removes given children. |
void |
removeAll()
Removes all roots, including the nodes below them. |
int |
size(NestedSetsTreeNode entity)
|
void |
update(NestedSetsTreeNode entity)
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 NestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> entityClass, DbSession session)
entityClass
- the persistence class representing the tree, implementing NestedSetsTreeNode.dbSession
- the database layer abstraction to be used for persistence actions.
Its simpleName will be used as table name for queries.public NestedSetsTreeDao(java.lang.Class<? extends NestedSetsTreeNode> entityClass, java.lang.String entityName, DbSession session)
entityClass
- the persistence class representing the tree table, implementing NestedSetsTreeNode.entityName
- the JPQL entity name of the database table to be used for queries, normally entityClass.getSimpleName().dbSession
- the database layer abstraction to be used for persistence actions.Method Detail |
---|
public NestedSetsTreeNode find(java.io.Serializable id)
public void update(NestedSetsTreeNode entity) throws UniqueConstraintViolationException
checkUniqueConstraintsOnUpdate
is true (default is false).
UniqueConstraintViolationException
- when given entity is not unique.public final boolean isRoot(NestedSetsTreeNode entity)
public NestedSetsTreeNode createRoot(NestedSetsTreeNode root) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when uniqueness would be violated.public java.util.List<NestedSetsTreeNode> getRoots()
public void removeAll()
public int size(NestedSetsTreeNode entity)
public java.util.List<NestedSetsTreeNode> getTree(NestedSetsTreeNode parent)
findSubTree()
or findDirectChildren()
!
parent
- the parent of the tree to read, can also be root of the tree.
public java.util.List<NestedSetsTreeNode> getTreeCacheable(NestedSetsTreeNode 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.
public boolean isLeaf(NestedSetsTreeNode node)
public int getChildCount(NestedSetsTreeNode parent)
public java.util.List<NestedSetsTreeNode> getChildren(NestedSetsTreeNode parent)
public java.util.List<NestedSetsTreeNode> findDirectChildren(java.util.List<NestedSetsTreeNode> subNodes)
subNodes
- a list of nodes from which to extract the direct child list, parent at head of list.
protected boolean isNextChild(int nextChildLeft, NestedSetsTreeNode node, int currentChildRight, java.util.List<NestedSetsTreeNode> subNodes, int currentIndex)
public final java.util.List<NestedSetsTreeNode> findSubTree(NestedSetsTreeNode parent, java.util.List<NestedSetsTreeNode> tree)
parent
- the parent node to search a sub-tree for, contained somewhere in the given list of nodes.tree
- a list of nodes from which to extract a sub-tree, containing the given parent.
protected boolean isValidFilterChild(NestedSetsTreeNode entity)
public NestedSetsTreeNode getRoot(NestedSetsTreeNode node)
public NestedSetsTreeNode getParent(NestedSetsTreeNode node)
public java.util.List<NestedSetsTreeNode> getPath(NestedSetsTreeNode node)
public int getLevel(NestedSetsTreeNode node)
public boolean isEqualToOrChildOf(NestedSetsTreeNode child, NestedSetsTreeNode parent)
public boolean isChildOf(NestedSetsTreeNode child, NestedSetsTreeNode parent)
public NestedSetsTreeNode addChild(NestedSetsTreeNode parent, NestedSetsTreeNode child) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when uniqueness would be violated.public NestedSetsTreeNode addChildAt(NestedSetsTreeNode parent, NestedSetsTreeNode child, int position) throws UniqueConstraintViolationException
position
- -1 for append, else target position in child list.
UniqueConstraintViolationException
- when uniqueness would be violated.public NestedSetsTreeNode addChildBefore(NestedSetsTreeNode sibling, NestedSetsTreeNode child) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when uniqueness would be violated.public void remove(NestedSetsTreeNode node)
public void move(NestedSetsTreeNode node, NestedSetsTreeNode newParent) throws UniqueConstraintViolationException
UniqueConstraintViolationException
public void moveTo(NestedSetsTreeNode node, NestedSetsTreeNode parent, int position) throws UniqueConstraintViolationException
UniqueConstraintViolationException
public void moveBefore(NestedSetsTreeNode node, NestedSetsTreeNode sibling) throws UniqueConstraintViolationException
UniqueConstraintViolationException
public void moveToBeRoot(NestedSetsTreeNode child) throws UniqueConstraintViolationException
UniqueConstraintViolationException
- when unique constraint(s) for roots would be violated.public NestedSetsTreeNode copy(NestedSetsTreeNode node, NestedSetsTreeNode parent, NestedSetsTreeNode 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 NestedSetsTreeNode copyTo(NestedSetsTreeNode node, NestedSetsTreeNode parent, int position, NestedSetsTreeNode 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 NestedSetsTreeNode copyBefore(NestedSetsTreeNode node, NestedSetsTreeNode sibling, NestedSetsTreeNode 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 NestedSetsTreeNode copyToBeRoot(NestedSetsTreeNode child, NestedSetsTreeNode 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<NestedSetsTreeNode> find(NestedSetsTreeNode 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 void remove(NestedSetsTreeNode node, int removedNodesCount)
protected java.util.List<NestedSetsTreeNode> getChildListForInsertion(NestedSetsTreeNode parent)
protected void copyOrMovePreconditions(NestedSetsTreeNode relativeNode, NestedSetsTreeNode nodeToMove)
AbstractTreeDao
copyOrMovePreconditions
in class AbstractTreeDao<NestedSetsTreeNode>
protected java.util.List<NestedSetsTreeNode> getSubTreeDepthFirstForCopy(NestedSetsTreeNode nodeToCopy)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |