org.apache.jackrabbit.core.state
Class XAItemStateManager

java.lang.Object
  extended by org.apache.jackrabbit.core.state.LocalItemStateManager
      extended by org.apache.jackrabbit.core.state.XAItemStateManager
All Implemented Interfaces:
InternalXAResource, ItemStateListener, ItemStateManager, NodeStateListener, UpdatableItemStateManager

public class XAItemStateManager
extends LocalItemStateManager
implements InternalXAResource

Extension to LocalItemStateManager 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
 
Method Summary
 void afterOperation(TransactionContext tx)
          Invoked after one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method has been called.
 void associate(TransactionContext tx)
          Associate this resource with a transaction.
 void beforeOperation(TransactionContext tx)
          Invoked before one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method is called.
 void commit(TransactionContext tx)
          Commit transaction.
static XAItemStateManager createInstance(SharedItemStateManager sharedStateMgr, EventStateCollectionFactory factory, String attributeName, ItemStateCacheFactory cacheFactory)
          Creates a new XAItemStateManager instance and registers it as an ItemStateListener with the given SharedItemStateManager.
 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 id
 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.
 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 an ItemState has successfully been modified (i.e. its underlying persistent state has changed).
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, getNodeState, getPropertyState, inEditMode, nodeAdded, nodeModified, nodeRemoved, nodesReplaced, removeListener, stateCreated, stateDestroyed, stateDiscarded, store, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createInstance

public static XAItemStateManager createInstance(SharedItemStateManager sharedStateMgr,
                                                EventStateCollectionFactory factory,
                                                String attributeName,
                                                ItemStateCacheFactory cacheFactory)
Creates a new XAItemStateManager instance and registers it as an ItemStateListener with the given SharedItemStateManager.

Parameters:
sharedStateMgr - the SharedItemStateManager
factory - the EventStateCollectionFactory
attributeName - the attribute name, if null then a default name is used
cacheFactory - the ItemStateCacheFactory
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 interface InternalXAResource
Parameters:
tx - transaction context, if null disassociate

beforeOperation

public void beforeOperation(TransactionContext tx)
Invoked before one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method is called.

Specified by:
beforeOperation in interface InternalXAResource
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 interface InternalXAResource
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 interface InternalXAResource
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 interface InternalXAResource
Parameters:
tx - transaction context.

afterOperation

public void afterOperation(TransactionContext tx)
Invoked after one of the InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext), InternalXAResource.commit(org.apache.jackrabbit.core.TransactionContext) or InternalXAResource.rollback(org.apache.jackrabbit.core.TransactionContext) method has been called.

Specified by:
afterOperation in interface InternalXAResource
Parameters:
tx - transaction context

getChangeLog

public ChangeLog getChangeLog()
Returns the current change log. First tries thread-local change log, then instance-local change log. Returns null 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 class LocalItemStateManager
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 interface ItemStateManager
Overrides:
getItemState in class LocalItemStateManager
Parameters:
id - item id
Returns:
item state
Throws:
NoSuchItemStateException - if the item does not exist
ItemStateException - 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 interface ItemStateManager
Overrides:
hasItemState in class LocalItemStateManager
Parameters:
id - item id
Returns:
true if an item state exists, otherwise false

getNodeReferences

public NodeReferences getNodeReferences(NodeId id)
                                 throws NoSuchItemStateException,
                                        ItemStateException
Return a node references object, given its target 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:
getNodeReferences in interface ItemStateManager
Overrides:
getNodeReferences in class LocalItemStateManager
Parameters:
id - target id
Returns:
node references object
Throws:
NoSuchItemStateException - if the item does not exist
ItemStateException - 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 interface ItemStateManager
Overrides:
hasNodeReferences in class LocalItemStateManager
Parameters:
id - target id
Returns:
true if a node reference object exists for the given id, otherwise false.

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 class LocalItemStateManager
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 referenced
StaleItemStateException - if at least one of the affected item states has become stale in the meantime
ItemStateException - if an error occurs

stateModified

public void stateModified(ItemState modified)
Called when an 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. 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 interface ItemStateListener
Overrides:
stateModified in class LocalItemStateManager
Parameters:
modified - the ItemState that has been 'modified'


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.