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