public class LocalItemStateManager extends Object implements UpdatableItemStateManager, NodeStateListener
ItemStateManager
that isolates changes to
persistent states from other clients.Modifier and Type | Field and Description |
---|---|
protected EventStateCollectionFactory |
factory
Event state collection factory.
|
protected SharedItemStateManager |
sharedStateMgr
Shared item state manager
|
Modifier | Constructor and Description |
---|---|
protected |
LocalItemStateManager(SharedItemStateManager sharedStateMgr,
EventStateCollectionFactory factory,
ItemStateCacheFactory cacheFactory)
Creates a new
LocalItemStateManager instance. |
Modifier and Type | Method and Description |
---|---|
void |
addListener(ItemStateListener listener)
Add an
ItemStateListener |
void |
cancel()
Cancel an update operation.
|
static LocalItemStateManager |
createInstance(SharedItemStateManager sharedStateMgr,
EventStateCollectionFactory factory,
ItemStateCacheFactory cacheFactory)
Creates a new
LocalItemStateManager instance and registers it as an ItemStateListener
with the given SharedItemStateManager . |
PropertyState |
createNew(Name propName,
NodeId parentId)
Creates a
PropertyState instance representing new,
i.e. |
NodeState |
createNew(NodeId id,
Name nodeTypeName,
NodeId parentId)
Creates a
NodeState instance representing new,
i.e. |
void |
destroy(ItemState state)
Destroy an item state.
|
void |
dispose()
Disposes this
UpdatableItemStateManager and frees resources. |
void |
edit()
Start an edit operation on items inside this manager.
|
protected ChangeLog |
getChanges()
Returns the change log that contains the current changes in this local
item state manager.
|
ItemState |
getItemState(ItemId id)
Return an item state, given its item id.
|
NodeIdFactory |
getNodeIdFactory() |
NodeReferences |
getNodeReferences(NodeId id)
Return a node references object, given its target id
|
protected NodeState |
getNodeState(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.
|
NodeState |
getOrCreateLocalState(NodeState transientState)
Returns the local node state below the given transient one.
|
protected PropertyState |
getPropertyState(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.
|
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 |
inEditMode()
Returns
true if this manager is in edit mode i.e. |
void |
nodeAdded(NodeState state,
Name name,
int index,
NodeId id)
Called when a child node has been added
|
void |
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 removed
|
void |
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 an
ItemStateListener |
void |
stateCreated(ItemState created)
Called when an
ItemState has successfully
been created (i.e. |
void |
stateDestroyed(ItemState destroyed)
Called when an
ItemState has successfully been
removed (i.e. |
void |
stateDiscarded(ItemState discarded)
Called when an
ItemState has been discarded (i.e. |
void |
stateModified(ItemState modified)
Called when an
ItemState has successfully
been modified (i.e. |
void |
store(ItemState state)
Store an item state.
|
void |
update()
End an update operation.
|
protected void |
update(ChangeLog changeLog)
End an update operation.
|
protected final SharedItemStateManager sharedStateMgr
protected final EventStateCollectionFactory factory
protected LocalItemStateManager(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, ItemStateCacheFactory cacheFactory)
LocalItemStateManager
instance.sharedStateMgr
- shared state managerfactory
- event state collection factorypublic static LocalItemStateManager createInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, ItemStateCacheFactory cacheFactory)
LocalItemStateManager
instance and registers it as an ItemStateListener
with the given SharedItemStateManager
.sharedStateMgr
- the SharedItemStateManager
factory
- the EventStateCollectionFactory
cacheFactory
- the ItemStateCacheFactory
LocalItemStateManager
instanceprotected NodeState getNodeState(NodeId id) throws NoSuchItemStateException, ItemStateException
id
- node idNoSuchItemStateException
ItemStateException
protected PropertyState getPropertyState(PropertyId id) throws NoSuchItemStateException, ItemStateException
id
- property idNoSuchItemStateException
ItemStateException
protected ChangeLog getChanges()
public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
getItemState
in interface ItemStateManager
id
- item idNoSuchItemStateException
- if the item does not existItemStateException
- if an error occurspublic boolean hasItemState(ItemId id)
hasItemState
in interface ItemStateManager
id
- item idtrue
if an item state exists,
otherwise false
public NodeReferences getNodeReferences(NodeId id) throws NoSuchItemStateException, ItemStateException
getNodeReferences
in interface ItemStateManager
id
- target idNoSuchItemStateException
- if the item does not existItemStateException
- if an error occurspublic boolean hasNodeReferences(NodeId id)
hasNodeReferences
in interface ItemStateManager
id
- target idtrue
if a node reference object exists for the given
id, otherwise false
.public void edit() throws IllegalStateException
UpdatableItemStateManager.update()
or UpdatableItemStateManager.cancel()
must be invoked.edit
in interface UpdatableItemStateManager
IllegalStateException
- if the manager is already in edit mode.public boolean inEditMode()
true
if this manager is in edit mode i.e.
if an edit operation has been started by invoking UpdatableItemStateManager.edit()
,
otherwise returns false
.inEditMode
in interface UpdatableItemStateManager
true
if this manager is in edit mode, otherwise
false
public NodeState createNew(NodeId id, Name nodeTypeName, NodeId parentId) throws javax.jcr.RepositoryException
NodeState
instance representing new,
i.e. not yet existing state. Call UpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState)
on the returned object to make it persistent.createNew
in interface UpdatableItemStateManager
id
- the id of the node, or null
for a new node idnodeTypeName
- The node type nameparentId
- parent node's idjavax.jcr.RepositoryException
- if the node state can not be createdpublic NodeState getOrCreateLocalState(NodeState transientState) throws javax.jcr.RepositoryException
transientState
- transient statejavax.jcr.RepositoryException
- if the local state could not be createdpublic PropertyState createNew(Name propName, NodeId parentId) throws IllegalStateException
PropertyState
instance representing new,
i.e. not yet existing state. Call UpdatableItemStateManager.store(org.apache.jackrabbit.core.state.ItemState)
on the returned object to make it persistent.createNew
in interface UpdatableItemStateManager
propName
- property nameparentId
- parent node IdIllegalStateException
- if the manager is not in edit mode.public void store(ItemState state) throws IllegalStateException
store
in interface UpdatableItemStateManager
state
- item state that should be storedIllegalStateException
- if the manager is not in edit mode.public void destroy(ItemState state) throws IllegalStateException
destroy
in interface UpdatableItemStateManager
state
- item state that should be destroyedIllegalStateException
- if the manager is not in edit mode.public void cancel() throws IllegalStateException
cancel
in interface UpdatableItemStateManager
IllegalStateException
- if the manager is not in edit mode.public void update() throws javax.jcr.ReferentialIntegrityException, StaleItemStateException, ItemStateException, IllegalStateException
update
in interface UpdatableItemStateManager
javax.jcr.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.protected void update(ChangeLog changeLog) throws javax.jcr.ReferentialIntegrityException, StaleItemStateException, ItemStateException
changeLog
- change log containing local states and referencesjavax.jcr.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 occurspublic void dispose()
UpdatableItemStateManager
and frees resources.dispose
in interface UpdatableItemStateManager
public void addListener(ItemStateListener listener)
ItemStateListener
listener
- the new listener to be informed on modificationspublic void removeListener(ItemStateListener listener)
ItemStateListener
listener
- an existing listenerpublic void stateCreated(ItemState created)
ItemState
has 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.
stateCreated
in interface ItemStateListener
created
- the ItemState
that has been 'created'public void stateModified(ItemState modified)
ItemState
has 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.
stateModified
in interface ItemStateListener
modified
- the ItemState
that has been 'modified'public void stateDestroyed(ItemState destroyed)
ItemState
has 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.
stateDestroyed
in interface ItemStateListener
destroyed
- the ItemState
that has been 'destroyed'public void stateDiscarded(ItemState discarded)
ItemState
has 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.
stateDiscarded
in interface ItemStateListener
discarded
- the ItemState
that has been discardedItemState.discard()
public void nodeAdded(NodeState state, Name name, int index, NodeId id)
Optimization: shared state manager we're listening to does not deliver node state changes, therefore the state concerned must be a local state.
nodeAdded
in interface NodeStateListener
state
- node state that changedname
- name of node that was addedindex
- index of new nodeid
- id of new nodepublic void nodesReplaced(NodeState state)
Optimization: shared state manager we're listening to does not deliver node state changes, therefore the state concerned must be a local state.
nodesReplaced
in interface NodeStateListener
state
- node state that changedpublic void nodeModified(NodeState state)
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.
nodeModified
in interface NodeStateListener
state
- node state that changedpublic void nodeRemoved(NodeState state, Name name, int index, NodeId id)
Optimization: shared state manager we're listening to does not deliver node state changes, therefore the state concerned must be a local state.
nodeRemoved
in interface NodeStateListener
state
- node state that changedname
- name of node that was removedindex
- index of removed nodeid
- id of removed nodepublic NodeIdFactory getNodeIdFactory()
Copyright © 2004-2020 The Apache Software Foundation. All Rights Reserved.