1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.vm; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.config.i18n.CoreMessages; |
15 | |
import org.mule.transaction.AbstractSingleResourceTransaction; |
16 | |
import org.mule.transaction.IllegalTransactionStateException; |
17 | |
import org.mule.umo.TransactionException; |
18 | |
import org.mule.util.queue.QueueManager; |
19 | |
import org.mule.util.queue.QueueSession; |
20 | |
import org.mule.util.xa.ResourceManagerException; |
21 | |
|
22 | |
public class VMTransaction extends AbstractSingleResourceTransaction |
23 | |
{ |
24 | |
|
25 | |
public VMTransaction() throws TransactionException |
26 | 9 | { |
27 | 10 | QueueManager qm = MuleManager.getInstance().getQueueManager(); |
28 | 10 | QueueSession qs = qm.getQueueSession(); |
29 | 10 | bindResource(qm, qs); |
30 | 9 | } |
31 | |
|
32 | |
public void bindResource(Object key, Object resource) throws TransactionException |
33 | |
{ |
34 | 10 | if (!(key instanceof QueueManager) || !(resource instanceof QueueSession)) |
35 | |
{ |
36 | 0 | throw new IllegalTransactionStateException( |
37 | |
CoreMessages.transactionCanOnlyBindToResources("QueueManager/QueueSession")); |
38 | |
} |
39 | 10 | super.bindResource(key, resource); |
40 | 8 | } |
41 | |
|
42 | |
protected void doBegin() throws TransactionException |
43 | |
{ |
44 | |
try |
45 | |
{ |
46 | 10 | ((QueueSession)resource).begin(); |
47 | |
} |
48 | 0 | catch (ResourceManagerException e) |
49 | |
{ |
50 | 0 | throw new TransactionException(CoreMessages.cannotStartTransaction("VMTransaction"), e); |
51 | 9 | } |
52 | 9 | } |
53 | |
|
54 | |
protected void doCommit() throws TransactionException |
55 | |
{ |
56 | |
try |
57 | |
{ |
58 | 10 | ((QueueSession)resource).commit(); |
59 | |
} |
60 | 0 | catch (ResourceManagerException e) |
61 | |
{ |
62 | 0 | throw new TransactionException(CoreMessages.transactionCommitFailed(), e); |
63 | 10 | } |
64 | 10 | } |
65 | |
|
66 | |
protected void doRollback() throws TransactionException |
67 | |
{ |
68 | |
try |
69 | |
{ |
70 | 0 | ((QueueSession)resource).rollback(); |
71 | |
} |
72 | 0 | catch (ResourceManagerException e) |
73 | |
{ |
74 | 0 | throw new TransactionException(CoreMessages.transactionRollbackFailed(), e); |
75 | 0 | } |
76 | 0 | } |
77 | |
|
78 | |
} |