Class BTreeManager
- java.lang.Object
- 
- org.apache.jackrabbit.commons.flat.BTreeManager
 
- 
- All Implemented Interfaces:
- TreeManager
 
 public class BTreeManager extends Object implements TreeManager ThisTreeManagerimplementation provides B+-tree like behavior. That is items of a sequence (i.e.NodeSequenceorPropertySequence) 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 xonly contains child nodes with names greater or equal tox. 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 aComparatoron 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 SummaryConstructors Constructor Description BTreeManager(Node root, int minChildren, int maxChildren, Comparator<String> order, boolean autoSave)Create a newBTreeManagerrooted at Noderoot.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected NodecreateIntermediateNode(Node parent, String name)Creates and return an intermediate node for the givennameas child node ofparent.booleangetAutoSave()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 aSizedIteratorof the child nodes ofnode.Comparator<String>getOrder()Comparatorused for establishing the order of the keys in the sequence.protected SizedIterator<Property>getProperties(Node node)NodegetRoot()protected <T> SizedIterator<T>getSizedIterator(Iterator<T> iterator, long size)booleanisLeaf(Node node)Returns!node.hasNodes()booleanisRoot(Node node)Determined whether the givennodeis the root node of the JCR sub-tree.voidjoin(ItemSequence itemSequence, Node node, Node cause)This implementation does not actually join any nodes.voidjoin(ItemSequence itemSequence, Node node, Property cause)This implementation does not actually join any nodes.protected voidmove(Node node, Node parent)Movenodeto the newparent.protected voidmove(Property property, Node parent)Movepropertyto the newparent.voidsplit(ItemSequence itemSequence, Node node, Node cause)This implementations splitsnodewhen its number of child nodes exceeds the maximum number specified in the constructor.voidsplit(ItemSequence itemSequence, Node node, Property cause)This implementations splitsnodewhen its number of properties exceeds the maximum number specified in the constructor.
 
- 
- 
- 
Constructor Detail- 
BTreeManagerpublic BTreeManager(Node root, int minChildren, int maxChildren, Comparator<String> order, boolean autoSave) throws RepositoryException Create a newBTreeManagerrooted at Noderoot.- Parameters:
- 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 stored
- autoSave- determines whether the current session is saved after add/delete operations.
- Throws:
- RepositoryException
 
 
- 
 - 
Method Detail- 
getIgnoredPropertiespublic Set<String> getIgnoredProperties() Properties to ignore. The default set containsJcrConstants.JCR_PRIMARYTYPEandJcrConstants.JCR_MIXINTYPES.- Specified by:
- getIgnoredPropertiesin interface- TreeManager
- Returns:
 
 - 
splitpublic void split(ItemSequence itemSequence, Node node, Node cause) throws RepositoryException This implementations splitsnodewhen 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.- Specified by:
- splitin interface- TreeManager
- Parameters:
- itemSequence- the- ItemSequencewhere the new node- causehas been inserted.
- node- the parent node of the newly inserted node
- cause- the newly inserted node or- nullif not known.
- Throws:
- RepositoryException
- See Also:
- TreeManager.split(org.apache.jackrabbit.commons.flat.ItemSequence, javax.jcr.Node, javax.jcr.Node)
 
 - 
splitpublic void split(ItemSequence itemSequence, Node node, Property cause) throws RepositoryException This implementations splitsnodewhen 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.- Specified by:
- splitin interface- TreeManager
- Parameters:
- itemSequence- the- ItemSequencewhere the new property- causehas been inserted.
- node- the parent node of the newly inserted property
- cause- the newly inserted property or- nullif not known.
- Throws:
- RepositoryException
- See Also:
- TreeManager.split(org.apache.jackrabbit.commons.flat.ItemSequence, javax.jcr.Node, javax.jcr.Property)
 
 - 
joinpublic void join(ItemSequence itemSequence, Node node, Node cause) throws RepositoryException This implementation does not actually join any nodes. It does however deletenodeifgetNodes(Node)returns an empty iterator. It does further recursively delete any parent ofnodewhich does not have any child node.- Specified by:
- joinin interface- TreeManager
- Parameters:
- itemSequence- the- ItemSequencewhere the node- causehas been deleted from.
- node- the parent node from which- causehas been deleted.
- cause- the deleted node or- nullif not known. Note:- causemight be stale.
- Throws:
- RepositoryException
- See Also:
- TreeManager.join(org.apache.jackrabbit.commons.flat.ItemSequence, javax.jcr.Node, javax.jcr.Node)
 
 - 
joinpublic void join(ItemSequence itemSequence, Node node, Property cause) throws RepositoryException This implementation does not actually join any nodes. It does however deletenodeifgetProperties(Node)returns an empty iterator. It does further recursively delete any parent ofnodewhich does not have any child node.- Specified by:
- joinin interface- TreeManager
- Parameters:
- itemSequence- the- ItemSequencewhere the property- causehas been deleted from.
- node- the parent node from which- causehas been deleted.
- cause- the deleted property or- nullif not known. Note:- causemight be stale.
- Throws:
- RepositoryException
- See Also:
- TreeManager.join(org.apache.jackrabbit.commons.flat.ItemSequence, javax.jcr.Node, javax.jcr.Property)
 
 - 
getRootpublic Node getRoot() - Specified by:
- getRootin interface- TreeManager
- Returns:
- the root node of the JCR sub-tree where the items of the sequence are be mapped to.
 
 - 
isRootpublic boolean isRoot(Node node) throws RepositoryException Description copied from interface:TreeManagerDetermined whether the givennodeis the root node of the JCR sub-tree.- Specified by:
- isRootin interface- TreeManager
- Parameters:
- node- Node to test for root
- Returns:
- getRoot().isSame(node).
- Throws:
- RepositoryException
 
 - 
isLeafpublic boolean isLeaf(Node node) throws RepositoryException Returns!node.hasNodes()- Specified by:
- isLeafin interface- TreeManager
- Parameters:
- node- Node to test for leaf
- Returns:
- trueif- nodeis a leaf node,- falseotherwise.
- Throws:
- RepositoryException
- See Also:
- TreeManager.isLeaf(javax.jcr.Node)
 
 - 
getOrderpublic Comparator<String> getOrder() Description copied from interface:TreeManagerComparatorused for establishing the order of the keys in the sequence.- Specified by:
- getOrderin interface- TreeManager
- Returns:
- a Comparator<String>instance
 
 - 
getAutoSavepublic boolean getAutoSave() Description copied from interface:TreeManagerWhether to automatically save changes of the current session occurring from adding/removing nodes and properties.- Specified by:
- getAutoSavein interface- TreeManager
- Returns:
- trueif changes should be automatically saved,- falseotherwiese.
 
 - 
getNodesprotected SizedIterator<Node> getNodes(Node node) throws RepositoryException Returns aSizedIteratorof the child nodes ofnode.- Throws:
- RepositoryException
 
 - 
getPropertiesprotected SizedIterator<Property> getProperties(Node node) throws RepositoryException - Throws:
- RepositoryException
 
 - 
createIntermediateNodeprotected Node createIntermediateNode(Node parent, String name) throws RepositoryException Creates and return an intermediate node for the givennameas child node ofparent.- Throws:
- RepositoryException
 
 - 
moveprotected void move(Node node, Node parent) throws RepositoryException Movenodeto the newparent.- Throws:
- RepositoryException
 
 - 
moveprotected void move(Property property, Node parent) throws RepositoryException Movepropertyto the newparent.- Throws:
- RepositoryException
 
 - 
getSizedIteratorprotected final <T> SizedIterator<T> getSizedIterator(Iterator<T> iterator, long size) Wrapsiteratorinto aSizedIteratorgiven asize. The value of thesizeparameter must correctly reflect the number of items initerator.
 
- 
 
-