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