00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00086
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
00185
00186
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 }