1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.util.xa; |
12 | |
|
13 | |
import javax.transaction.Status; |
14 | |
|
15 | |
import org.safehaus.uuid.UUIDGenerator; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
public class AbstractTransactionContext |
22 | |
{ |
23 | |
|
24 | 0 | private static UUIDGenerator gen = UUIDGenerator.getInstance(); |
25 | |
|
26 | 0 | 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 | 0 | { |
35 | 0 | status = Status.STATUS_NO_TRANSACTION; |
36 | 0 | suspended = false; |
37 | 0 | finished = false; |
38 | 0 | readOnly = true; |
39 | 0 | } |
40 | |
|
41 | |
public String toString() |
42 | |
{ |
43 | 0 | StringBuffer sb = new StringBuffer(); |
44 | 0 | sb.append(id).append("["); |
45 | 0 | sb.append(getStatusString()); |
46 | 0 | if (suspended) |
47 | |
{ |
48 | 0 | sb.append(", suspended"); |
49 | |
} |
50 | 0 | if (readOnly) |
51 | |
{ |
52 | 0 | sb.append(", readonly"); |
53 | |
} |
54 | 0 | if (finished) |
55 | |
{ |
56 | 0 | sb.append(", finished"); |
57 | |
} |
58 | 0 | sb.append("]"); |
59 | 0 | return sb.toString(); |
60 | |
} |
61 | |
|
62 | |
private String getStatusString() |
63 | |
{ |
64 | 0 | switch (status) |
65 | |
{ |
66 | |
case Status.STATUS_ACTIVE : |
67 | 0 | return "active"; |
68 | |
case Status.STATUS_MARKED_ROLLBACK : |
69 | 0 | return "marked rollback"; |
70 | |
case Status.STATUS_PREPARED : |
71 | 0 | return "prepared"; |
72 | |
case Status.STATUS_COMMITTED : |
73 | 0 | return "committed"; |
74 | |
case Status.STATUS_ROLLEDBACK : |
75 | 0 | return "rolled back"; |
76 | |
case Status.STATUS_UNKNOWN : |
77 | 0 | return "unknown"; |
78 | |
case Status.STATUS_NO_TRANSACTION : |
79 | 0 | return "no transaction"; |
80 | |
case Status.STATUS_PREPARING : |
81 | 0 | return "preparing"; |
82 | |
case Status.STATUS_COMMITTING : |
83 | 0 | return "committing"; |
84 | |
case Status.STATUS_ROLLING_BACK : |
85 | 0 | return "rolling back"; |
86 | |
default : |
87 | 0 | return "undefined status"; |
88 | |
} |
89 | |
} |
90 | |
|
91 | |
public synchronized void finalCleanUp() throws ResourceManagerException |
92 | |
{ |
93 | |
|
94 | 0 | } |
95 | |
|
96 | |
public synchronized void notifyFinish() |
97 | |
{ |
98 | 0 | finished = true; |
99 | 0 | notifyAll(); |
100 | 0 | } |
101 | |
|
102 | |
} |