public class BTreeManager extends Object implements TreeManager
TreeManager implementation provides B+-tree like behavior. That
is items of a sequence (i.e. NodeSequence or PropertySequence)
are mapped to a sub-tree in JCR in a way such that only leave nodes carry
actual values, the sub-tree is always balanced and ordered. This
implementation does in contrast to a full B+-tree implementation not
join nodes after deletions. This does not affect the order of items and also
leaves the tree balanced wrt. its depths. It might however result in a sparse
tree. That is, the tree might get unbalanced wrt. its weights.
The nodes in the JCR sub tree are arranged such that any node named x
only contains child nodes with names greater or equal to x.
The implementation keeps the child nodes in the sub tree ordered if the
respective node type supports ordering of child nodes.
Ordering is always wrt. to a Comparator on the respective keys.
For lexical order this arrangement corresponds to how words are arranged in a multi
volume encyclopedia.
Example usage:
// Create a new TreeManager instance rooted at node. Splitting of nodes takes place
// when the number of children of a node exceeds 40 and is done such that each new
// node has at least 40 child nodes. The keys are ordered according to the natural
// order of java.lang.String.
TreeManager treeManager = new BTreeManager(node, 20, 40, Rank.<String>comparableComparator(), true);
// Create a new NodeSequence with that tree manager
NodeSequence nodes = ItemSequence.createNodeSequence(treeManager);
// Add nodes with key "jcr" and "day"
nodes.addNode("jcr", NodeType.NT_UNSTRUCTURED);
nodes.addNode("day", NodeType.NT_UNSTRUCTURED);
// Iterate over the node in the sequence.
// Prints "day jcr "
for (Node n : nodes) {
System.out.print(n.getName() + " ");
}
// Retrieve node with key "jcr"
Node n = nodes.getItem("jcr");
// Remove node with key "day"
nodes.removeNode("day");
| Constructor and Description |
|---|
BTreeManager(Node root,
int minChildren,
int maxChildren,
Comparator<String> order,
boolean autoSave)
Create a new
BTreeManager rooted at Node root. |
| Modifier and Type | Method and Description |
|---|---|
protected Node |
createIntermediateNode(Node parent,
String name)
Creates and return an intermediate node for the given
name
as child node of parent. |
boolean |
getAutoSave()
Whether to automatically save changes of the current session occurring
from adding/removing nodes and properties.
|
Set<String> |
getIgnoredProperties()
Properties to ignore.
|
protected SizedIterator<Node> |
getNodes(Node node)
Returns a
SizedIterator of the child nodes of node. |
Comparator<String> |
getOrder()
Comparator used for establishing the order of the keys in the
sequence. |
protected SizedIterator<Property> |
getProperties(Node node)
|
Node |
getRoot() |
protected <T> SizedIterator<T> |
getSizedIterator(Iterator<T> iterator,
long size)
|
boolean |
isLeaf(Node node)
Returns
!node.hasNodes() |
boolean |
isRoot(Node node)
Determined whether the given
node is the root node of the
JCR sub-tree. |
void |
join(ItemSequence itemSequence,
Node node,
Node cause)
This implementation does not actually join any nodes.
|
void |
join(ItemSequence itemSequence,
Node node,
Property cause)
This implementation does not actually join any nodes.
|
protected void |
move(Node node,
Node parent)
Move
node to the new parent. |
protected void |
move(Property property,
Node parent)
Move
property to the new parent. |
void |
split(ItemSequence itemSequence,
Node node,
Node cause)
This implementations splits
node when its number of child
nodes exceeds the maximum number specified in the constructor. |
void |
split(ItemSequence itemSequence,
Node node,
Property cause)
This implementations splits
node when its number of
properties exceeds the maximum number specified in the constructor. |
public BTreeManager(Node root, int minChildren, int maxChildren, Comparator<String> order, boolean autoSave) throws RepositoryException
BTreeManager rooted at Node root.root - the root of the JCR sub-tree where the items of the sequence
are stored.minChildren - minimal number of children for a node after splitting.maxChildren - maximal number of children for a node after which
splitting occurs.order - order according to which the keys are storedautoSave - determines whether the current session is saved after
add/delete operations.RepositoryExceptionpublic Set<String> getIgnoredProperties()
JcrConstants.JCR_PRIMARYTYPE
and JcrConstants.JCR_MIXINTYPES.getIgnoredProperties in interface TreeManagerpublic void split(ItemSequence itemSequence, Node node, Node cause) throws RepositoryException
node when its number of child
nodes exceeds the maximum number specified in the constructor. Splitting
is done such that after the split each of the new child nodes contains at
least as many nodes as specified in the constructor.split in interface TreeManageritemSequence - the ItemSequence where the new node
cause has been inserted.node - the parent node of the newly inserted nodecause - the newly inserted node or null if not known.RepositoryExceptionTreeManager.split(org.apache.jackrabbit.commons.flat.ItemSequence,
javax.jcr.Node, javax.jcr.Node)public void split(ItemSequence itemSequence, Node node, Property cause) throws RepositoryException
node when its number of
properties exceeds the maximum number specified in the constructor.
Splitting is done such that after the split each of the new child nodes
contains at least as many nodes as specified in the constructor.split in interface TreeManageritemSequence - the ItemSequence where the new property
cause has been inserted.node - the parent node of the newly inserted propertycause - the newly inserted property or null if not
known.RepositoryExceptionTreeManager.split(org.apache.jackrabbit.commons.flat.ItemSequence,
javax.jcr.Node, javax.jcr.Property)public void join(ItemSequence itemSequence, Node node, Node cause) throws RepositoryException
node if getNodes(Node) returns an empty
iterator. It does further recursively delete any parent of
node which does not have any child node.join in interface TreeManageritemSequence - the ItemSequence where the node
cause has been deleted from.node - the parent node from which cause has been
deleted.cause - the deleted node or null if not known.
Note: cause might be stale.RepositoryExceptionTreeManager.join(org.apache.jackrabbit.commons.flat.ItemSequence,
javax.jcr.Node, javax.jcr.Node)public void join(ItemSequence itemSequence, Node node, Property cause) throws RepositoryException
node if getProperties(Node) returns an empty
iterator. It does further recursively delete any parent of
node which does not have any child node.join in interface TreeManageritemSequence - the ItemSequence where the property
cause has been deleted from.node - the parent node from which cause has been
deleted.cause - the deleted property or null if not known.
Note: cause might be stale.RepositoryExceptionTreeManager.join(org.apache.jackrabbit.commons.flat.ItemSequence,
javax.jcr.Node, javax.jcr.Property)public Node getRoot()
getRoot in interface TreeManagerpublic boolean isRoot(Node node) throws RepositoryException
TreeManagernode is the root node of the
JCR sub-tree.isRoot in interface TreeManagernode - Node to test for rootgetRoot().isSame(node).RepositoryExceptionpublic boolean isLeaf(Node node) throws RepositoryException
!node.hasNodes()isLeaf in interface TreeManagernode - Node to test for leaftrue if node is a leaf node,
false otherwise.RepositoryExceptionTreeManager.isLeaf(javax.jcr.Node)public Comparator<String> getOrder()
TreeManagerComparator used for establishing the order of the keys in the
sequence.getOrder in interface TreeManagerComparator<String> instancepublic boolean getAutoSave()
TreeManagergetAutoSave in interface TreeManagertrue if changes should be automatically saved,
false otherwiese.protected SizedIterator<Node> getNodes(Node node) throws RepositoryException
SizedIterator of the child nodes of node.RepositoryExceptionprotected SizedIterator<Property> getProperties(Node node) throws RepositoryException
RepositoryExceptionprotected Node createIntermediateNode(Node parent, String name) throws RepositoryException
name
as child node of parent.RepositoryExceptionprotected void move(Node node, Node parent) throws RepositoryException
node to the new parent.RepositoryExceptionprotected void move(Property property, Node parent) throws RepositoryException
property to the new parent.RepositoryExceptionprotected final <T> SizedIterator<T> getSizedIterator(Iterator<T> iterator, long size)
iterator into a SizedIterator given a
size. The value of the size parameter must
correctly reflect the number of items in iterator.Copyright © 2004–2024 The Apache Software Foundation. All rights reserved.