View Javadoc

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