View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.util.xa;
8   
9   import org.mule.util.UUID;
10  
11  import javax.transaction.Status;
12  
13  public abstract class AbstractTransactionContext
14  {
15      protected String id = UUID.getUUID();
16      protected long timeout;
17      protected int status;
18      protected boolean readOnly;
19      protected boolean suspended;
20      protected boolean finished;
21  
22      public AbstractTransactionContext()
23      {
24          status = Status.STATUS_NO_TRANSACTION;
25          suspended = false;
26          finished = false;
27          readOnly = true;
28      }
29  
30      public String toString()
31      {
32          StringBuffer sb = new StringBuffer();
33          sb.append(id).append("[");
34          sb.append(getStatusString());
35          if (suspended)
36          {
37              sb.append(", suspended");
38          }
39          if (readOnly)
40          {
41              sb.append(", readonly");
42          }
43          if (finished)
44          {
45              sb.append(", finished");
46          }
47          sb.append("]");
48          return sb.toString();
49      }
50  
51      private String getStatusString()
52      {
53          switch (status)
54          {
55              case Status.STATUS_ACTIVE :
56                  return "active";
57              case Status.STATUS_MARKED_ROLLBACK :
58                  return "marked rollback";
59              case Status.STATUS_PREPARED :
60                  return "prepared";
61              case Status.STATUS_COMMITTED :
62                  return "committed";
63              case Status.STATUS_ROLLEDBACK :
64                  return "rolled back";
65              case Status.STATUS_UNKNOWN :
66                  return "unknown";
67              case Status.STATUS_NO_TRANSACTION :
68                  return "no transaction";
69              case Status.STATUS_PREPARING :
70                  return "preparing";
71              case Status.STATUS_COMMITTING :
72                  return "committing";
73              case Status.STATUS_ROLLING_BACK :
74                  return "rolling back";
75              default :
76                  return "undefined status";
77          }
78      }
79  
80      public synchronized void finalCleanUp() throws ResourceManagerException
81      {
82          // nothing to do (yet?)
83      }
84  
85      public synchronized void notifyFinish()
86      {
87          finished = true;
88          notifyAll();
89      }
90  
91  }