1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transaction; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.config.i18n.CoreMessages; |
15 | |
import org.mule.impl.internal.notifications.TransactionNotification; |
16 | |
import org.mule.umo.TransactionException; |
17 | |
import org.mule.umo.UMOTransaction; |
18 | |
|
19 | |
import javax.transaction.Transaction; |
20 | |
|
21 | |
import org.apache.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 2 | public abstract class AbstractTransaction implements UMOTransaction |
28 | |
{ |
29 | |
|
30 | 2 | protected final transient Log logger = LogFactory.getLog(getClass()); |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public boolean isRollbackOnly() throws TransactionException |
38 | |
{ |
39 | 2 | return getStatus() == STATUS_MARKED_ROLLBACK; |
40 | |
} |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public boolean isBegun() throws TransactionException |
48 | |
{ |
49 | 0 | int status = getStatus(); |
50 | 0 | return status != STATUS_NO_TRANSACTION && status != STATUS_UNKNOWN; |
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public boolean isRolledBack() throws TransactionException |
59 | |
{ |
60 | 0 | return getStatus() == STATUS_ROLLEDBACK; |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public boolean isCommitted() throws TransactionException |
69 | |
{ |
70 | 0 | return getStatus() == STATUS_COMMITTED; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public void begin() throws TransactionException |
79 | |
{ |
80 | 2 | logger.debug("Beginning transaction"); |
81 | 2 | doBegin(); |
82 | 2 | TransactionCoordination.getInstance().bindTransaction(this); |
83 | 2 | fireNotification(new TransactionNotification(this, TransactionNotification.TRANSACTION_BEGAN)); |
84 | 2 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void commit() throws TransactionException |
92 | |
{ |
93 | |
try |
94 | |
{ |
95 | 2 | logger.debug("Committing transaction " + this); |
96 | |
|
97 | 2 | if (isRollbackOnly()) |
98 | |
{ |
99 | 0 | throw new IllegalTransactionStateException(CoreMessages.transactionMarkedForRollback()); |
100 | |
} |
101 | |
|
102 | 2 | doCommit(); |
103 | 2 | fireNotification(new TransactionNotification(this, TransactionNotification.TRANSACTION_COMMITTED)); |
104 | |
} |
105 | |
finally |
106 | |
{ |
107 | 2 | TransactionCoordination.getInstance().unbindTransaction(this); |
108 | 2 | } |
109 | 2 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public void rollback() throws TransactionException |
117 | |
{ |
118 | |
try |
119 | |
{ |
120 | 2 | logger.debug("Rolling back transaction"); |
121 | 2 | setRollbackOnly(); |
122 | 2 | doRollback(); |
123 | 2 | fireNotification(new TransactionNotification(this, TransactionNotification.TRANSACTION_ROLLEDBACK)); |
124 | |
} |
125 | |
finally |
126 | |
{ |
127 | 2 | TransactionCoordination.getInstance().unbindTransaction(this); |
128 | 2 | } |
129 | 2 | } |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
protected abstract void doBegin() throws TransactionException; |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
protected abstract void doCommit() throws TransactionException; |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
protected abstract void doRollback() throws TransactionException; |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
protected void fireNotification(TransactionNotification notification) |
158 | |
{ |
159 | 6 | MuleManager.getInstance().fireNotification(notification); |
160 | 6 | } |
161 | |
|
162 | |
public boolean isXA() |
163 | |
{ |
164 | 0 | return false; |
165 | |
} |
166 | |
|
167 | |
public void resume() throws TransactionException |
168 | |
{ |
169 | 0 | throw new IllegalTransactionStateException(CoreMessages.notMuleXaTransaction(this)); |
170 | |
} |
171 | |
|
172 | |
public Transaction suspend() throws TransactionException |
173 | |
{ |
174 | 0 | throw new IllegalTransactionStateException(CoreMessages.notMuleXaTransaction(this)); |
175 | |
} |
176 | |
} |