Class LocalItemStateManager
- java.lang.Object
-
- org.apache.jackrabbit.core.state.LocalItemStateManager
-
- All Implemented Interfaces:
ItemStateListener,ItemStateManager,NodeStateListener,UpdatableItemStateManager
- Direct Known Subclasses:
XAItemStateManager
public class LocalItemStateManager extends Object implements UpdatableItemStateManager, NodeStateListener
LocalItemStateManagerthat isolates changes to persistent states from other clients.
-
-
Field Summary
Fields Modifier and Type Field Description protected EventStateCollectionFactoryfactoryEvent state collection factory.protected SharedItemStateManagersharedStateMgrShared item state manager
-
Constructor Summary
Constructors Modifier Constructor Description protectedLocalItemStateManager(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, ItemStateCacheFactory cacheFactory)Creates a newLocalItemStateManagerinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(ItemStateListener listener)Add anItemStateListenervoidcancel()Cancel an update operation.static LocalItemStateManagercreateInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, ItemStateCacheFactory cacheFactory)Creates a newLocalItemStateManagerinstance and registers it as anItemStateListenerwith the givenSharedItemStateManager.NodeStatecreateNew(NodeId id, Name nodeTypeName, NodeId parentId)Creates aNodeStateinstance representing new, i.e.PropertyStatecreateNew(Name propName, NodeId parentId)Creates aPropertyStateinstance representing new, i.e.voiddestroy(ItemState state)Destroy an item state.voiddispose()Disposes thisUpdatableItemStateManagerand frees resources.voidedit()Start an edit operation on items inside this manager.protected ChangeLoggetChanges()Returns the change log that contains the current changes in this local item state manager.ItemStategetItemState(ItemId id)Return an item state, given its item id.NodeIdFactorygetNodeIdFactory()NodeReferencesgetNodeReferences(NodeId id)Return a node references object, given its target idprotected NodeStategetNodeState(NodeId id)Retrieve a node state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.NodeStategetOrCreateLocalState(NodeState transientState)Returns the local node state below the given transient one.protected PropertyStategetPropertyState(PropertyId id)Retrieve a property state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.booleanhasItemState(ItemId id)Return a flag indicating whether an item state for a given item id exists.booleanhasNodeReferences(NodeId id)Return a flag indicating whether a node references object for a given target id exists.booleaninEditMode()Returnstrueif this manager is in edit mode i.e.voidnodeAdded(NodeState state, Name name, int index, NodeId id)Called when a child node has been addedvoidnodeModified(NodeState state)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.voidremoveListener(ItemStateListener listener)Remove anItemStateListenervoidstateCreated(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.voidstore(ItemState state)Store an item state.voidupdate()End an update operation.protected voidupdate(ChangeLog changeLog)End an update operation.
-
-
-
Field Detail
-
sharedStateMgr
protected final SharedItemStateManager sharedStateMgr
Shared item state manager
-
factory
protected final EventStateCollectionFactory factory
Event state collection factory.
-
-
Constructor Detail
-
LocalItemStateManager
protected LocalItemStateManager(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, ItemStateCacheFactory cacheFactory)
Creates a newLocalItemStateManagerinstance.- Parameters:
sharedStateMgr- shared state managerfactory- event state collection factory
-
-
Method Detail
-
createInstance
public static LocalItemStateManager createInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, ItemStateCacheFactory cacheFactory)
Creates a newLocalItemStateManagerinstance and registers it as anItemStateListenerwith the givenSharedItemStateManager.- Parameters:
sharedStateMgr- theSharedItemStateManagerfactory- theEventStateCollectionFactorycacheFactory- theItemStateCacheFactory- Returns:
- a new
LocalItemStateManagerinstance
-
getNodeState
protected NodeState getNodeState(NodeId id) throws NoSuchItemStateException, ItemStateException
Retrieve a node state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.- Parameters:
id- node id- Returns:
- node state
- Throws:
NoSuchItemStateExceptionItemStateException
-
getPropertyState
protected PropertyState getPropertyState(PropertyId id) throws NoSuchItemStateException, ItemStateException
Retrieve a property state from the parent shared state manager and wraps it into a intermediate object that helps us handle local modifications.- Parameters:
id- property id- Returns:
- property state
- Throws:
NoSuchItemStateExceptionItemStateException
-
getChanges
protected ChangeLog getChanges()
Returns the change log that contains the current changes in this local item state manager.- Returns:
- the change log with the current changes.
-
getItemState
public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
Return an item state, given its item id.- Specified by:
getItemStatein 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:
hasItemStatein interfaceItemStateManager- Parameters:
id- item id- Returns:
trueif 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:
getNodeReferencesin 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:
hasNodeReferencesin interfaceItemStateManager- Parameters:
id- target id- Returns:
trueif a node reference object exists for the given id, otherwisefalse.
-
edit
public void edit() throws IllegalStateExceptionStart 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:
editin interfaceUpdatableItemStateManager- Throws:
IllegalStateException- if the manager is already in edit mode.
-
inEditMode
public boolean inEditMode()
Returnstrueif this manager is in edit mode i.e. if an edit operation has been started by invokingUpdatableItemStateManager.edit(), otherwise returnsfalse.- Specified by:
inEditModein interfaceUpdatableItemStateManager- Returns:
trueif this manager is in edit mode, otherwisefalse
-
createNew
public NodeState createNew(NodeId id, Name nodeTypeName, NodeId parentId) throws RepositoryException
Creates aNodeStateinstance 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:
createNewin interfaceUpdatableItemStateManager- Parameters:
id- the id of the node, ornullfor 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
-
getOrCreateLocalState
public NodeState getOrCreateLocalState(NodeState transientState) throws RepositoryException
Returns the local node state below the given transient one. If given a fresh new node state, then a new local state is created and added to the change log.- Parameters:
transientState- transient state- Returns:
- local node state
- Throws:
RepositoryException- if the local state could not be created
-
createNew
public PropertyState createNew(Name propName, NodeId parentId) throws IllegalStateException
Creates aPropertyStateinstance 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:
createNewin interfaceUpdatableItemStateManager- Parameters:
propName- property nameparentId- parent node Id- Returns:
- a property state
- Throws:
IllegalStateException- if the manager is not in edit mode.
-
store
public void store(ItemState state) throws IllegalStateException
Store an item state.- Specified by:
storein 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:
destroyin interfaceUpdatableItemStateManager- Parameters:
state- item state that should be destroyed- Throws:
IllegalStateException- if the manager is not in edit mode.
-
cancel
public void cancel() throws IllegalStateExceptionCancel an update operation. This will undo all changes made to objects inside this item state manager.- Specified by:
cancelin interfaceUpdatableItemStateManager- Throws:
IllegalStateException- if the manager is not in edit mode.
-
update
public void update() throws ReferentialIntegrityException, StaleItemStateException, ItemStateException, IllegalStateExceptionEnd 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:
updatein 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.
-
update
protected void update(ChangeLog changeLog) throws ReferentialIntegrityException, StaleItemStateException, ItemStateException
End an update operation. Fetch the states and references from the parent (shared) item manager, reconnect them to the items collected in our (local) change log and overwrite the shared items with our copies.- Parameters:
changeLog- change log containing local states and references- 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 item states has become stale in the meantimeItemStateException- if an error occurs
-
dispose
public void dispose()
Disposes thisUpdatableItemStateManagerand frees resources.- Specified by:
disposein interfaceUpdatableItemStateManager
-
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
-
stateCreated
public void stateCreated(ItemState created)
Called when anItemStatehas successfully been created (i.e. its underlying persistent state was created).Notification handler gets called for both local states that this state manager has created, as well as states that were created by the shared state manager we're listening to.
- 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).Notification handler gets called for both local states that this state manager has created, as well as states that were created by the shared state manager we're listening to.
- Specified by:
stateModifiedin interfaceItemStateListener- Parameters:
modified- theItemStatethat has been 'modified'
-
stateDestroyed
public void stateDestroyed(ItemState destroyed)
Called when anItemStatehas successfully been removed (i.e. its underlying persistent state has been destroyed).Notification handler gets called for both local states that this state manager has created, as well as states that were created by the shared state manager we're listening to.
- 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').Notification handler gets called for both local states that this state manager has created, as well as states that were created by the shared state manager we're listening to.
- 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 addedOptimization: shared state manager we're listening to does not deliver node state changes, therefore the state concerned must be a local state.
- 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.Optimization: shared state manager we're listening to does not deliver node state changes, therefore the state concerned must be a local state.
- Specified by:
nodesReplacedin 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.Optimization: shared state manager we're listening to does not deliver node state changes, therefore the state concerned must be a local state.
- Specified by:
nodeModifiedin 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 removedOptimization: shared state manager we're listening to does not deliver node state changes, therefore the state concerned must be a local state.
- Specified by:
nodeRemovedin interfaceNodeStateListener- Parameters:
state- node state that changedname- name of node that was removedindex- index of removed nodeid- id of removed node
-
getNodeIdFactory
public NodeIdFactory getNodeIdFactory()
-
-