KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > connectionmanager > xa > XAResourceWrapper


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22
23 package org.jboss.resource.connectionmanager.xa;
24
25 import java.io.Serializable JavaDoc;
26
27 import javax.transaction.xa.XAException JavaDoc;
28 import javax.transaction.xa.XAResource JavaDoc;
29 import javax.transaction.xa.Xid JavaDoc;
30
31 import org.jboss.logging.Logger;
32
33 /**
34  * A XAResourceWrapper.
35  *
36  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
37  * @version $Revision: 1.1 $
38  */

39 public class XAResourceWrapper implements XAResource JavaDoc, Serializable JavaDoc
40 {
41
42    /** The serialVersionUID */
43    private static final long serialVersionUID = 4551722165222496828L;
44
45    private static final Logger log = Logger.getLogger(XAResourceWrapper.class);
46    
47    /** The xaResource */
48    private XAResource JavaDoc xaResource;
49
50    private boolean pad;
51
52    private Boolean JavaDoc overrideRmValue;
53    
54    public XAResourceWrapper(XAResource JavaDoc resource)
55    {
56       this(Boolean.FALSE, false, resource);
57
58    }
59
60    public XAResourceWrapper(boolean pad, XAResource JavaDoc resource)
61    {
62       this(Boolean.FALSE, pad, resource);
63    }
64
65    public XAResourceWrapper(Boolean JavaDoc override, boolean pad, XAResource JavaDoc resource)
66    {
67       this.overrideRmValue = override;
68       this.pad = pad;
69       this.xaResource = resource;
70
71    }
72
73    public void commit(Xid JavaDoc xid, boolean onePhase) throws XAException JavaDoc
74    {
75       xid = convertXid(xid);
76       xaResource.commit(xid, onePhase);
77    }
78
79    public void end(Xid JavaDoc xid, int flags) throws XAException JavaDoc
80    {
81       xid = convertXid(xid);
82       xaResource.end(xid, flags);
83
84    }
85
86    public void forget(Xid JavaDoc xid) throws XAException JavaDoc
87    {
88       xid = convertXid(xid);
89       xaResource.forget(xid);
90    }
91
92    public int getTransactionTimeout() throws XAException JavaDoc
93    {
94       return xaResource.getTransactionTimeout();
95    }
96
97    public boolean isSameRM(XAResource JavaDoc resource) throws XAException JavaDoc
98    {
99       
100       if (overrideRmValue != null)
101       {
102          if(log.isTraceEnabled())
103          {
104             log.trace("Executing isSameRM with override value" + overrideRmValue + " for XAResourceWrapper" + this);
105             
106          }
107          
108          return overrideRmValue.booleanValue();
109
110       }
111       else
112       {
113          if(resource instanceof XAResourceWrapper)
114          {
115             XAResourceWrapper other = (XAResourceWrapper)resource;
116             return xaResource.isSameRM(other.getResource());
117             
118          }else
119          {
120             return xaResource.isSameRM(resource);
121             
122          }
123          
124       }
125
126    }
127
128    public int prepare(Xid JavaDoc xid) throws XAException JavaDoc
129    {
130       xid = convertXid(xid);
131       return xaResource.prepare(xid);
132    }
133
134    public Xid JavaDoc[] recover(int flag) throws XAException JavaDoc
135    {
136
137       return xaResource.recover(flag);
138    }
139
140    public void rollback(Xid JavaDoc xid) throws XAException JavaDoc
141    {
142       xid = convertXid(xid);
143       xaResource.rollback(xid);
144    }
145
146    public boolean setTransactionTimeout(int flag) throws XAException JavaDoc
147    {
148       return xaResource.setTransactionTimeout(flag);
149
150    }
151
152    public void start(Xid JavaDoc xid, int flags) throws XAException JavaDoc
153    {
154       xid = convertXid(xid);
155       xaResource.start(xid, flags);
156    }
157
158    private Xid JavaDoc convertXid(Xid JavaDoc xid)
159    {
160             
161       if (xid instanceof JcaXid)
162          return xid;
163
164       else
165          return new JcaXid(pad, xid);
166
167    }
168
169    private XAResource JavaDoc getResource()
170    {
171       return xaResource;
172    }
173    
174    public String JavaDoc toString()
175    {
176       return super.toString();
177    }
178
179 }
180
Popular Tags