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 toLocalItemStateManagerthat 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 protectedXAItemStateManager(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 voidafterOperation(TransactionContext tx)voidassociate(TransactionContext tx)Associate this resource with a transaction.voidbeforeOperation(TransactionContext tx)voidcommit(TransactionContext tx)Commit transaction.static XAItemStateManagercreateInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, String attributeName, ItemStateCacheFactory cacheFactory)Creates a newXAItemStateManagerinstance and registers it as anItemStateListenerwith the givenSharedItemStateManager.ChangeLoggetChangeLog()Returns the current change log.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.NodeReferencesgetNodeReferences(NodeId id)Return a node references object, given its target idbooleanhasItemState(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.voidprepare(TransactionContext tx)Prepare transaction.voidrollback(TransactionContext tx)Rollback transaction.voidsetVirtualProvider(VirtualItemStateProvider virtualProvider)Set optional virtual item state provider.voidstateModified(ItemState modified)Called when anItemStatehas successfully been modified (i.e.protected voidupdate(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, ifnullthen a default name is used
-
-
Method Detail
-
createInstance
public static XAItemStateManager createInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, String attributeName, ItemStateCacheFactory cacheFactory)
Creates a newXAItemStateManagerinstance and registers it as anItemStateListenerwith the givenSharedItemStateManager.- Parameters:
sharedStateMgr- theSharedItemStateManagerfactory- theEventStateCollectionFactoryattributeName- the attribute name, ifnullthen a default name is usedcacheFactory- theItemStateCacheFactory- Returns:
- a new
XAItemStateManagerinstance
-
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:
associatein interfaceInternalXAResource- Parameters:
tx- transaction context, ifnulldisassociate
-
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:
beforeOperationin 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:
preparein 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:
commitin 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:
rollbackin 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:
afterOperationin 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. Returnsnullif no change log was found.
-
getChanges
protected ChangeLog getChanges()
Description copied from class:LocalItemStateManagerReturns the change log that contains the current changes in this local item state manager.- Overrides:
getChangesin 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:
getItemStatein interfaceItemStateManager- Overrides:
getItemStatein 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:
hasItemStatein interfaceItemStateManager- Overrides:
hasItemStatein classLocalItemStateManager- 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 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:
getNodeReferencesin interfaceItemStateManager- Overrides:
getNodeReferencesin 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:
hasNodeReferencesin interfaceItemStateManager- Overrides:
hasNodeReferencesin classLocalItemStateManager- Parameters:
id- target id- Returns:
trueif 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:
updatein 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 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. 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:
stateModifiedin interfaceItemStateListener- Overrides:
stateModifiedin classLocalItemStateManager- Parameters:
modified- theItemStatethat has been 'modified'
-
-