1 7 package org.jboss.test.tm.resource; 8 9 import javax.transaction.xa.XAException ; 10 import javax.transaction.xa.XAResource ; 11 import javax.transaction.xa.Xid ; 12 13 import org.jboss.tm.LastResource; 14 15 21 public class LocalResource extends Resource implements LastResource 22 { 23 24 private boolean failLocal = false; 25 26 31 public LocalResource(Integer id) 32 { 33 super(id); 34 } 35 36 public void failLocal() 37 { 38 failLocal = true; 39 } 40 41 public int prepare(Xid xid) throws XAException 42 { 43 XAException e = new XAException ("Prepare called on local resource"); 44 e.errorCode = XAException.XAER_PROTO; 45 throw e; 46 } 47 48 public void commit(Xid xid, boolean onePhase) throws XAException 49 { 50 State state = getState(xid); 51 if (state.resState != ACTIVE && state.resState != ENDED) 52 { 53 state.resState = ERROR; 54 throw new XAException (XAException.XAER_PROTO); 55 } 56 if (failLocal) 57 { 58 state.resState = ROLLEDBACK; 59 state.removed = true; 60 throw new XAException (XAException.XA_RBROLLBACK); 61 } 62 else 63 { 64 state.resState = COMMITTED; 65 state.removed = true; 66 } 67 } 68 69 public boolean isSameRM(XAResource res) 70 { 71 return res == this; 72 } 73 } 74 | Popular Tags |