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