1 17 18 package org.apache.geronimo.transaction.manager; 19 20 import java.sql.Connection ; 21 import java.sql.Statement ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.List ; 25 import javax.sql.XAConnection ; 26 import javax.sql.XADataSource ; 27 import javax.transaction.TransactionManager ; 28 import javax.transaction.xa.XAResource ; 29 import javax.transaction.xa.Xid ; 30 31 37 public class XATransactionTester { 38 private TransactionManager manager; 39 private XADataSource ds; 40 private Xid xid; 41 42 public static void main(String [] args) throws Exception { 43 new XATransactionTester().run(args); 44 } 45 46 public void run(String [] args) throws Exception { 47 ds = getDataSource(args); 48 XAConnection xaConn = ds.getXAConnection("test", "test"); 49 XAResource xaRes = xaConn.getXAResource(); 50 manager = new TransactionManagerImpl(10, new DummyLog()); 51 Connection c = xaConn.getConnection(); 52 Statement s = c.createStatement(); 53 54 manager.begin(); 55 manager.getTransaction().enlistResource(xaRes); 56 s.execute("UPDATE XA_TEST SET X=X+1"); 57 manager.getTransaction().delistResource(xaRes, XAResource.TMSUCCESS); 58 manager.commit(); 59 60 71 72 87 88 } 89 90 93 private XADataSource getDataSource(String [] args) throws Exception { 94 return null; 98 } 99 100 private class DummyLog implements TransactionLog { 101 102 public void begin(Xid xid) throws LogException { 103 XATransactionTester.this.xid = xid; 104 } 105 106 public Object prepare(Xid xid, List branches) throws LogException { 107 return new Object (); 108 } 109 110 public void commit(Xid xid, Object logMark) throws LogException { 111 } 112 113 public void rollback(Xid xid, Object logMark) throws LogException { 114 } 115 116 public Collection recover(XidFactory xidFactory) throws LogException { 117 return new ArrayList (); 118 } 119 120 public String getXMLStats() { 121 return null; 122 } 123 124 public int getAverageForceTime() { 125 return 0; 126 } 127 128 public int getAverageBytesPerForce() { 129 return 0; 130 } 131 } 132 } 133 | Popular Tags |