View Javadoc

1   /*
2    * $Id: AbstractTransactionContext.java 7963 2007-08-21 08:53:15Z 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  public class AbstractTransactionContext
18  {
19  
20      private static UUIDGenerator gen = UUIDGenerator.getInstance();
21  
22      protected String id = gen.generateTimeBasedUUID().toString();
23      protected long timeout;
24      protected int status;
25      protected boolean readOnly;
26      protected boolean suspended;
27      protected boolean finished;
28  
29      public AbstractTransactionContext()
30      {
31          status = Status.STATUS_NO_TRANSACTION;
32          suspended = false;
33          finished = false;
34          readOnly = true;
35      }
36  
37      public String toString()
38      {
39          StringBuffer sb = new StringBuffer();
40          sb.append(id).append("[");
41          sb.append(getStatusString());
42          if (suspended)
43          {
44              sb.append(", suspended");
45          }
46          if (readOnly)
47          {
48              sb.append(", readonly");
49          }
50          if (finished)
51          {
52              sb.append(", finished");
53          }
54          sb.append("]");
55          return sb.toString();
56      }
57  
58      private String getStatusString()
59      {
60          switch (status)
61          {
62              case Status.STATUS_ACTIVE :
63                  return "active";
64              case Status.STATUS_MARKED_ROLLBACK :
65                  return "marked rollback";
66              case Status.STATUS_PREPARED :
67                  return "prepared";
68              case Status.STATUS_COMMITTED :
69                  return "committed";
70              case Status.STATUS_ROLLEDBACK :
71                  return "rolled back";
72              case Status.STATUS_UNKNOWN :
73                  return "unknown";
74              case Status.STATUS_NO_TRANSACTION :
75                  return "no transaction";
76              case Status.STATUS_PREPARING :
77                  return "preparing";
78              case Status.STATUS_COMMITTING :
79                  return "committing";
80              case Status.STATUS_ROLLING_BACK :
81                  return "rolling back";
82              default :
83                  return "undefined status";
84          }
85      }
86  
87      public synchronized void finalCleanUp() throws ResourceManagerException
88      {
89          // nothing to do (yet?)
90      }
91  
92      public synchronized void notifyFinish()
93      {
94          finished = true;
95          notifyAll();
96      }
97  
98  }