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