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 aHierarchyManager
that 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 int
DEFAULT_UPPER_LIMIT
Default 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 void
buildPath(PathBuilder builder, ItemState state, HierarchyManagerImpl.CycleDetector detector)
Adds the path element of an item id to the path currently being built.void
enableConsistencyChecks(boolean enable)
Enable or disable consistency checks in this instance.int
getDepth(ItemId id)
Returns the depth of the specified item which is equivalent togetPath(id).getAncestorCount()
.Name
getName(ItemId id)
Returns the name of the specified item.Path
getPath(ItemId id)
Returns the path to the given item.boolean
isAncestor(NodeId nodeId, ItemId itemId)
Determines whether the node with the specifiednodeId
is an ancestor of the item denoted by the givenitemId
.void
nodeAdded(NodeState state, Name name, int index, NodeId id)
Called when a child node has been addedvoid
nodeModified(NodeState modified)
Called when a node has been modified, typically as a result of removal or addition of a child node.void
nodeRemoved(NodeState state, Name name, int index, NodeId id)
Called when a child node has been removedvoid
nodesReplaced(NodeState state)
Called when the children nodes were replaced by other nodes, typically as result of a reorder operation.protected void
pathResolved(ItemId id, PathBuilder builder)
protected ItemId
resolvePath(Path path, int typesAllowed)
Internal implementation ofHierarchyManagerImpl.resolvePath(Path)
that will either resolve to a node or a property.void
stateCreated(ItemState created)
Called when anItemState
has successfully been created (i.e.void
stateDestroyed(ItemState destroyed)
Called when anItemState
has successfully been removed (i.e.void
stateDiscarded(ItemState discarded)
Called when anItemState
has been discarded (i.e.void
stateModified(ItemState modified)
Called when anItemState
has successfully been modified (i.e.String
toString()
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
-true
to enable consistency checks;false
to 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 ofnext
greater than1
.- Overrides:
resolvePath
in classHierarchyManagerImpl
- Parameters:
path
- path to resolvetypesAllowed
- one ofRETURN_ANY
,RETURN_NODE
orRETURN_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:
pathResolved
in classHierarchyManagerImpl
- Parameters:
id
- id of resolved itembuilder
- path builder containing path resolved- Throws:
MalformedPathException
- if the path contained inbuilder
is 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,builder
contains the path ofstate
.Overridden method tries to find a mapping for the intermediate item
state
and 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:
buildPath
in classHierarchyManagerImpl
- Parameters:
builder
- builder currently being usedstate
- item to find path ofdetector
- path cycle detector- Throws:
ItemStateException
RepositoryException
-
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:
getPath
in interfaceHierarchyManager
- Overrides:
getPath
in classHierarchyManagerImpl
- Returns:
- Throws:
ItemNotFoundException
RepositoryException
-
getName
public Name getName(ItemId id) throws ItemNotFoundException, RepositoryException
Returns the name of the specified item.- Specified by:
getName
in interfaceHierarchyManager
- Overrides:
getName
in classHierarchyManagerImpl
- Parameters:
id
- id of item whose name should be returned- Returns:
- Throws:
ItemNotFoundException
RepositoryException
-
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:
getDepth
in interfaceHierarchyManager
- Overrides:
getDepth
in classHierarchyManagerImpl
- Parameters:
id
- item id- Returns:
- the depth of the specified item
- Throws:
ItemNotFoundException
- if the specifiedid
does 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 specifiednodeId
is an ancestor of the item denoted by the givenitemId
. This is equivalent togetPath(nodeId).isAncestorOf(getPath(itemId))
.- Specified by:
isAncestor
in interfaceHierarchyManager
- Overrides:
isAncestor
in classHierarchyManagerImpl
- Parameters:
nodeId
- node iditemId
- item id- Returns:
true
if the node with the specifiednodeId
is an ancestor of the item denoted by the givenitemId
;false
otherwise- 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 anItemState
has successfully been created (i.e. its underlying persistent state was created).- Specified by:
stateCreated
in interfaceItemStateListener
- Parameters:
created
- theItemState
that has been 'created'
-
stateModified
public void stateModified(ItemState modified)
Called when anItemState
has successfully been modified (i.e. its underlying persistent state has changed).- Specified by:
stateModified
in interfaceItemStateListener
- Parameters:
modified
- theItemState
that 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:
nodeModified
in interfaceNodeStateListener
- Parameters:
modified
- node state that changed
-
stateDestroyed
public void stateDestroyed(ItemState destroyed)
Called when anItemState
has successfully been removed (i.e. its underlying persistent state has been destroyed).- Specified by:
stateDestroyed
in interfaceItemStateListener
- Parameters:
destroyed
- theItemState
that has been 'destroyed'
-
stateDiscarded
public void stateDiscarded(ItemState discarded)
Called when anItemState
has been discarded (i.e. it has been rendered 'invalid').- Specified by:
stateDiscarded
in interfaceItemStateListener
- Parameters:
discarded
- theItemState
that 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:
nodeAdded
in 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:
nodesReplaced
in 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:
nodeRemoved
in interfaceNodeStateListener
- Parameters:
state
- node state that changedname
- name of node that was removedindex
- index of removed nodeid
- id of removed node
-
-