Compensating command example

To use a compensating command, you must retrieve the compensator that is associated with the primary command and call its execute method.

ModifyCheckingAccountCompensator command

The following code example shows the code used to run the original command and to give the user the option of undoing the work by running the compensating command.

{
...
CheckingAccount checkingAccount
....
try {
ModifyCheckingAccountCmd cmd =
new ModifyCheckingAccountCmdImpl(null, 1000);
cmd.setCheckingAccount(checkingAccount);
cmd.execute();
...
System.out.println("Would you like to undo this work? Enter Y or N");
try {
// Retrieve and validate user's response
...
}
...
if (answer.equalsIgnoreCase(Y)) {
Command compensatingCommand = cmd.getCompensatingCommand();
compensatingCommand.execute();
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
...
}



Related tasks
Using a command
Reference topic    

Terms of Use | Feedback

Last updated: Feb 19, 2011 5:25:36 AM CST
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=v610web&product=was-nd-mp&topic=rcmd_usecompensatingcmd
File name: rcmd_usecompensatingcmd.html