View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.jms.xa;
8   
9   import javax.transaction.xa.XAException;
10  import javax.transaction.xa.XAResource;
11  import javax.transaction.xa.Xid;
12  
13  public class XAResourceWrapper implements XAResource
14  {
15      private XAResource xaResource;
16      private SessionInvocationHandler sessionInvocationHandler;
17      private Boolean sameRMOverrideValue;
18  
19  
20      public XAResourceWrapper(XAResource xaResource, SessionInvocationHandler sessionInvocationHandler, Boolean sameRMOverrideValue)
21      {
22          this.xaResource = xaResource;
23          this.sessionInvocationHandler = sessionInvocationHandler;
24          this.sameRMOverrideValue = sameRMOverrideValue;
25      }
26  
27      public int getTransactionTimeout() throws XAException
28      {
29          return xaResource.getTransactionTimeout();
30      }
31  
32      public boolean setTransactionTimeout(int i) throws XAException
33      {
34          return xaResource.setTransactionTimeout(i);
35      }
36  
37      public boolean isSameRM(XAResource other) throws XAException
38      {
39          if (sameRMOverrideValue != null)
40          {
41              return sameRMOverrideValue;
42          }
43  
44          if (other instanceof XAResourceWrapper)
45          {
46              other = ((XAResourceWrapper) other).xaResource;
47          }
48          return this.xaResource.isSameRM(other);
49      }
50  
51      public Xid[] recover(int i) throws XAException
52      {
53          return xaResource.recover(i);
54      }
55  
56      public int prepare(Xid xid) throws XAException
57      {
58          return xaResource.prepare(xid);
59      }
60  
61      public void forget(Xid xid) throws XAException
62      {
63          xaResource.forget(xid);
64      }
65  
66      public void rollback(Xid xid) throws XAException
67      {
68          xaResource.rollback(xid);
69      }
70  
71      public void end(Xid xid, int i) throws XAException
72      {
73          xaResource.end(xid, i);
74          sessionInvocationHandler.setEnlisted(false);
75      }
76  
77      public void start(Xid xid, int i) throws XAException
78      {
79          xaResource.start(xid, i);
80      }
81  
82      public void commit(Xid xid, boolean b) throws XAException
83      {
84          xaResource.commit(xid, b);
85      }
86  
87      @Override
88      public String toString()
89      {
90          return xaResource.toString();
91      }
92  }