|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.neo4j.kernel.impl.transaction.xaframework.XaTransaction
public abstract class XaTransaction
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 |
---|
public XaTransaction(int identifier, XaLogicalLog log)
Method Detail |
---|
public abstract boolean isReadOnly()
true
if read only transaction, that is no
modifications will be made once the transaction commits.
protected abstract void doAddCommand(XaCommand command)
XaTransaction
needs to hold all the commands in memory
until it receives the doCommit
or doRollback
call.
command
- The command to be added to transactionprotected abstract void doRollback() throws XAException
rollback()
.
XAException
- If unable to rollbackprotected abstract void doPrepare() throws XAException
XAException
- If unable to prepareprotected abstract void doCommit() throws XAException
execute()
.
XAEXception
- If unable to commit
XAException
protected void setRecovered()
public boolean isRecovered()
true
if this is a "recovered transaction".
true
if transaction was created during a recovery
else false
is returnedpublic final int getIdentifier()
XaLogicalLog.getCurrentTxIdentifier()
.
public final void addCommand(XaCommand command)
doAddCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand)
. Also check
XaConnectionHelpImpl
class documentation example.
command
- The command to add to transaction
RuntimeException
- If problem writing command to logical log or this transaction
is committed or rolled backprotected void injectCommand(XaCommand command)
doAddCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand)
. Injects the command
into the transaction without writing to the logical log.
command
- The command that will be injectedpublic final void rollback() throws XAException
doRollback()
.
XAException
- If unable to rollbackpublic final void prepare() throws XAException
doPrepare()
.
XAException
- if unable to preparepublic final void commit() throws XAException
XaLogicalLog.getCurrentTxIdentifier()
then calls doCommit()
.
XAException
- If unable to commitpublic long getCommitTxId()
public void setCommitTxId(long commitTxId)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |