org.apache.jackrabbit.core.state
Class TransactionalItemStateManager

java.lang.Object
  extended byorg.apache.jackrabbit.core.state.LocalItemStateManager
      extended byorg.apache.jackrabbit.core.state.TransactionalItemStateManager
All Implemented Interfaces:
ItemStateListener, ItemStateManager, UpdatableItemStateManager

public class TransactionalItemStateManager
extends LocalItemStateManager

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
sharedStateMgr, wspImpl
 
Constructor Summary
TransactionalItemStateManager(SharedItemStateManager sharedStateMgr, WorkspaceImpl wspImpl)
          Creates a new LocalItemStateManager instance.
 
Method Summary
 void commit(TransactionContext tx)
          Commit changes made within a transaction
 ItemState getItemState(ItemId id)
          Return an item state, given its item id.

If this state manager is committing changes, this method first checks the commitLog ThreadLocal.

 NodeReferences getNodeReferences(NodeReferencesId id)
          Return a node references object, given its target id

If this state manager is committing changes, this method first checks the commitLog ThreadLocal.

 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.

 boolean hasNodeReferences(NodeReferencesId 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.

 void prepare(TransactionContext tx)
          Prepare a transaction
 void rollback(TransactionContext tx)
          Rollback changes made within a transaction
 void setTransactionContext(TransactionContext tx)
          Set transaction context.
protected  void update(ChangeLog changeLog)
          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 to a transaction, simply merge the changes given to the ones already known (removing items that were first added and then again deleted).

 
Methods inherited from class org.apache.jackrabbit.core.state.LocalItemStateManager
cancel, createNew, createNew, destroy, dispose, edit, getNodeState, getPropertyState, inEditMode, stateCreated, stateDestroyed, stateDiscarded, stateModified, store, store, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionalItemStateManager

public TransactionalItemStateManager(SharedItemStateManager sharedStateMgr,
                                     WorkspaceImpl wspImpl)
Creates a new LocalItemStateManager instance.

Parameters:
sharedStateMgr - shared state manager
Method Detail

setTransactionContext

public void setTransactionContext(TransactionContext tx)
Set transaction context.

Parameters:
tx - transaction context.

prepare

public void prepare(TransactionContext tx)
             throws TransactionException
Prepare a transaction

Parameters:
tx - transaction context
Throws:
TransactionException - if an error occurs

commit

public void commit(TransactionContext tx)
            throws TransactionException
Commit changes made within a transaction

Parameters:
tx - transaction context
Throws:
TransactionException - if an error occurs

rollback

public void rollback(TransactionContext tx)
Rollback changes made within a transaction

Parameters:
tx - transaction context

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
Throws:
NoSuchItemStateException
ItemStateException

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

getNodeReferences

public NodeReferences getNodeReferences(NodeReferencesId 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
Throws:
NoSuchItemStateException
ItemStateException

hasNodeReferences

public boolean hasNodeReferences(NodeReferencesId 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

update

protected void update(ChangeLog changeLog)
               throws 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 to 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:
ItemStateException - if an error occurs
StaleItemStateException - if at least one of the affected item states has become stale in the meantime


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