01: /*
02: * $Id: AbstractTransactionContext.java 8077 2007-08-27 20:15:25Z aperepel $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: private static UUIDGenerator gen = UUIDGenerator.getInstance();
20:
21: protected String id = gen.generateTimeBasedUUID().toString();
22: protected long timeout;
23: protected int status;
24: protected boolean readOnly;
25: protected boolean suspended;
26: protected boolean finished;
27:
28: public AbstractTransactionContext() {
29: status = Status.STATUS_NO_TRANSACTION;
30: suspended = false;
31: finished = false;
32: readOnly = true;
33: }
34:
35: public String toString() {
36: StringBuffer sb = new StringBuffer();
37: sb.append(id).append("[");
38: sb.append(getStatusString());
39: if (suspended) {
40: sb.append(", suspended");
41: }
42: if (readOnly) {
43: sb.append(", readonly");
44: }
45: if (finished) {
46: sb.append(", finished");
47: }
48: sb.append("]");
49: return sb.toString();
50: }
51:
52: private String getStatusString() {
53: switch (status) {
54: case Status.STATUS_ACTIVE:
55: return "active";
56: case Status.STATUS_MARKED_ROLLBACK:
57: return "marked rollback";
58: case Status.STATUS_PREPARED:
59: return "prepared";
60: case Status.STATUS_COMMITTED:
61: return "committed";
62: case Status.STATUS_ROLLEDBACK:
63: return "rolled back";
64: case Status.STATUS_UNKNOWN:
65: return "unknown";
66: case Status.STATUS_NO_TRANSACTION:
67: return "no transaction";
68: case Status.STATUS_PREPARING:
69: return "preparing";
70: case Status.STATUS_COMMITTING:
71: return "committing";
72: case Status.STATUS_ROLLING_BACK:
73: return "rolling back";
74: default:
75: return "undefined status";
76: }
77: }
78:
79: public synchronized void finalCleanUp()
80: throws ResourceManagerException {
81: // nothing to do (yet?)
82: }
83:
84: public synchronized void notifyFinish() {
85: finished = true;
86: notifyAll();
87: }
88:
89: }
|