Class SessionItemStateManager
- java.lang.Object
-
- org.apache.jackrabbit.core.state.SessionItemStateManager
-
- All Implemented Interfaces:
ItemStateListener
,ItemStateManager
,NodeStateListener
,UpdatableItemStateManager
public class SessionItemStateManager extends Object implements UpdatableItemStateManager, NodeStateListener
Item state manager that handles both transient and persistent items.
-
-
Constructor Summary
Constructors Constructor Description SessionItemStateManager(NodeId rootNodeId, LocalItemStateManager stateMgr)
Creates a newSessionItemStateManager
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ItemStateListener listener)
Add anItemStateListener
void
cancel()
Cancel an update operation.NodeState
createNew(NodeId id, Name nodeTypeName, NodeId parentId)
Creates aNodeState
instance representing new, i.e.PropertyState
createNew(PropertyState transientState)
Customized variant ofcreateNew(Name, NodeId)
that connects the newly created persistent state with the transient state.PropertyState
createNew(Name propName, NodeId parentId)
Creates aPropertyState
instance representing new, i.e.NodeState
createTransientNodeState(NodeId id, Name nodeTypeName, NodeId parentId, int initialStatus)
NodeState
createTransientNodeState(NodeState overlayedState, int initialStatus)
PropertyState
createTransientPropertyState(NodeId parentId, Name propName, int initialStatus)
PropertyState
createTransientPropertyState(PropertyState overlayedState, int initialStatus)
void
destroy(ItemState state)
Destroy an item state.void
disconnectTransientItemState(ItemState state)
Disconnect a transient item state from its underlying persistent state.void
dispose()
Disposes thisUpdatableItemStateManager
and frees resources.void
disposeAllTransientItemStates()
Disposes all transient item states in the cache and in the attic.void
disposeTransientItemState(ItemState state)
Disposes the specified transient item state instance, i.e.void
disposeTransientItemStateInAttic(ItemState state)
Disposes the specified transient item state instance in the attic, i.e.void
edit()
Start an edit operation on items inside this manager.ItemStateManager
getAttic()
Return the attic item state provider that holds all items moved into the attic.HierarchyManager
getAtticAwareHierarchyMgr()
Returns an attic-aware hierarchy manager, i.e.Collection<ItemState>
getDescendantTransientItemStates(ItemId id)
Returns a collection of those transient item state instances that are direct or indirect descendants of the item state with the given parent.Iterable<ItemState>
getDescendantTransientItemStatesInAttic(ItemId id)
Same as
except that item state instances in the attic are returned.getDescendantTransientItemStates(ItemId)
HierarchyManager
getHierarchyMgr()
Returns the hierarchy managerNodeId
getIdOfRootTransientNodeState()
Returns the id of the root of the minimal subtree including all transient states.ItemState
getItemState(ItemId id)
Return an item state, given its item id.NodeReferences
getNodeReferences(NodeId id)
Return a node references object, given its target idItemState
getTransientItemState(ItemId id)
boolean
hasAnyTransientItemStates()
boolean
hasItemState(ItemId id)
Return a flag indicating whether an item state for a given item id exists.boolean
hasNodeReferences(NodeId id)
Return a flag indicating whether a node references object for a given target id exists.boolean
hasTransientItemState(ItemId id)
boolean
hasTransientItemStateInAttic(ItemId id)
boolean
inEditMode()
Returnstrue
if this manager is in edit mode i.e.boolean
isItemStateInAttic(ItemId id)
Return a flag indicating whether the specified item is in the transient item state manager's attic space.NodeState
makePersistent(NodeState transientState)
Pushes the given transient state to the change log so it'll be persisted when the change log is committed.void
moveTransientItemStateToAttic(ItemState state)
Transfers the specified transient item state instance from the 'active' cache to the attic.void
nodeAdded(NodeState state, Name name, int index, NodeId id)
Called when a child node has been addedvoid
nodeModified(NodeState state)
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.void
removeListener(ItemStateListener listener)
Remove anItemStateListener
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.void
store(ItemState state)
Store an item state.String
toString()
void
update()
End an update operation.
-
-
-
Constructor Detail
-
SessionItemStateManager
public SessionItemStateManager(NodeId rootNodeId, LocalItemStateManager stateMgr)
Creates a newSessionItemStateManager
instance.- Parameters:
rootNodeId
- the root node idstateMgr
- the local item state manager
-
-
Method Detail
-
getHierarchyMgr
public HierarchyManager getHierarchyMgr()
Returns the hierarchy manager- Returns:
- the hierarchy manager
-
getAtticAwareHierarchyMgr
public HierarchyManager getAtticAwareHierarchyMgr()
Returns an attic-aware hierarchy manager, i.e. an hierarchy manager that is also able to build/resolve paths of those items that have been moved or removed (i.e. moved to the attic).- Returns:
- an attic-aware hierarchy manager
-
getItemState
public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
Return an item state, given its item id.- Specified by:
getItemState
in interfaceItemStateManager
- Parameters:
id
- item id- Returns:
- item state
- Throws:
NoSuchItemStateException
- if the item does not existItemStateException
- if an error occurs
-
hasItemState
public boolean hasItemState(ItemId id)
Return a flag indicating whether an item state for a given item id exists.- Specified by:
hasItemState
in interfaceItemStateManager
- Parameters:
id
- item id- Returns:
true
if an item state exists, otherwisefalse
-
getNodeReferences
public NodeReferences getNodeReferences(NodeId id) throws NoSuchItemStateException, ItemStateException
Return a node references object, given its target id- Specified by:
getNodeReferences
in interfaceItemStateManager
- Parameters:
id
- target id- Returns:
- node references object
- Throws:
NoSuchItemStateException
- if the item does not existItemStateException
- if an error occurs
-
hasNodeReferences
public boolean hasNodeReferences(NodeId id)
Return a flag indicating whether a node references object for a given target id exists.- Specified by:
hasNodeReferences
in interfaceItemStateManager
- Parameters:
id
- target id- Returns:
true
if a node reference object exists for the given id, otherwisefalse
.
-
edit
public void edit() throws IllegalStateException
Start an edit operation on items inside this manager. This allows calling the operations defined below. At the end of this operation, eitherUpdatableItemStateManager.update()
orUpdatableItemStateManager.cancel()
must be invoked.- Specified by:
edit
in interfaceUpdatableItemStateManager
- Throws:
IllegalStateException
- if the manager is already in edit mode.
-
inEditMode
public boolean inEditMode()
Returnstrue
if this manager is in edit mode i.e. if an edit operation has been started by invokingUpdatableItemStateManager.edit()
, otherwise returnsfalse
.- Specified by:
inEditMode
in interfaceUpdatableItemStateManager
- Returns:
true
if this manager is in edit mode, otherwisefalse
-
createNew
public NodeState createNew(NodeId id, Name nodeTypeName, NodeId parentId) throws RepositoryException
Creates aNodeState
instance representing new, i.e. not yet existing state. CallUpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState)
on the returned object to make it persistent.- Specified by:
createNew
in interfaceUpdatableItemStateManager
- Parameters:
id
- the id of the node, ornull
for a new node idnodeTypeName
- The node type nameparentId
- parent node's id- Returns:
- a node state
- Throws:
RepositoryException
- if the node state can not be created
-
createNew
public PropertyState createNew(Name propName, NodeId parentId) throws IllegalStateException
Creates aPropertyState
instance representing new, i.e. not yet existing state. CallUpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState)
on the returned object to make it persistent.- Specified by:
createNew
in interfaceUpdatableItemStateManager
- Parameters:
propName
- property nameparentId
- parent node Id- Returns:
- a property state
- Throws:
IllegalStateException
- if the manager is not in edit mode.
-
createNew
public PropertyState createNew(PropertyState transientState) throws ItemStateException
Customized variant ofcreateNew(Name, NodeId)
that connects the newly created persistent state with the transient state.- Throws:
ItemStateException
-
store
public void store(ItemState state) throws IllegalStateException
Store an item state.- Specified by:
store
in interfaceUpdatableItemStateManager
- Parameters:
state
- item state that should be stored- Throws:
IllegalStateException
- if the manager is not in edit mode.
-
destroy
public void destroy(ItemState state) throws IllegalStateException
Destroy an item state.- Specified by:
destroy
in interfaceUpdatableItemStateManager
- Parameters:
state
- item state that should be destroyed- Throws:
IllegalStateException
- if the manager is not in edit mode.
-
cancel
public void cancel() throws IllegalStateException
Cancel an update operation. This will undo all changes made to objects inside this item state manager.- Specified by:
cancel
in interfaceUpdatableItemStateManager
- Throws:
IllegalStateException
- if the manager is not in edit mode.
-
update
public void update() throws ReferentialIntegrityException, StaleItemStateException, ItemStateException, IllegalStateException
End an update operation. This will save all items added to this update operation in a single step. If this operation fails, no item will have been saved.- Specified by:
update
in interfaceUpdatableItemStateManager
- Throws:
ReferentialIntegrityException
- if a new or modified REFERENCE property refers to a non-existent target or if a removed node is still being referencedStaleItemStateException
- if at least one of the affected items has become stale in the meantimeItemStateException
- if the operation failed for another reasonIllegalStateException
- if the manager is not in edit mode.
-
dispose
public void dispose()
Disposes thisUpdatableItemStateManager
and frees resources.- Specified by:
dispose
in interfaceUpdatableItemStateManager
-
getTransientItemState
public ItemState getTransientItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
- Parameters:
id
-- Returns:
- Throws:
NoSuchItemStateException
ItemStateException
-
hasTransientItemState
public boolean hasTransientItemState(ItemId id)
- Parameters:
id
-- Returns:
-
hasTransientItemStateInAttic
public boolean hasTransientItemStateInAttic(ItemId id)
- Parameters:
id
-- Returns:
-
hasAnyTransientItemStates
public boolean hasAnyTransientItemStates()
- Returns:
true
if this manager has any transient state;false
otherwise.
-
getDescendantTransientItemStates
public Collection<ItemState> getDescendantTransientItemStates(ItemId id) throws InvalidItemStateException, RepositoryException
Returns a collection of those transient item state instances that are direct or indirect descendants of the item state with the given parent. The transient item state instance with the given identifier itself (if there is such) will not be included.The instances are returned in depth-first tree traversal order.
- Parameters:
id
- identifier of the common parent of the transient item state instances to be returned- Returns:
- collection of descendant transient item state instances
- Throws:
InvalidItemStateException
- if any descendant item state has been deleted externallyRepositoryException
- if another error occurs
-
getDescendantTransientItemStatesInAttic
public Iterable<ItemState> getDescendantTransientItemStatesInAttic(ItemId id) throws RepositoryException
Same as
except that item state instances in the attic are returned.getDescendantTransientItemStates(ItemId)
- Parameters:
id
- identifier of the common parent of the transient item state instances to be returned- Returns:
- collection of descendant transient item state instances in the attic
- Throws:
RepositoryException
-
getIdOfRootTransientNodeState
public NodeId getIdOfRootTransientNodeState() throws RepositoryException
Returns the id of the root of the minimal subtree including all transient states.- Returns:
- id of nearest common ancestor of all transient states or null if there's no transient state.
- Throws:
RepositoryException
- if an error occurs
-
isItemStateInAttic
public boolean isItemStateInAttic(ItemId id)
Return a flag indicating whether the specified item is in the transient item state manager's attic space.- Parameters:
id
- item id- Returns:
true
if the item state is in the attic space;false
otherwise
-
createTransientNodeState
public NodeState createTransientNodeState(NodeId id, Name nodeTypeName, NodeId parentId, int initialStatus) throws RepositoryException
- Parameters:
id
-nodeTypeName
-parentId
-initialStatus
-- Returns:
- Throws:
RepositoryException
-
createTransientNodeState
public NodeState createTransientNodeState(NodeState overlayedState, int initialStatus) throws ItemStateException
- Parameters:
overlayedState
-initialStatus
-- Returns:
- Throws:
ItemStateException
-
createTransientPropertyState
public PropertyState createTransientPropertyState(NodeId parentId, Name propName, int initialStatus) throws ItemStateException
- Parameters:
parentId
-propName
-initialStatus
-- Returns:
- Throws:
ItemStateException
-
createTransientPropertyState
public PropertyState createTransientPropertyState(PropertyState overlayedState, int initialStatus) throws ItemStateException
- Parameters:
overlayedState
-initialStatus
-- Returns:
- Throws:
ItemStateException
-
disconnectTransientItemState
public void disconnectTransientItemState(ItemState state)
Disconnect a transient item state from its underlying persistent state. Notifies theHierarchyManager
about the changed identity.- Parameters:
state
- the transientItemState
instance that should be disconnected
-
disposeTransientItemState
public void disposeTransientItemState(ItemState state)
Disposes the specified transient item state instance, i.e. discards it and clears it from cache.- Parameters:
state
- the transientItemState
instance that should be disposed- See Also:
ItemState.discard()
-
moveTransientItemStateToAttic
public void moveTransientItemStateToAttic(ItemState state)
Transfers the specified transient item state instance from the 'active' cache to the attic.- Parameters:
state
- the transientItemState
instance that should be moved to the attic
-
disposeTransientItemStateInAttic
public void disposeTransientItemStateInAttic(ItemState state)
Disposes the specified transient item state instance in the attic, i.e. discards it and removes it from the attic.- Parameters:
state
- the transientItemState
instance that should be disposed @see ItemState#discard()
-
disposeAllTransientItemStates
public void disposeAllTransientItemStates()
Disposes all transient item states in the cache and in the attic.
-
addListener
public void addListener(ItemStateListener listener)
Add anItemStateListener
- Parameters:
listener
- the new listener to be informed on modifications
-
removeListener
public void removeListener(ItemStateListener listener)
Remove anItemStateListener
- Parameters:
listener
- an existing listener
-
getAttic
public ItemStateManager getAttic()
Return the attic item state provider that holds all items moved into the attic.- Returns:
- attic
-
stateCreated
public void stateCreated(ItemState created)
Called when anItemState
has successfully been created (i.e. its underlying persistent state was created).Notification handler gets called for both transient states that this state manager has created, as well as states that were created by the local state manager we're listening to.
- 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).Notification handler gets called for both transient states that this state manager has created, as well as states that were created by the local state manager we're listening to.
- Specified by:
stateModified
in interfaceItemStateListener
- Parameters:
modified
- theItemState
that has been 'modified'
-
stateDestroyed
public void stateDestroyed(ItemState destroyed)
Called when anItemState
has successfully been removed (i.e. its underlying persistent state has been destroyed).Notification handler gets called for both transient states that this state manager has created, as well as states that were created by the local state manager we're listening to.
- 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').Notification handler gets called for both transient states that this state manager has created, as well as states that were created by the local state manager we're listening to.
- 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 addedPass notification to listeners if a transient state was modified or if the local state is not overlayed.
- 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.Pass notification to listeners if a transient state was modified or if the local state is not overlayed.
- Specified by:
nodesReplaced
in interfaceNodeStateListener
- Parameters:
state
- node state that changed
-
nodeModified
public void nodeModified(NodeState state)
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.Pass notification to listeners if a transient state was modified or if the local state is not overlayed.
- Specified by:
nodeModified
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 removedPass notification to listeners if a transient state was modified or if the local state is not overlayed.
- 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
-
makePersistent
public NodeState makePersistent(NodeState transientState) throws RepositoryException
Pushes the given transient state to the change log so it'll be persisted when the change log is committed. The transient state is replaced with the local state that has been pushed to the change log.- Parameters:
transientState
- transient state- Returns:
- the local state to be persisted
- Throws:
RepositoryException
- if the transiet state can not be persisted
-
-