001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022:
023: package org.jboss.resource.connectionmanager.xa;
024:
025: import javax.transaction.xa.XAException;
026: import javax.transaction.xa.XAResource;
027: import javax.transaction.xa.Xid;
028:
029: import org.jboss.logging.Logger;
030:
031: /**
032: * A XAResourceWrapper supporting JCA specific constructs for XAResource management primarily
033: * the isSameRMOverrideValue.
034: *
035: * @author <a href="weston.price@jboss.org">Weston Price</a>
036: * @version $Revision: 1.1 $
037: */
038: public class JcaXAResourceWrapper implements XAResource {
039: private static final Logger log = Logger
040: .getLogger(JcaXAResourceWrapper.class);
041:
042: private final XAResource resource;
043: private Boolean overrideSameRM;
044:
045: public JcaXAResourceWrapper(final XAResource resource,
046: final Boolean overrideSameRM) {
047: this .resource = resource;
048: this .overrideSameRM = overrideSameRM;
049: }
050:
051: public void commit(Xid xid, boolean onePhase) throws XAException {
052: resource.commit(xid, onePhase);
053: }
054:
055: public void end(Xid xid, int flags) throws XAException {
056: resource.end(xid, flags);
057: }
058:
059: public void forget(Xid xid) throws XAException {
060: resource.forget(xid);
061: }
062:
063: public int getTransactionTimeout() throws XAException {
064: return resource.getTransactionTimeout();
065: }
066:
067: public boolean isSameRM(XAResource xaRes) throws XAException {
068:
069: if (overrideSameRM != null) {
070: return overrideSameRM.booleanValue();
071: }
072:
073: if (xaRes instanceof JcaXAResourceWrapper) {
074: final JcaXAResourceWrapper jca = (JcaXAResourceWrapper) xaRes;
075: xaRes = jca.getUnderlyingXAResource();
076: }
077:
078: final XAResource current = getUnderlyingXAResource();
079:
080: return current.isSameRM(xaRes);
081:
082: }
083:
084: public int prepare(Xid xid) throws XAException {
085: return resource.prepare(xid);
086: }
087:
088: public Xid[] recover(int flag) throws XAException {
089: return resource.recover(flag);
090: }
091:
092: public void rollback(Xid xid) throws XAException {
093: resource.rollback(xid);
094: }
095:
096: public boolean setTransactionTimeout(int seconds)
097: throws XAException {
098: return resource.setTransactionTimeout(seconds);
099: }
100:
101: public void start(Xid xid, int flags) throws XAException {
102: resource.start(xid, flags);
103: }
104:
105: public XAResource getUnderlyingXAResource() {
106: return this.resource;
107: }
108:
109: }
|