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