Class XAItemStateManager
- java.lang.Object
-
- org.apache.jackrabbit.core.state.LocalItemStateManager
-
- org.apache.jackrabbit.core.state.XAItemStateManager
-
- All Implemented Interfaces:
ItemStateListener
,ItemStateManager
,NodeStateListener
,UpdatableItemStateManager
,InternalXAResource
public class XAItemStateManager extends LocalItemStateManager implements InternalXAResource
Extension toLocalItemStateManager
that remembers changes on multiple save() requests and commits them only when an associated transaction is itself committed.
-
-
Field Summary
-
Fields inherited from class org.apache.jackrabbit.core.state.LocalItemStateManager
factory, sharedStateMgr
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
XAItemStateManager(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, String attributeName, ItemStateCacheFactory cacheFactory)
Creates a new instance of this class with a custom attribute name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterOperation(TransactionContext tx)
void
associate(TransactionContext tx)
Associate this resource with a transaction.void
beforeOperation(TransactionContext tx)
void
commit(TransactionContext tx)
Commit transaction.static XAItemStateManager
createInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, String attributeName, ItemStateCacheFactory cacheFactory)
Creates a newXAItemStateManager
instance and registers it as anItemStateListener
with the givenSharedItemStateManager
.ChangeLog
getChangeLog()
Returns the current change log.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.NodeReferences
getNodeReferences(NodeId id)
Return a node references object, given its target idboolean
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.void
prepare(TransactionContext tx)
Prepare transaction.void
rollback(TransactionContext tx)
Rollback transaction.void
setVirtualProvider(VirtualItemStateProvider virtualProvider)
Set optional virtual item state provider.void
stateModified(ItemState modified)
Called when anItemState
has successfully been modified (i.e.protected void
update(ChangeLog changeLog)
End an update operation.-
Methods inherited from class org.apache.jackrabbit.core.state.LocalItemStateManager
addListener, cancel, createInstance, createNew, createNew, destroy, dispose, edit, getNodeIdFactory, getNodeState, getOrCreateLocalState, getPropertyState, inEditMode, nodeAdded, nodeModified, nodeRemoved, nodesReplaced, removeListener, stateCreated, stateDestroyed, stateDiscarded, store, update
-
-
-
-
Constructor Detail
-
XAItemStateManager
protected XAItemStateManager(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, String attributeName, ItemStateCacheFactory cacheFactory)
Creates a new instance of this class with a custom attribute name.- Parameters:
sharedStateMgr
- shared state managerfactory
- event state collection factoryattributeName
- the attribute name, ifnull
then a default name is used
-
-
Method Detail
-
createInstance
public static XAItemStateManager createInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, String attributeName, ItemStateCacheFactory cacheFactory)
Creates a newXAItemStateManager
instance and registers it as anItemStateListener
with the givenSharedItemStateManager
.- Parameters:
sharedStateMgr
- theSharedItemStateManager
factory
- theEventStateCollectionFactory
attributeName
- the attribute name, ifnull
then a default name is usedcacheFactory
- theItemStateCacheFactory
- Returns:
- a new
XAItemStateManager
instance
-
setVirtualProvider
public void setVirtualProvider(VirtualItemStateProvider virtualProvider)
Set optional virtual item state provider.
-
associate
public void associate(TransactionContext tx)
Associate this resource with a transaction. All further operations on the object should be interpreted as part of this transaction and changes recorded in some attribute of the transaction context.- Specified by:
associate
in interfaceInternalXAResource
- Parameters:
tx
- transaction context, ifnull
disassociate
-
beforeOperation
public void beforeOperation(TransactionContext tx)
Invoked before one of theInternalXAResource.prepare(org.apache.jackrabbit.data.core.TransactionContext)
,InternalXAResource.commit(org.apache.jackrabbit.data.core.TransactionContext)
orInternalXAResource.rollback(org.apache.jackrabbit.data.core.TransactionContext)
method is called.- Specified by:
beforeOperation
in interfaceInternalXAResource
- Parameters:
tx
- transaction context
-
prepare
public void prepare(TransactionContext tx) throws TransactionException
Prepare transaction. The transaction is identified by a transaction context.- Specified by:
prepare
in interfaceInternalXAResource
- Parameters:
tx
- transaction context- Throws:
TransactionException
- if an error occurs
-
commit
public void commit(TransactionContext tx) throws TransactionException
Commit transaction. The transaction is identified by a transaction context. If the method throws, other resources get their changes rolled back.- Specified by:
commit
in interfaceInternalXAResource
- Parameters:
tx
- transaction context- Throws:
TransactionException
- if an error occurs
-
rollback
public void rollback(TransactionContext tx)
Rollback transaction. The transaction is identified by a transaction context.- Specified by:
rollback
in interfaceInternalXAResource
- Parameters:
tx
- transaction context.
-
afterOperation
public void afterOperation(TransactionContext tx)
Invoked after one of theInternalXAResource.prepare(org.apache.jackrabbit.data.core.TransactionContext)
,InternalXAResource.commit(org.apache.jackrabbit.data.core.TransactionContext)
orInternalXAResource.rollback(org.apache.jackrabbit.data.core.TransactionContext)
method has been called.- Specified by:
afterOperation
in interfaceInternalXAResource
- Parameters:
tx
- transaction context
-
getChangeLog
public ChangeLog getChangeLog()
Returns the current change log. First tries thread-local change log, then instance-local change log. Returnsnull
if no change log was found.
-
getChanges
protected ChangeLog getChanges()
Description copied from class:LocalItemStateManager
Returns the change log that contains the current changes in this local item state manager.- Overrides:
getChanges
in classLocalItemStateManager
- Returns:
- the change log with the current changes.
- Throws:
UnsupportedOperationException
- always.
-
getItemState
public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
Return an item state, given its item id.If this state manager is committing changes, this method first checks the commitLog ThreadLocal. Else if associated to a transaction check the transactional change log. Fallback is always the call to the base class.
- Specified by:
getItemState
in interfaceItemStateManager
- Overrides:
getItemState
in classLocalItemStateManager
- 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.If this state manager is committing changes, this method first checks the commitLog ThreadLocal. Else if associated to a transaction check the transactional change log. Fallback is always the call to the base class.
- Specified by:
hasItemState
in interfaceItemStateManager
- Overrides:
hasItemState
in classLocalItemStateManager
- 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 idIf this state manager is committing changes, this method first checks the commitLog ThreadLocal. Else if associated to a transaction check the transactional change log. Fallback is always the call to the base class.
- Specified by:
getNodeReferences
in interfaceItemStateManager
- Overrides:
getNodeReferences
in classLocalItemStateManager
- 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.If this state manager is committing changes, this method first checks the commitLog ThreadLocal. Else if associated to a transaction check the transactional change log. Fallback is always the call to the base class.
- Specified by:
hasNodeReferences
in interfaceItemStateManager
- Overrides:
hasNodeReferences
in classLocalItemStateManager
- Parameters:
id
- target id- Returns:
true
if a node reference object exists for the given id, otherwisefalse
.
-
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.If associated with a transaction, simply merge the changes given to the ones already known (removing items that were first added and then again deleted).
- Overrides:
update
in classLocalItemStateManager
- 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
-
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 local states that this state manager has created, as well as states that were created by the shared state manager we're listening to. Check whether the shared state modified is contained in our transactional log: in that case, update its state as well, as it might get reused in a subsequent transaction (see JCR-1554).
- Specified by:
stateModified
in interfaceItemStateListener
- Overrides:
stateModified
in classLocalItemStateManager
- Parameters:
modified
- theItemState
that has been 'modified'
-
-