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 | 0 | public class XaTransactionFactory implements ExternalTransactionAwareTransactionFactory |
22 | |
{ |
23 | |
public Transaction beginTransaction(MuleContext muleContext) throws TransactionException |
24 | |
{ |
25 | |
try |
26 | |
{ |
27 | 0 | XaTransaction xat = new XaTransaction(muleContext); |
28 | 0 | xat.begin(); |
29 | 0 | return xat; |
30 | |
} |
31 | 0 | catch (Exception e) |
32 | |
{ |
33 | 0 | 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 | 0 | TransactionManager txManager = muleContext.getTransactionManager(); |
45 | 0 | if (txManager.getTransaction() == null) |
46 | |
{ |
47 | 0 | return null; |
48 | |
} |
49 | 0 | XaTransaction xat = new ExternalXaTransaction(muleContext); |
50 | 0 | xat.begin(); |
51 | 0 | return xat; |
52 | |
} |
53 | 0 | catch (Exception e) |
54 | |
{ |
55 | 0 | throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e); |
56 | |
} |
57 | |
} |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public boolean isTransacted() |
65 | |
{ |
66 | 0 | return true; |
67 | |
} |
68 | |
} |