1 17 18 package org.apache.geronimo.connector.outbound.transactionlog; 19 20 import javax.resource.ResourceException ; 21 import javax.resource.spi.LocalTransaction ; 22 import javax.transaction.xa.XAException ; 23 import javax.transaction.xa.XAResource ; 24 import javax.transaction.xa.Xid ; 25 26 import org.apache.geronimo.transaction.manager.NamedXAResource; 27 28 35 public class LogXAResource implements NamedXAResource { 36 37 final String name; 38 final LocalTransaction localTransaction; 39 private Xid xid; 40 41 public LogXAResource(LocalTransaction localTransaction, String name) { 42 this.localTransaction = localTransaction; 43 this.name = name; 44 } 45 public void commit(Xid xid, boolean onePhase) throws XAException { 46 } 47 48 public void end(Xid xid, int flags) throws XAException { 49 } 50 51 public void forget(Xid xid) throws XAException { 52 } 53 54 public int getTransactionTimeout() throws XAException { 55 return 0; 56 } 57 58 public boolean isSameRM(XAResource xaResource) throws XAException { 59 return this == xaResource; 60 } 61 62 public int prepare(Xid xid) throws XAException { 63 return 0; 64 } 65 66 public Xid [] recover(int flag) throws XAException { 67 return new Xid [0]; 68 } 69 70 public void rollback(Xid xid) throws XAException { 71 if (this.xid == null || !this.xid.equals(xid)) { 72 throw new XAException (); 73 } 74 try { 75 localTransaction.rollback(); 76 } catch (ResourceException e) { 77 throw (XAException )new XAException ().initCause(e); 78 } finally { 79 this.xid = null; 80 } 81 } 82 83 public boolean setTransactionTimeout(int seconds) throws XAException { 84 return false; 85 } 86 87 public void start(Xid xid, int flag) throws XAException { 88 if (flag == XAResource.TMNOFLAGS) { 89 if (this.xid != null) { 91 throw new XAException ("already enlisted"); 92 } 93 this.xid = xid; 94 try { 95 localTransaction.begin(); 96 } catch (ResourceException e) { 97 throw (XAException ) new XAException ("could not start local tx").initCause(e); 98 } 99 } else if (flag == XAResource.TMRESUME) { 100 if (xid != this.xid) { 101 throw new XAException ("attempting to resume in different transaction"); 102 } 103 } else { 104 throw new XAException ("unknown state"); 105 } 106 } 107 108 public String getName() { 109 return name; 110 } 111 } 112 | Popular Tags |