LocalXAWrapper.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * --------------------------------------------------------------------------
00022  * $Id: LocalXAWrapper.java,v 1.6 2004/10/29 23:33:37 ehardesty Exp $
00023  * --------------------------------------------------------------------------
00024  */
00025 
00026 
00027 package org.objectweb.jonas.resource;
00028 
00029 import javax.resource.ResourceException;
00030 import javax.resource.spi.LocalTransaction;
00031 
00032 import javax.transaction.xa.XAResource;
00033 import javax.transaction.xa.XAException;
00034 import javax.transaction.xa.Xid;
00035 
00036 import org.objectweb.util.monolog.api.Logger;
00037 import org.objectweb.util.monolog.api.BasicLevel;
00038 
00046 public final class LocalXAWrapper
00047     implements XAResource {
00048 
00052     private static Logger logger = null;
00053 
00057     protected boolean isInTransaction;
00058 
00063     protected LocalTransaction localTrans = null;
00064 
00065     LocalXAWrapper(LocalTransaction _localTrans, Logger _logger) {
00066         isInTransaction = false;
00067         localTrans = _localTrans;
00068         logger = _logger;
00069     }
00070 
00079     public void commit(Xid xid, boolean flag)
00080         throws XAException {
00081         logger.log(BasicLevel.DEBUG, "Xid =" + xid + "flag=" + flag);
00082 
00083 
00084         if (isInTransaction) {
00085             // Unbalance start/end. Probably a close is missing.
00086             // We decide to unset isInTransaction here to avoid a further error
00087             logger.log(BasicLevel.DEBUG, "XA START without XA END");
00088             isInTransaction = false;
00089         }
00090 
00091         try {
00092             localTrans.commit();
00093         } catch (ResourceException res) {
00094             throw new XAException(res.toString());
00095         }
00096     }
00097 
00102     public void end(Xid xid, int i)
00103         throws XAException {
00104         logger.log(BasicLevel.DEBUG, "Xid =" + xid + "i=" + i);
00105         if (!isInTransaction) {
00106             logger.log(BasicLevel.ERROR, "END without START");
00107             XAException ex = new XAException(XAException.XA_RBPROTO);
00108             throw(ex);
00109         }
00110         isInTransaction = false;
00111 
00112     }
00113 
00118     public void forget(Xid xid)
00119         throws XAException {
00120         logger.log(BasicLevel.DEBUG, "");
00121     }
00122 
00127     public int getTransactionTimeout()
00128         throws XAException {
00129         logger.log(BasicLevel.DEBUG, "");
00130         return -1;
00131     }
00132 
00141     public boolean isSameRM(XAResource xaresource)
00142         throws XAException {
00143         logger.log(BasicLevel.DEBUG, "");
00144 
00145         if (xaresource.equals(this)) {
00146             logger.log(BasicLevel.DEBUG, "isSameRM = true " + this);
00147             return true;
00148         }
00149         logger.log(BasicLevel.DEBUG, "isSameRM = false " + this);
00150         return false;
00151     }
00152 
00157     public int prepare(Xid xid)
00158         throws XAException {
00159         logger.log(BasicLevel.DEBUG, "");
00160         return XAResource.XA_OK;
00161     }
00162 
00166     public Xid[] recover(int i)
00167         throws XAException {
00168         logger.log(BasicLevel.DEBUG, "");
00169         return null;
00170     }
00171 
00179     public void rollback(Xid xid)
00180         throws XAException {
00181         logger.log(BasicLevel.DEBUG, "Xid =" + xid);
00182 
00183         if (isInTransaction) {
00184             // Unbalance start/end. Probably a close is missing.
00185             // We decide to unset isInTransaction here to avoid a further error, but
00186             // I'm not sure it's a good idea.
00187             logger.log(BasicLevel.DEBUG, "XA START without XA END");
00188             isInTransaction = false;
00189         }
00190 
00191         try {
00192             localTrans.rollback();
00193         } catch (ResourceException res) {
00194             throw new XAException("Rollback failed, " + res.getMessage());
00195         }
00196     }
00197 
00202     public boolean setTransactionTimeout(int i)
00203         throws XAException {
00204         logger.log(BasicLevel.DEBUG, "");
00205         return false;
00206     }
00207 
00216     public void start(Xid xid, int i)
00217         throws XAException {
00218         logger.log(BasicLevel.DEBUG, "Xid =" + xid + "i=" + i);
00219         try {
00220             if (i != XAResource.TMJOIN && i != XAResource.TMRESUME) {
00221                 if (isInTransaction) {
00222                     throw new XAException("LocalXAWrapper.start:  Local transaction already started");
00223                 }
00224                 localTrans.begin();
00225                 isInTransaction = true;
00226             }
00227         } catch (ResourceException res) {
00228             throw new XAException("LocalTransaction.begin failed, " + res.toString());
00229         }
00230         logger.log(BasicLevel.DEBUG, "OK");
00231     }
00232 }

Generated on Tue Feb 15 15:05:19 2005 for JOnAS by  doxygen 1.3.9.1