org.prevayler.util.memento
Class MementoTransaction

java.lang.Object
  extended by org.prevayler.util.memento.MementoTransaction
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AccountCreation, AccountDeletion, Deposit, Transfer, Withdrawal

public abstract class MementoTransaction
extends Object
implements Serializable

An atomic transaction to be executed on a PrevalentSystem. Any operation which changes the observable state of a PrevalentSystem must be encapsulated as a Command. This command adds the capability to create mementos of objects before they get modified. In the event of a failure, these mementos are restored and the system is left in the state it was in before the command got executed. The execution is split in four parts:

Version:
2.0
Author:
Johan Stuyts
See Also:
Serialized Form

Constructor Summary
MementoTransaction()
           
 
Method Summary
protected abstract  void checkPrecondition()
          Check the precondition.
protected abstract  void createMementos(MementoCollector collector)
          Create mementos for all objects which (possibly) get modified.
protected abstract  Account execute(MementoCollector collector)
          Execute the actual command.
 Account execute(MementoCollector collector, Bank prevalentSystem)
          Executes this command on the received system.
protected abstract  void findObjects(Bank prevalentSystem)
          Find the objects this command modifies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MementoTransaction

public MementoTransaction()
Method Detail

execute

public Account execute(MementoCollector collector,
                       Bank prevalentSystem)
                throws Exception
Executes this command on the received system. See prevayler.demos for examples. The returned object has to be Serializable in preparation for future versions of Prevayler that will provide fault-tolerance through system replicas.

Parameters:
collector - The memento collector to which to add the mementos. A memento collector instead of a Prevayler instance is passed, so the command will not easily invoke subcommands through the prevayler (which is not allowed).
prevalentSystem - The system on which to execute the command.
Returns:
The object returned by the execution of this command. Most commands simply return null.
Throws:
Exception

findObjects

protected abstract void findObjects(Bank prevalentSystem)
                             throws Exception
Find the objects this command modifies.

Parameters:
prevalentSystem - The prevalent system in which to find the objects.
Throws:
Exception

checkPrecondition

protected abstract void checkPrecondition()
                                   throws Exception
Check the precondition.

Throws:
Exception

createMementos

protected abstract void createMementos(MementoCollector collector)
Create mementos for all objects which (possibly) get modified.

Parameters:
collector - The memento collector to which to add the mementos.

execute

protected abstract Account execute(MementoCollector collector)
                            throws Exception
Execute the actual command.

Parameters:
collector - The memento collector which can be used to execute subcommands.
Returns:
The object returned by the execution of this command. Most commands simply return null.
Throws:
Exception


Copyright © 2001-2013. All Rights Reserved.