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 org.apache.commons.logging.Log; |
20 | |
import org.apache.commons.logging.LogFactory; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 0 | public abstract class AbstractTransaction implements UMOTransaction |
26 | |
{ |
27 | |
|
28 | 0 | protected final transient Log logger = LogFactory.getLog(getClass()); |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public boolean isRollbackOnly() throws TransactionException |
36 | |
{ |
37 | 0 | 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 | 0 | logger.debug("Beginning transaction"); |
79 | 0 | doBegin(); |
80 | 0 | TransactionCoordination.getInstance().bindTransaction(this); |
81 | 0 | fireNotification(new TransactionNotification(this, TransactionNotification.TRANSACTION_BEGAN)); |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public void commit() throws TransactionException |
90 | |
{ |
91 | |
try |
92 | |
{ |
93 | 0 | logger.debug("Committing transaction"); |
94 | |
|
95 | 0 | if (isRollbackOnly()) |
96 | |
{ |
97 | 0 | throw new IllegalTransactionStateException(CoreMessages.transactionMarkedForRollback()); |
98 | |
} |
99 | |
|
100 | 0 | doCommit(); |
101 | 0 | fireNotification(new TransactionNotification(this, TransactionNotification.TRANSACTION_COMMITTED)); |
102 | |
} |
103 | |
finally |
104 | |
{ |
105 | 0 | TransactionCoordination.getInstance().unbindTransaction(this); |
106 | 0 | } |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public void rollback() throws TransactionException |
115 | |
{ |
116 | |
try |
117 | |
{ |
118 | 0 | logger.debug("Rolling back transaction"); |
119 | 0 | setRollbackOnly(); |
120 | 0 | doRollback(); |
121 | 0 | fireNotification(new TransactionNotification(this, TransactionNotification.TRANSACTION_ROLLEDBACK)); |
122 | |
} |
123 | |
finally |
124 | |
{ |
125 | 0 | TransactionCoordination.getInstance().unbindTransaction(this); |
126 | 0 | } |
127 | 0 | } |
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 | 0 | MuleManager.getInstance().fireNotification(notification); |
158 | 0 | } |
159 | |
|
160 | |
} |