Package org.apache.jackrabbit.core
Class CachingHierarchyManager
- java.lang.Object
-
- org.apache.jackrabbit.core.HierarchyManagerImpl
-
- org.apache.jackrabbit.core.CachingHierarchyManager
-
- All Implemented Interfaces:
HierarchyManager,ItemStateListener,NodeStateListener
public class CachingHierarchyManager extends HierarchyManagerImpl implements NodeStateListener
Implementation of aHierarchyManagerthat caches paths of items.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.jackrabbit.core.HierarchyManagerImpl
HierarchyManagerImpl.CycleDetector
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_UPPER_LIMITDefault upper limit of cached states-
Fields inherited from class org.apache.jackrabbit.core.HierarchyManagerImpl
provider, rootNodeId
-
-
Constructor Summary
Constructors Constructor Description CachingHierarchyManager(NodeId rootNodeId, ItemStateManager provider)Create a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildPath(PathBuilder builder, ItemState state, HierarchyManagerImpl.CycleDetector detector)Adds the path element of an item id to the path currently being built.voidenableConsistencyChecks(boolean enable)Enable or disable consistency checks in this instance.intgetDepth(ItemId id)Returns the depth of the specified item which is equivalent togetPath(id).getAncestorCount().NamegetName(ItemId id)Returns the name of the specified item.PathgetPath(ItemId id)Returns the path to the given item.booleanisAncestor(NodeId nodeId, ItemId itemId)Determines whether the node with the specifiednodeIdis an ancestor of the item denoted by the givenitemId.voidnodeAdded(NodeState state, Name name, int index, NodeId id)Called when a child node has been addedvoidnodeModified(NodeState modified)Called when a node has been modified, typically as a result of removal or addition of a child node.voidnodeRemoved(NodeState state, Name name, int index, NodeId id)Called when a child node has been removedvoidnodesReplaced(NodeState state)Called when the children nodes were replaced by other nodes, typically as result of a reorder operation.protected voidpathResolved(ItemId id, PathBuilder builder)protected ItemIdresolvePath(Path path, int typesAllowed)Internal implementation ofHierarchyManagerImpl.resolvePath(Path)that will either resolve to a node or a property.voidstateCreated(ItemState created)Called when anItemStatehas successfully been created (i.e.voidstateDestroyed(ItemState destroyed)Called when anItemStatehas successfully been removed (i.e.voidstateDiscarded(ItemState discarded)Called when anItemStatehas been discarded (i.e.voidstateModified(ItemState modified)Called when anItemStatehas successfully been modified (i.e.StringtoString()Dump contents of path map and elements included to a string.-
Methods inherited from class org.apache.jackrabbit.core.HierarchyManagerImpl
getChildNodeEntry, getChildNodeEntry, getItemState, getName, getParentId, getParentIds, getRelativeDepth, getRootNodeId, getShareRelativeDepth, hasItemState, isShareAncestor, resolveNodePath, resolvePath, resolvePath, resolvePropertyPath
-
-
-
-
Field Detail
-
DEFAULT_UPPER_LIMIT
public static final int DEFAULT_UPPER_LIMIT
Default upper limit of cached states- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CachingHierarchyManager
public CachingHierarchyManager(NodeId rootNodeId, ItemStateManager provider)
Create a new instance of this class.- Parameters:
rootNodeId- root node idprovider- item state manager
-
-
Method Detail
-
enableConsistencyChecks
public void enableConsistencyChecks(boolean enable)
Enable or disable consistency checks in this instance.- Parameters:
enable-trueto enable consistency checks;falseto disable
-
resolvePath
protected ItemId resolvePath(Path path, int typesAllowed) throws RepositoryException
Internal implementation ofHierarchyManagerImpl.resolvePath(Path)that will either resolve to a node or a property. Should be overridden by a subclass that can resolve an intermediate path into anItemId. This subclass can then invokeHierarchyManagerImpl.resolvePath(org.apache.jackrabbit.spi.Path.Element[], int, ItemId, int)with a value ofnextgreater than1.- Overrides:
resolvePathin classHierarchyManagerImpl- Parameters:
path- path to resolvetypesAllowed- one ofRETURN_ANY,RETURN_NODEorRETURN_PROPERTY- Returns:
- id or
null - Throws:
RepositoryException- if an error occurs
-
pathResolved
protected void pathResolved(ItemId id, PathBuilder builder) throws MalformedPathException
Called byHierarchyManagerImpl.resolvePath(org.apache.jackrabbit.spi.Path.Element[], int, ItemId, int). May be overridden by some subclass to process/cache intermediate state.- Overrides:
pathResolvedin classHierarchyManagerImpl- Parameters:
id- id of resolved itembuilder- path builder containing path resolved- Throws:
MalformedPathException- if the path contained inbuilderis malformed
-
buildPath
protected void buildPath(PathBuilder builder, ItemState state, HierarchyManagerImpl.CycleDetector detector) throws ItemStateException, RepositoryException
Adds the path element of an item id to the path currently being built. Recursively invoked method that may be overridden by some subclass to either return cached responses or add response to cache. On exit,buildercontains the path ofstate.Overridden method tries to find a mapping for the intermediate item
stateand add its path elements to the builder currently being used. If no mapping is found, the item is cached instead after the base implementation has been invoked.- Overrides:
buildPathin classHierarchyManagerImpl- Parameters:
builder- builder currently being usedstate- item to find path ofdetector- path cycle detector- Throws:
ItemStateExceptionRepositoryException
-
getPath
public Path getPath(ItemId id) throws ItemNotFoundException, RepositoryException
Returns the path to the given item.Overridden method simply checks whether we have an item matching the id and returns its path, otherwise calls base implementation.
- Specified by:
getPathin interfaceHierarchyManager- Overrides:
getPathin classHierarchyManagerImpl- Returns:
- Throws:
ItemNotFoundExceptionRepositoryException
-
getName
public Name getName(ItemId id) throws ItemNotFoundException, RepositoryException
Returns the name of the specified item.- Specified by:
getNamein interfaceHierarchyManager- Overrides:
getNamein classHierarchyManagerImpl- Parameters:
id- id of item whose name should be returned- Returns:
- Throws:
ItemNotFoundExceptionRepositoryException
-
getDepth
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException
Returns the depth of the specified item which is equivalent togetPath(id).getAncestorCount(). The depth reflects the absolute hierarchy level.- Specified by:
getDepthin interfaceHierarchyManager- Overrides:
getDepthin classHierarchyManagerImpl- Parameters:
id- item id- Returns:
- the depth of the specified item
- Throws:
ItemNotFoundException- if the specifiediddoes not denote an existing item.RepositoryException- if another error occurs
-
isAncestor
public boolean isAncestor(NodeId nodeId, ItemId itemId) throws ItemNotFoundException, RepositoryException
Determines whether the node with the specifiednodeIdis an ancestor of the item denoted by the givenitemId. This is equivalent togetPath(nodeId).isAncestorOf(getPath(itemId)).- Specified by:
isAncestorin interfaceHierarchyManager- Overrides:
isAncestorin classHierarchyManagerImpl- Parameters:
nodeId- node iditemId- item id- Returns:
trueif the node with the specifiednodeIdis an ancestor of the item denoted by the givenitemId;falseotherwise- Throws:
ItemNotFoundException- if any of the specified id's does not denote an existing item.RepositoryException- if another error occurs
-
stateCreated
public void stateCreated(ItemState created)
Called when anItemStatehas successfully been created (i.e. its underlying persistent state was created).- Specified by:
stateCreatedin interfaceItemStateListener- Parameters:
created- theItemStatethat has been 'created'
-
stateModified
public void stateModified(ItemState modified)
Called when anItemStatehas successfully been modified (i.e. its underlying persistent state has changed).- Specified by:
stateModifiedin interfaceItemStateListener- Parameters:
modified- theItemStatethat has been 'modified'
-
nodeModified
public void nodeModified(NodeState modified)
Called when a node has been modified, typically as a result of removal or addition of a child node.Please note, that this method is not called if
ItemStateListener.stateModified(ItemState)was called. If path information is cached formodified, this iterates over all child nodes in the path map, evicting the ones that do not (longer) exist in the underlyingNodeState.- Specified by:
nodeModifiedin interfaceNodeStateListener- Parameters:
modified- node state that changed
-
stateDestroyed
public void stateDestroyed(ItemState destroyed)
Called when anItemStatehas successfully been removed (i.e. its underlying persistent state has been destroyed).- Specified by:
stateDestroyedin interfaceItemStateListener- Parameters:
destroyed- theItemStatethat has been 'destroyed'
-
stateDiscarded
public void stateDiscarded(ItemState discarded)
Called when anItemStatehas been discarded (i.e. it has been rendered 'invalid').- Specified by:
stateDiscardedin interfaceItemStateListener- Parameters:
discarded- theItemStatethat has been discarded- See Also:
ItemState.discard()
-
nodeAdded
public void nodeAdded(NodeState state, Name name, int index, NodeId id)
Called when a child node has been added- Specified by:
nodeAddedin interfaceNodeStateListener- Parameters:
state- node state that changedname- name of node that was addedindex- index of new nodeid- id of new node
-
nodesReplaced
public void nodesReplaced(NodeState state)
Called when the children nodes were replaced by other nodes, typically as result of a reorder operation.Iterate over all cached children of this state and verify each child's position.
- Specified by:
nodesReplacedin interfaceNodeStateListener- Parameters:
state- node state that changed
-
nodeRemoved
public void nodeRemoved(NodeState state, Name name, int index, NodeId id)
Called when a child node has been removed- Specified by:
nodeRemovedin interfaceNodeStateListener- Parameters:
state- node state that changedname- name of node that was removedindex- index of removed nodeid- id of removed node
-
-