    1   package groovy.txn;
    2
    3   import groovy.lang.Closure;
    4
    5   /***
    6    * @author James Strachan
    7    * @version $Revision: 1924 $
    8    */
    9   public class TransactionBuilder {
    10      public void transaction(Closure closure) {
    11          TransactionBean bean = new TransactionBean();
    12          closure.setDelegate(bean);
    13          closure.call(this);
    14
    15          // lets call the closures now
    16          System.out.println("Performing normal transaction");
    17          bean.run().call(this);
    18          bean.onSuccess().call(this);
    19
    20          System.out.println("Performing error transaction");
    21          bean.run().call(this);
    22          bean.onError().call(this);
    23      }
    24  }