1
2
3
4
5
6
7 package org.mule.transaction;
8
9 import org.mule.api.MuleContext;
10 import org.mule.api.transaction.ExternalTransactionAwareTransactionFactory;
11 import org.mule.api.transaction.Transaction;
12 import org.mule.api.transaction.TransactionException;
13 import org.mule.config.i18n.CoreMessages;
14
15 import javax.transaction.TransactionManager;
16
17
18
19
20
21 public class XaTransactionFactory implements ExternalTransactionAwareTransactionFactory
22 {
23 public Transaction beginTransaction(MuleContext muleContext) throws TransactionException
24 {
25 try
26 {
27 XaTransaction xat = new XaTransaction(muleContext);
28 xat.begin();
29 return xat;
30 }
31 catch (Exception e)
32 {
33 throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
34 }
35 }
36
37
38
39
40 public Transaction joinExternalTransaction(MuleContext muleContext) throws TransactionException
41 {
42 try
43 {
44 TransactionManager txManager = muleContext.getTransactionManager();
45 if (txManager.getTransaction() == null)
46 {
47 return null;
48 }
49 XaTransaction xat = new ExternalXaTransaction(muleContext);
50 xat.begin();
51 return xat;
52 }
53 catch (Exception e)
54 {
55 throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
56 }
57 }
58
59
60
61
62
63
64 public boolean isTransacted()
65 {
66 return true;
67 }
68 }