View Javadoc

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