org.neo4j.kernel.impl.transaction.xaframework
Class XaTransaction

java.lang.Object
  extended by org.neo4j.kernel.impl.transaction.xaframework.XaTransaction
Direct Known Subclasses:
WriteTransaction

public abstract class XaTransaction
extends Object

XaTransaction holds all the commands that participate in the transaction and then either rollbacks or commits them. Here are two example implementations:

 
 // Example of XaTransaction implementation where commands are written to
 // to logical log directly when created
 public class MyTransaction extends XaTransaction
 {
     private List cmds = new java.util.LinkedList();
 
     public boolean isReadyOnly()
     {
         return cmds.size() == 0;
     }
 
     public void doAddCommand( XaCommand cmd )
     {
         cmds.add( cmd );
     }
 
     public void doRollback()
     {
         Iterator itr = cmds.iterator();
         while ( itr.hasNext() )
             ((XaCommand) itr.next()).rollback();
     }
 
     public void doCommit()
     {
         Iterator itr = cmds.iterator();
         while ( itr.hasNext() )
             ((XaCommand) itr.next()).execute();
     }
 
     public void doPrepare()
     {
         // do nothing since commands are added before prepare
     }
 }
 
 
Some other implementation that makes use of prepare could look something like this:
 
 // Example of XaTransaction implementation where commands are written to
 // to logical log when transaction is prepared
 public class MyTransaction extends XaTransaction
 {
     private List cmds = new java.util.LinkedList();
 
     public boolean isReadyOnly()
     {
         return cmds.size() == 0;
     }
 
     public void doAddCommand( XaCommand cmd )
     {
         // do nothing, we call addCommand in prepare 
     }
 
     public void doRollback()
     {
         Iterator itr = cmds.iterator();
         while ( itr.hasNext() )
             ((XaCommand) itr.next()).rollback();
     }
 
     public void doCommit()
     {
         Iterator itr = cmds.iterator();
         while ( itr.hasNext() )
             ((XaCommand) itr.next()).execute();
     }
 
     public void doPrepare()
     {
         Iterator itr = cmds.iterator();
         while ( itr.hasNext() )
             addCommand( (XaCommand) itr.next() );
     }
 
 }
 
 


Constructor Summary
XaTransaction(int identifier, XaLogicalLog log)
           
 
Method Summary
 void addCommand(XaCommand command)
          Adds the command to transaction.
 void commit()
          First registers the transaction identifier (see XaLogicalLog.getCurrentTxIdentifier() then calls doCommit().
protected abstract  void doAddCommand(XaCommand command)
          When a command is added to transaction it will be passed via this method.
protected abstract  void doCommit()
          Commits the transaction, loop through all commands and invoke execute().
protected abstract  void doPrepare()
          Called when transaction is beeing prepared.
protected abstract  void doRollback()
          Rollbacks the transaction, loop through all commands and invoke rollback().
 long getCommitTxId()
           
 int getIdentifier()
          Returns the "internal" identifier for this transaction.
protected  void injectCommand(XaCommand command)
          Used during recovery, calls doAddCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand).
abstract  boolean isReadOnly()
          Returns true if read only transaction, that is no modifications will be made once the transaction commits.
 boolean isRecovered()
          Returns true if this is a "recovered transaction".
 void prepare()
          Called before prepare marker is written to logical log.
 void rollback()
          Rollbacks the transaction, calls doRollback().
 void setCommitTxId(long commitTxId)
           
protected  void setRecovered()
          If this transaction is created during a recovery scan of the logical log method will be called to mark the transaction "recovered".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XaTransaction

public XaTransaction(int identifier,
                     XaLogicalLog log)
Method Detail

isReadOnly

public abstract boolean isReadOnly()
Returns true if read only transaction, that is no modifications will be made once the transaction commits.

Returns:
true if read only transaction

doAddCommand

protected abstract void doAddCommand(XaCommand command)
When a command is added to transaction it will be passed via this method. The XaTransaction needs to hold all the commands in memory until it receives the doCommit or doRollback call.

Parameters:
command - The command to be added to transaction

doRollback

protected abstract void doRollback()
                            throws XAException
Rollbacks the transaction, loop through all commands and invoke rollback().

Throws:
XAException - If unable to rollback

doPrepare

protected abstract void doPrepare()
                           throws XAException
Called when transaction is beeing prepared.

Throws:
XAException - If unable to prepare

doCommit

protected abstract void doCommit()
                          throws XAException
Commits the transaction, loop through all commands and invoke execute().

Throws:
XAEXception - If unable to commit
XAException

setRecovered

protected void setRecovered()
If this transaction is created during a recovery scan of the logical log method will be called to mark the transaction "recovered".


isRecovered

public boolean isRecovered()
Returns true if this is a "recovered transaction".

Returns:
true if transaction was created during a recovery else false is returned

getIdentifier

public final int getIdentifier()
Returns the "internal" identifier for this transaction. See XaLogicalLog.getCurrentTxIdentifier().

Returns:
The transaction identifier

addCommand

public final void addCommand(XaCommand command)
Adds the command to transaction. First writes the command to the logical log then calls doAddCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand). Also check XaConnectionHelpImpl class documentation example.

Parameters:
command - The command to add to transaction
Throws:
RuntimeException - If problem writing command to logical log or this transaction is committed or rolled back

injectCommand

protected void injectCommand(XaCommand command)
Used during recovery, calls doAddCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand). Injects the command into the transaction without writing to the logical log.

Parameters:
command - The command that will be injected

rollback

public final void rollback()
                    throws XAException
Rollbacks the transaction, calls doRollback().

Throws:
XAException - If unable to rollback

prepare

public final void prepare()
                   throws XAException
Called before prepare marker is written to logical log. Calls doPrepare().

Throws:
XAException - if unable to prepare

commit

public final void commit()
                  throws XAException
First registers the transaction identifier (see XaLogicalLog.getCurrentTxIdentifier() then calls doCommit().

Throws:
XAException - If unable to commit

getCommitTxId

public long getCommitTxId()

setCommitTxId

public void setCommitTxId(long commitTxId)


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.