1 21 package org.apache.derby.client; 22 23 import java.sql.Connection ; 24 import java.sql.SQLException ; 25 import javax.sql.XAConnection ; 26 import javax.transaction.xa.XAResource ; 27 28 import org.apache.derby.client.am.SqlException; 29 import org.apache.derby.client.net.NetLogWriter; 30 import org.apache.derby.client.net.NetXAConnection; 31 import org.apache.derby.jdbc.ClientXADataSource; 32 33 public class ClientXAConnection extends ClientPooledConnection implements XAConnection { 34 private static int rmIdSeed_ = 95688932; 36 private ClientXADataSource derbyds_ = null; 37 private XAResource xares_ = null; 38 private org.apache.derby.client.net.NetXAResource netXares_ = null; 39 private boolean fFirstGetConnection_ = true; 40 private Connection logicalCon_; private NetXAConnection controlCon_ = null; 43 44 public ClientXAConnection(ClientXADataSource ds, 45 org.apache.derby.client.net.NetLogWriter logWtr, 46 String userId, 47 String password) throws SQLException { 48 super(ds, logWtr, userId, password, getUnigueRmId()); 49 derbyds_ = ds; 50 51 logicalCon_ = super.getConnection(); 56 57 netXares_ = new org.apache.derby.client.net.NetXAResource(this, 58 rmId_, userId, password, netXAPhysicalConnection_); 59 xares_ = netXares_; 60 } 61 62 public Connection getConnection() throws SQLException { 63 if (fFirstGetConnection_) { 64 fFirstGetConnection_ = false; 68 } else { 69 logicalCon_ = super.getConnection(); 71 if (this.physicalConnection_ != null) { if (netXAPhysicalConnection_ != null) { netXares_.initForReuse(); 74 } 75 } 76 } 77 return logicalCon_; 78 } 79 80 private static synchronized int getUnigueRmId() { 81 rmIdSeed_ += 1; 82 return rmIdSeed_; 83 } 84 85 public int getRmId() { 86 return rmId_; 87 } 88 89 public XAResource getXAResource() throws SQLException { 90 if (logWriter_ != null) { 91 logWriter_.traceExit(this, "getXAResource", xares_); 92 } 93 94 return xares_; 95 } 96 97 public ClientXADataSource getDataSource() throws SqlException { 98 if (logWriter_ != null) { 99 logWriter_.traceExit(this, "getDataSource", derbyds_); 100 } 101 102 return derbyds_; 103 } 104 105 public NetXAConnection createControlConnection(NetLogWriter logWriter, 106 String user, 107 String password, 108 org.apache.derby.jdbc.ClientDataSource dataSource, 109 int rmId, 110 boolean isXAConn) throws SQLException { 111 try 112 { 113 controlCon_ = new NetXAConnection(logWriter, 114 user, 115 password, 116 dataSource, 117 rmId, 118 isXAConn, 119 this); 120 controlCon_.getNetConnection().setTransactionIsolation( 121 Connection.TRANSACTION_READ_UNCOMMITTED); 122 123 if (logWriter_ != null) { 124 logWriter_.traceExit(this, "createControlConnection", controlCon_); 125 } 126 127 return controlCon_; 128 } 129 catch ( SqlException se ) 130 { 131 throw se.getSQLException(); 132 } 133 } 134 135 136 public synchronized void close() throws SQLException { 137 super.close(); 138 } 139 } 140 141 | Popular Tags |