1 46 package org.objectweb.jotm; 47 48 import javax.transaction.xa.Xid ; 49 50 import javax.resource.spi.XATerminator ; 51 52 import javax.transaction.xa.XAException ; 53 54 58 59 public class XATerminatorImpl implements XATerminator { 60 61 private transient static XATerminatorImpl unique = null; 63 64 68 71 private TransactionImpl iftx = null; 72 75 private Xid xid; 76 79 private Log mylog; 80 81 83 private int errorCode; 84 private final static int XA_RBBASE = 100; 85 private final static int XA_RBROLLBACK = XA_RBBASE; 86 private final static int XA_RBCOMMFAIL = XA_RBBASE + 1; 87 private final static int XA_RBDEADLOCK = XA_RBBASE + 2; 88 private final static int XA_RBINTEGRITY = XA_RBBASE + 3; 89 private final static int XA_RBOTHER = XA_RBBASE + 4; 90 private final static int XA_RBPROTO = XA_RBBASE + 5; 91 private final static int XA_RBRBTIMEOUT = XA_RBBASE + 6; 92 private final static int XA_RBTRANSIENT = XA_RBBASE + 7; 93 private final static int XA_RBEND = XA_RBTRANSIENT; 94 private final static int XA_NOMIGRATE = 9; 95 private final static int XA_HEURHAZ = 8; 96 private final static int XA_HEURCOM = 7; 97 private final static int XA_HEURRB = 6; 98 private final static int XA_HEURMIX = 5; 99 private final static int XA_NOTUSED1 = 4; 100 private final static int XA_RDONLY = 3; 101 private final static int XAER_RMERR = -3; 103 private final static int XAER_NOTA = -4; 104 private final static int XAER_INVAL = -5; 105 private final static int XAER_PROTO = -6; 106 private final static int XAER_RMFAIL = -7; 107 private final static int XAER_DUPID = -8; 108 private final static int XAER_OUTSIDE = -9; 109 110 111 115 119 120 public XATerminatorImpl() throws XAException { 121 122 if (TraceTm.jotm.isDebugEnabled()) { 123 TraceTm.jotm.debug("create XATerminator"); 124 } 125 126 unique = this; 127 } 128 129 133 138 139 public String get_transaction_name () throws XAException { 140 141 TraceTm.jotm.debug("XATerminatorImpl.get_transaction_name()"); 142 143 return xid.toString(); 144 } 145 146 161 162 public void commit (Xid xid, boolean onePhase) throws XAException { 163 164 if (TraceTm.jotm.isDebugEnabled()) { 165 TraceTm.jotm.debug("commit xid="+ xid + "onePhase="+ onePhase); 166 } 167 168 171 XidImpl myxid = new XidImpl(xid); 172 iftx = Current.getCurrent().getTxByXid(myxid); 173 174 if (iftx == null) { 175 TraceTm.jotm.error("XATerminatorImpl.commit(): unknown xid " + xid); 176 throw new XAException (XAER_NOTA); 177 } 178 179 try { 180 iftx.commit(); 181 } catch (Exception e) { 182 TraceTm.jotm.error("XATerminatorImpl.commit(): commit raised exception ", e); 183 } 184 } 185 186 199 200 public void rollback (Xid xid) throws XAException { 201 202 if (TraceTm.jotm.isDebugEnabled()) { 203 TraceTm.jotm.debug("rollback xid="+ xid); 204 } 205 206 209 XidImpl myxid = new XidImpl(xid); 210 iftx = Current.getCurrent().getTxByXid(myxid); 211 212 if (iftx == null) { 213 TraceTm.jotm.error("XATerminatorImpl.rollback(): unknown xid " + xid); 214 throw new XAException (XAER_NOTA); 215 } 216 217 try { 218 iftx.rollback(); 219 } catch (Exception e) { 220 TraceTm.jotm.error("XATerminatorImpl.rollback(): rollback raised exception ", e); 221 } 222 } 223 224 239 240 public int prepare (Xid xid) throws XAException { 241 242 int ret = 0; 243 244 if (TraceTm.jotm.isDebugEnabled()) { 245 TraceTm.jotm.debug("prepare xid="+ xid); 246 } 247 248 251 XidImpl myxid = new XidImpl(xid); 252 iftx = Current.getCurrent().getTxByXid(myxid); 253 254 if (iftx == null) { 255 TraceTm.jotm.error("XATerminatorImpl.prepare(): unknown xid " + xid); 256 throw new XAException (XAER_NOTA); 257 } 258 259 try { 260 ret = iftx.prepare(); 261 } catch (Exception e) { 262 TraceTm.jotm.error("XATerminatorImpl.prepare(): prepare raised exception ", e); 263 } 264 265 return ret; 266 } 267 268 276 277 public void forget (Xid xid) throws XAException { 278 279 TraceTm.jotm.debug("XATerminatorImpl.forget()"); 280 281 284 XidImpl myxid = new XidImpl(xid); 285 286 try { 287 Current.getCurrent().forgetTx(myxid); 288 } catch (Exception e) { 289 TraceTm.jotm.error("XATerminatorImpl.forget(): forget raised exception ", e); 290 } 291 } 292 293 309 310 public Xid[] recover (int flag) throws XAException { 311 312 TraceTm.jotm.debug("XATerminatorImpl.recover()"); 313 314 316 return (Xid []) Current.getCurrent().getPreparedHeuristicXid(); 317 318 } 319 320 } 321 | Popular Tags |