1 22 package org.enhydra.jdbc.oracle; 23 24 25 import oracle.jdbc.xa.client.OracleXAResource; 26 import oracle.jdbc.xa.OracleXid; 27 import org.enhydra.jdbc.standard.StandardXAConnection; 28 import org.enhydra.jdbc.standard.StandardXADataSource; 29 30 import javax.transaction.xa.XAResource ; 31 import javax.transaction.xa.XAException ; 32 import javax.transaction.xa.Xid ; 33 import java.util.Hashtable ; 34 import java.sql.SQLException ; 35 36 37 44 public final class OracleXAConnection extends StandardXAConnection { 45 46 private XAResource xarsrc = null; 47 private static Hashtable txctxs = new Hashtable (); 48 49 52 public OracleXAConnection (StandardXADataSource dataSource, String user, String password) throws SQLException { 53 super (dataSource, user, password); } 55 56 private OracleXid getOracleXid(Xid xid) throws XAException { 57 if (!(xid instanceof OracleXid)) { 58 byte[] txctx = (byte[])txctxs.get(xid); 59 dataSource.log.debug("txctx is " + txctx); 60 OracleXid newXid = new OracleXid(xid.getFormatId(), xid.getGlobalTransactionId(), xid.getBranchQualifier(), txctx); 61 return newXid; 62 } else { 63 return (OracleXid)xid; 64 } 65 } 66 67 public void commit(Xid xid, boolean flag) throws XAException { 68 dataSource.log.debug("commit:" + xid.getGlobalTransactionId()); 69 xarsrc.commit(getOracleXid(xid), flag); 70 xaDataSource.freeConnection(xid, false); 71 txctxs.remove(xid); 72 } 73 74 public void end(Xid xid, int flags) throws XAException { 75 dataSource.log.debug("end" + ":" + xid.getFormatId() + ":" + xid.getGlobalTransactionId() + ":" + xid.getBranchQualifier() + ":" + flags); 76 xarsrc.end(getOracleXid(xid), flags); 77 } 78 79 public void forget(Xid xid) throws XAException { 80 dataSource.log.debug("forget" + ":" + xid.getGlobalTransactionId()); 81 xarsrc.forget(getOracleXid(xid)); 82 xaDataSource.freeConnection(xid, false); 83 txctxs.remove(xid); 84 } 85 86 public int prepare(Xid xid) throws XAException { 87 dataSource.log.debug("prepare" + ":" + xid.getGlobalTransactionId()); 88 int res = xarsrc.prepare(getOracleXid(xid)); 89 if (res == XA_RDONLY) { 90 xaDataSource.freeConnection(xid, false); 91 txctxs.remove(xid); 92 } 93 return res; 94 } 95 96 public void rollback(Xid xid) throws XAException { 97 dataSource.log.debug("rollback" + ":" + xid.getGlobalTransactionId()); 98 xarsrc.rollback(getOracleXid(xid)); 99 xaDataSource.freeConnection(xid, false); 100 txctxs.remove(xid); 101 } 102 103 public void start(Xid xid, int flags) throws XAException { 104 dataSource.log.debug("start" + ":" + xid.getFormatId() + ":" + xid.getGlobalTransactionId() + ":" + xid.getBranchQualifier() + ":" + flags); 105 doStart(xid, flags); 106 xarsrc = new OracleXAResource(curCon.con); 107 OracleXid oXid = getOracleXid(xid); 108 xarsrc.start(oXid, flags); 109 txctxs.put(xid, oXid.getTxContext()); 110 curCon = null; 111 con = null; 112 } 113 114 public boolean isSameRM(XAResource res) throws XAException { 115 if (!(res instanceof OracleXAConnection)) { 116 dataSource.log.debug("isSameRM returning false"); 117 return false; 118 } 119 OracleXAConnection ores = (OracleXAConnection)res; 120 if (ores.xarsrc.isSameRM(xarsrc)) { 121 dataSource.log.debug("isSameRM returning true"); 122 return true; 123 } 124 dataSource.log.debug("isSameRM returning false"); 125 return false; 126 } 127 128 } 129 | Popular Tags |