View Javadoc

1   /*
2    * $Id: AbstractTransactionContext.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
11  package org.mule.util.xa;
12  
13  import javax.transaction.Status;
14  
15  import org.safehaus.uuid.UUIDGenerator;
16  
17  /**
18   * @author <a href="mailto:gnt@codehaus.org">Guillaume Nodet</a>
19   * @version $Revision: 7976 $
20   */
21  public class AbstractTransactionContext
22  {
23  
24      private static UUIDGenerator gen = UUIDGenerator.getInstance();
25  
26      protected String id = gen.generateTimeBasedUUID().toString();
27      protected long timeout;
28      protected int status;
29      protected boolean readOnly;
30      protected boolean suspended;
31      protected boolean finished;
32  
33      public AbstractTransactionContext()
34      {
35          status = Status.STATUS_NO_TRANSACTION;
36          suspended = false;
37          finished = false;
38          readOnly = true;
39      }
40  
41      public String toString()
42      {
43          StringBuffer sb = new StringBuffer();
44          sb.append(id).append("[");
45          sb.append(getStatusString());
46          if (suspended)
47          {
48              sb.append(", suspended");
49          }
50          if (readOnly)
51          {
52              sb.append(", readonly");
53          }
54          if (finished)
55          {
56              sb.append(", finished");
57          }
58          sb.append("]");
59          return sb.toString();
60      }
61  
62      private String getStatusString()
63      {
64          switch (status)
65          {
66              case Status.STATUS_ACTIVE :
67                  return "active";
68              case Status.STATUS_MARKED_ROLLBACK :
69                  return "marked rollback";
70              case Status.STATUS_PREPARED :
71                  return "prepared";
72              case Status.STATUS_COMMITTED :
73                  return "committed";
74              case Status.STATUS_ROLLEDBACK :
75                  return "rolled back";
76              case Status.STATUS_UNKNOWN :
77                  return "unknown";
78              case Status.STATUS_NO_TRANSACTION :
79                  return "no transaction";
80              case Status.STATUS_PREPARING :
81                  return "preparing";
82              case Status.STATUS_COMMITTING :
83                  return "committing";
84              case Status.STATUS_ROLLING_BACK :
85                  return "rolling back";
86              default :
87                  return "undefined status";
88          }
89      }
90  
91      public synchronized void finalCleanUp() throws ResourceManagerException
92      {
93          // nothing to do (yet?)
94      }
95  
96      public synchronized void notifyFinish()
97      {
98          finished = true;
99          notifyAll();
100     }
101 
102 }