View Javadoc

1   /*
2    * $Id: TestTransaction.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.tck.testmodels.mule;
11  
12  import org.mule.api.MuleContext;
13  import org.mule.api.transaction.TransactionException;
14  import org.mule.transaction.AbstractSingleResourceTransaction;
15  
16  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
17  
18  /**
19   * A test transaction that does nothing on commit or rollback. The transaction does retain a status so that
20   * developers can determine if the the transaction was rolled back or committed.
21   */
22  public class TestTransaction extends AbstractSingleResourceTransaction
23  {
24      private AtomicBoolean committed = new AtomicBoolean(false);
25      private AtomicBoolean rolledBack = new AtomicBoolean(false);
26  
27      private String testProperty;
28  
29      public TestTransaction(MuleContext muleContext)
30      {
31          super(muleContext);
32      }
33  
34      /**
35       * Really begin the transaction. Note that resources are enlisted yet.
36       *
37       * @throws org.mule.api.transaction.TransactionException
38       *
39       */
40      protected void doBegin() throws TransactionException
41      {
42          //do nothing
43      }
44  
45      /**
46       * Commit the transaction on the underlying resource
47       *
48       * @throws org.mule.api.transaction.TransactionException
49       *
50       */
51      protected void doCommit() throws TransactionException
52      {
53          committed.set(true);
54      }
55  
56      /**
57       * Rollback the transaction on the underlying resource
58       *
59       * @throws org.mule.api.transaction.TransactionException
60       *
61       */
62      protected void doRollback() throws TransactionException
63      {
64          rolledBack.set(true);
65      }
66  
67      public String getTestProperty()
68      {
69          return testProperty;
70      }
71  
72      public void setTestProperty(String testProperty)
73      {
74          this.testProperty = testProperty;
75      }
76  }