You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2006/04/14 16:08:05 UTC

svn commit: r394106 - in /db/derby/code/trunk/java/client/org/apache/derby/client: ./ am/ net/

Author: rhillegas
Date: Fri Apr 14 07:07:56 2006
New Revision: 394106

URL: http://svn.apache.org/viewcvs?rev=394106&view=rev
Log:
Commit Anurag's patch derby-1192.diff for DERBY-1192: more fine-tuning of the graph of connection classes.

Added:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection40.java   (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXACallInfo.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection.java Fri Apr 14 07:07:56 2006
@@ -20,9 +20,9 @@
 package org.apache.derby.client;
 
 import java.sql.SQLException;
+import org.apache.derby.client.net.NetXAConnection;
 import org.apache.derby.jdbc.ClientDataSource;
 import org.apache.derby.jdbc.ClientDriver;
-import org.apache.derby.client.am.ClientJDBCObjectFactory;
 import org.apache.derby.client.am.MessageId;
 import org.apache.derby.client.am.SqlException;
 import org.apache.derby.client.net.NetLogWriter;
@@ -94,13 +94,12 @@
             password_ = password;
             rmId_ = rmId;
             listeners_ = new java.util.Vector();
-            netXAPhysicalConnection_ = new org.apache.derby.client.net.NetXAConnection((NetLogWriter) logWriter_,
+            netXAPhysicalConnection_ = getNetXAConnection(ds,
+                    (NetLogWriter) logWriter_,
                     user,
                     password,
-                    ds,
-                    rmId,
-                    true);
-            physicalConnection_ = netXAPhysicalConnection_;
+                    rmId);
+            physicalConnection_ = netXAPhysicalConnection_.getNetConnection();
         } catch ( SqlException se ) {
             throw se.getSQLException();
         }
@@ -249,5 +248,29 @@
     // Used by LogicalConnection close when it disassociates itself from the ClientPooledConnection
     public synchronized void nullLogicalConnection() {
         logicalConnection_ = null;
+    }
+    
+    /**
+     * creates and returns NetXAConnection. 
+     * Overwrite this method to create different version of NetXAConnection
+     * @param ds 
+     * @param logWriter 
+     * @param user 
+     * @param password 
+     * @param rmId 
+     * @return NetXAConnection
+     */
+    protected NetXAConnection getNetXAConnection (ClientDataSource ds,
+                                  NetLogWriter logWriter,
+                                  String user,
+                                  String password,
+                                  int rmId) throws SqlException {
+          return new NetXAConnection(logWriter,
+                    user,
+                    password,
+                    ds,
+                    rmId,
+                    true);
+        
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java Fri Apr 14 07:07:56 2006
@@ -21,9 +21,12 @@
 package org.apache.derby.client;
 
 import java.sql.SQLException;
-import org.apache.derby.client.am.SqlException;
+import org.apache.derby.client.net.NetXAConnection;
 import org.apache.derby.jdbc.ClientDataSource;
 import javax.sql.StatementEventListener;
+import org.apache.derby.client.am.SqlException;
+import org.apache.derby.client.net.NetLogWriter;
+import org.apache.derby.client.net.NetXAConnection40;
 
 public class ClientPooledConnection40 extends ClientPooledConnection {
     
@@ -57,6 +60,26 @@
     public void removeStatementEventListener(StatementEventListener listener){
         throw new java.lang.UnsupportedOperationException();
     }
-    
-    
+
+    /**
+     * creates and returns NetXAConnection40.
+     * @param ds
+     * @param logWriter
+     * @param user
+     * @param password
+     * @param rmId
+     * @return NetXAConnection
+     */
+    protected NetXAConnection getNetXAConnection (ClientDataSource ds,
+                                  NetLogWriter logWriter,
+                                  String user,
+                                  String password,
+                                  int rmId) throws SqlException {
+        return new NetXAConnection40 (logWriter,
+                user,
+                password,
+                ds,
+                rmId,
+                true);
+    }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientXAConnection.java Fri Apr 14 07:07:56 2006
@@ -115,7 +115,8 @@
                     dataSource,
                     rmId,
                     isXAConn);
-            controlCon_.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+            controlCon_.getNetConnection().setTransactionIsolation(
+                    Connection.TRANSACTION_READ_UNCOMMITTED);
 
             if (logWriter_ != null) {
                 logWriter_.traceExit(this, "createControlConnection", controlCon_);

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Fri Apr 14 07:07:56 2006
@@ -609,9 +609,7 @@
 
     public void writeCommit() throws SqlException {
         if (isXAConnection_) {
-            if ((xaState_ == XA_T0_NOT_ASSOCIATED) ) {
-                writeLocalXACommit_();
-            }
+            writeXACommit_ ();
         } else {
             writeLocalCommit_();
         }
@@ -626,9 +624,7 @@
 
     public void readCommit() throws SqlException {
         if (isXAConnection_) {
-            if ((xaState_ == XA_T0_NOT_ASSOCIATED) ) {
-                readLocalXACommit_();               
-            }
+            readXACommit_ ();
         } else {
             readLocalCommit_();
         }
@@ -686,7 +682,7 @@
 
     public void writeRollback() throws SqlException {
         if (isXAConnection_) {
-            writeLocalXARollback_();
+            writeXARollback_ ();
         } else {
             writeLocalRollback_();
         }
@@ -1738,12 +1734,19 @@
     public abstract void readLocalXAStart_() throws SqlException;
 
     public abstract void writeLocalXACommit_() throws SqlException;
+    
+    protected abstract void writeXACommit_() throws SqlException;
 
-    public abstract void readLocalXACommit_() throws SqlException;
+    public abstract void readLocalXACommit_() throws SqlException;   
+    
+    protected abstract void readXACommit_() throws SqlException;   
 
     public abstract void writeLocalCommit_() throws SqlException;
 
     public abstract void readLocalCommit_() throws SqlException;
+    
+    protected abstract void writeXATransactionStart(Statement statement) 
+                                                throws SqlException;
 
     public void completeLocalCommit() {
     	java.util.Set keySet = CommitAndRollbackListeners_.keySet();
@@ -1772,10 +1775,17 @@
 
 
     public abstract void writeLocalXARollback_() throws SqlException;
+    
+    protected abstract void writeXARollback_() throws SqlException;
 
     public abstract void readLocalXARollback_() throws SqlException;
+    
+    protected abstract void readXARollback_() throws SqlException;
 
     public void writeTransactionStart(Statement statement) throws SqlException {
+        if (isXAConnection_) {
+            writeXATransactionStart (statement);
+        }
     }
 
     public void readTransactionStart() throws SqlException {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnection.java Fri Apr 14 07:07:56 2006
@@ -19,7 +19,7 @@
 */
 package org.apache.derby.client.net;
 
-import org.apache.derby.jdbc.ClientBaseDataSource;
+import java.sql.SQLException;
 import org.apache.derby.client.am.CallableStatement;
 import org.apache.derby.client.am.DatabaseMetaData;
 import org.apache.derby.client.am.DisconnectException;
@@ -31,8 +31,6 @@
 import org.apache.derby.client.am.Utils;
 import org.apache.derby.jdbc.ClientDataSource;
 import org.apache.derby.jdbc.ClientDriver;
-import org.apache.derby.client.am.ClientJDBCObjectFactory;
-
 
 public class NetConnection extends org.apache.derby.client.am.Connection {
 
@@ -1399,6 +1397,12 @@
     }
 
     public void setIndoubtTransactions(java.util.Hashtable indoubtTransactions) {
+        if (isXAConnection_) {
+            if (indoubtTransactions_ != null) {
+                indoubtTransactions_.clear();
+            }
+            indoubtTransactions_ = indoubtTransactions;
+        }
     }
 
     protected void setReadOnlyTransactionFlag(boolean flag) {
@@ -1528,6 +1532,113 @@
             (NetDatabaseMetaData) databaseMetaData_;
         return metadata.serverSupportsQryclsimp();
     }
-
+    
+    /**
+     * Returns if a transaction is in process
+     * @return open
+     */
+    public boolean isOpen() {
+        return open_;
+    }
+    
+    /**
+     * closes underlying connection and associated resource.
+     */
+    synchronized public void close() throws SQLException {
+        // call super.close*() to do the close*
+        super.close();
+        if (!isXAConnection_)
+            return;
+        if (isOpen()) {
+            return; // still open, return
+        }
+        if (xares_ != null) {
+            xares_.removeXaresFromSameRMchain();
+        }
+    }
+    
+    /**
+     * closes underlying connection and associated resource.
+     */
+    synchronized public void closeX() throws SQLException {
+        // call super.close*() to do the close*
+        super.closeX();
+        if (!isXAConnection_)
+            return;
+        if (isOpen()) {
+            return; // still open, return
+        }
+        if (xares_ != null) {
+            xares_.removeXaresFromSameRMchain();
+        }
+    }
+    
+    /**
+     * Invalidates connection but keeps socket open.
+     */
+    synchronized public void closeForReuse() throws SqlException {
+        // call super.close*() to do the close*
+        super.closeForReuse();
+        if (!isXAConnection_)
+            return;
+        if (isOpen()) {
+            return; // still open, return
+        }
+        if (xares_ != null) {
+            xares_.removeXaresFromSameRMchain();
+        }
+    }
+    
+    /**
+     * closes resources connection will be not available 
+     * for reuse.
+     */
+    synchronized public void closeResources() throws SQLException {
+        // call super.close*() to do the close*
+        super.closeResources();
+        if (!isXAConnection_)
+            return;
+        
+        if (isOpen()) {
+            return; // still open, return
+        }
+        if (xares_ != null) {
+            xares_.removeXaresFromSameRMchain();
+        }
+    }
+    
+    
+    /**
+     * Invokes write commit on NetXAConnection
+     */
+    protected void writeXACommit_() throws SqlException {
+        xares_.netXAConn_.writeCommit();
+    }
+    
+    /**
+     * Invokes readCommit on NetXAConnection
+     */
+    protected void readXACommit_() throws SqlException {
+        xares_.netXAConn_.readCommit();
+    }
+    
+    /**
+     * Invokes writeRollback on NetXAConnection
+     */
+    protected void writeXARollback_() throws SqlException {
+        xares_.netXAConn_.writeRollback();
+    }
+    
+    /**
+     * Invokes writeRollback on NetXAConnection
+     */
+    protected void readXARollback_() throws SqlException {
+            xares_.netXAConn_.readRollback();
+    }
+    
+    
+    protected void writeXATransactionStart(Statement statement) throws SqlException {
+        xares_.netXAConn_.writeTransactionStart(statement);
+    }
 }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXACallInfo.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXACallInfo.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXACallInfo.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXACallInfo.java Fri Apr 14 07:07:56 2006
@@ -98,8 +98,8 @@
     }
 
     public void saveConnectionVariables() {
-        in_ = actualConn_.getInputStream();
-        out_ = actualConn_.getOutputStream();
+        in_ = actualConn_.getNetConnection().getInputStream();
+        out_ = actualConn_.getNetConnection().getOutputStream();
         crrtkn_ = actualConn_.getCorrelatorToken();
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection.java Fri Apr 14 07:07:56 2006
@@ -2,7 +2,8 @@
 
    Derby - Class org.apache.derby.client.net.NetXAConnection
 
-   Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.
+   Copyright (c) 2001, 2005, 2006 The Apache Software Foundation or its 
+   licensors, where applicable.
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -29,68 +30,70 @@
 import org.apache.derby.client.am.SqlException;
 import org.apache.derby.client.am.Statement;
 
-public class NetXAConnection extends org.apache.derby.client.net.NetConnection {
+public class NetXAConnection {    
+    private NetConnection netCon;
     //---------------------constructors/finalizer---------------------------------
-    // For XA Connections
+    // For XA Connections    
     public NetXAConnection(NetLogWriter netLogWriter,
                            String user,
                            String password,
                            org.apache.derby.jdbc.ClientDataSource dataSource,
                            int rmId,
                            boolean isXAConn) throws SqlException {
-        super(netLogWriter, user, password, dataSource, rmId, isXAConn);
+        netCon = createNetConnection (netLogWriter, user, password, 
+                dataSource, rmId, isXAConn);
         checkPlatformVersion();
     }
 
     protected void finalize() throws java.lang.Throwable {
-        super.finalize();
+        netCon.finalize();
     }
 
     public void setCorrelatorToken(byte[] crttoken) {
-        crrtkn_ = crttoken;
+        netCon.crrtkn_ = crttoken;
     }
 
     public byte[] getCorrelatorToken() {
-        return crrtkn_;
+        return netCon.crrtkn_;
     }
 
     void setNetXAResource(NetXAResource xares) {
-        xares_ = xares;
+        netCon.xares_ = xares;
     }
 
     public void writeLocalXAStart_() throws SqlException {
-        netAgent_.netConnectionRequest_.writeLocalXAStart(this);
+        netCon.netAgent_.netConnectionRequest_.writeLocalXAStart(netCon);
     }
 
     public void readLocalXAStart_() throws SqlException {
-        netAgent_.netConnectionReply_.readLocalXAStart(this);
+        netCon.netAgent_.netConnectionReply_.readLocalXAStart(netCon);
     }
 
     public void writeLocalXACommit_() throws SqlException {
-        netAgent_.netConnectionRequest_.writeLocalXACommit(this);
+        netCon.netAgent_.netConnectionRequest_.writeLocalXACommit(netCon);
     }
 
     public void readLocalXACommit_() throws SqlException {
-        netAgent_.netConnectionReply_.readLocalXACommit(this);
+        netCon.netAgent_.netConnectionReply_.readLocalXACommit(netCon);
     }
 
     public void writeLocalXARollback_() throws SqlException {
-        netAgent_.netConnectionRequest_.writeLocalXARollback(this);
+        netCon.netAgent_.netConnectionRequest_.writeLocalXARollback(netCon);
     }
 
     public void readLocalXARollback_() throws SqlException {
-        netAgent_.netConnectionReply_.readLocalXARollback(this);
+        netCon.netAgent_.netConnectionReply_.readLocalXARollback(netCon);
     }
 
     public void writeTransactionStart(Statement statement) throws SqlException {
         //KATHEY  remove below after checking that we don't need it.
-        if (!isXAConnection_) {
+        if (!netCon.isXAConnection()) {
             return; // not a XA connection
         }
 
         // this is a XA connection
-        int xaState = getXAState();
-        xares_.exceptionsOnXA = null;
+        int xaState = netCon.getXAState();
+        netCon.xares_.exceptionsOnXA = null;
         //TODO: Looks like this can go and also the whole client indoubtTransaction code.
         /*
         if (xaState == XA_RECOVER) { // in recover, clean up and go to open-idle
@@ -107,15 +110,9 @@
         return;
     }
 
-    public void setIndoubtTransactions(java.util.Hashtable indoubtTransactions) {
-        if (indoubtTransactions_ != null) {
-            indoubtTransactions_.clear();
-        }
-        indoubtTransactions_ = indoubtTransactions;
-    }
-
     public byte[] getUOWID(Xid xid) {
-        NetIndoubtTransaction indoubtTxn = (NetIndoubtTransaction) indoubtTransactions_.get(xid);
+        NetIndoubtTransaction indoubtTxn = 
+                (NetIndoubtTransaction) netCon.indoubtTransactions_.get(xid);
         if (indoubtTxn == null) {
             return null;
         }
@@ -123,9 +120,8 @@
         return uowid;
     }
 
-
     public int getPort(Xid xid) {
-        NetIndoubtTransaction indoubtTxn = (NetIndoubtTransaction) indoubtTransactions_.get(xid);
+        NetIndoubtTransaction indoubtTxn = (NetIndoubtTransaction) netCon.indoubtTransactions_.get(xid);
         if (indoubtTxn == null) {
             return -1;
         }
@@ -134,115 +130,65 @@
 
     public void writeCommit() throws SqlException {
         // this logic must be in sync with willAutoCommitGenerateFlow() logic
-        if (isXAConnection_) { // XA Connection
-            int xaState = getXAState();
-            if (xaState == XA_T0_NOT_ASSOCIATED){
-                xares_.callInfoArray_[xares_.conn_.currXACallInfoOffset_].xid_ =
-                        NetXAResource.nullXid;
-                writeLocalXACommit_();
-            }
-        } else { // not XA connection
-            writeLocalCommit_();
+        int xaState = netCon.getXAState();
+        if (xaState == netCon.XA_T0_NOT_ASSOCIATED){
+            netCon.xares_.callInfoArray_[
+                    netCon.xares_.conn_.currXACallInfoOffset_
+                    ].xid_ = NetXAResource.nullXid;
+            writeLocalXACommit_();
         }
     }
 
     public void readCommit() throws SqlException {
-        if (isXAConnection_) { // XA Connection
-            int xaState = getXAState();
-            NetXACallInfo callInfo = xares_.callInfoArray_[currXACallInfoOffset_];
-            callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
-            if (xaState == XA_T0_NOT_ASSOCIATED) {
-                readLocalXACommit_();
-                //TODO: Remove
-                //setXAState(XA_LOCAL);
-            }
-            if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
-                callInfo.xaFunction_ = NetXAResource.XAFUNC_COMMIT;
-                xares_.xaRetValErrorAccumSQL(callInfo, 0);
-                callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
-                throw xares_.exceptionsOnXA;
-            }
-        } else
-        // non-XA connections
-        {
-            readLocalCommit_();
-        }
+        int xaState = netCon.getXAState();
+        NetXACallInfo callInfo = netCon.xares_.callInfoArray_
+                [netCon.currXACallInfoOffset_];
+        callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
+        if (xaState == netCon.XA_T0_NOT_ASSOCIATED) {
+            readLocalXACommit_();
+            //TODO: Remove
+            //setXAState(XA_LOCAL);
+        }
+        if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
+            callInfo.xaFunction_ = NetXAResource.XAFUNC_COMMIT;
+            netCon.xares_.xaRetValErrorAccumSQL(callInfo, 0);
+            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
+            throw netCon.xares_.exceptionsOnXA;
+        }        
     }
 
     public void writeRollback() throws SqlException {
-        if (isXAConnection_) {
-            xares_.callInfoArray_[xares_.conn_.currXACallInfoOffset_].xid_ =
-                    xares_.nullXid;
-            writeLocalXARollback_();
-        } else {
-            writeLocalRollback_(); // non-XA
-        }
+      netCon.xares_.callInfoArray_[
+                netCon.xares_.conn_.currXACallInfoOffset_
+                ].xid_ = netCon.xares_.nullXid;
+       writeLocalXARollback_(); 
     }
 
     public void readRollback() throws SqlException {
-        if (isXAConnection_) { // XA connections
-            NetXACallInfo callInfo = xares_.callInfoArray_[currXACallInfoOffset_];
-            callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
-            readLocalXARollback_();
-
-            if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
-                callInfo.xaFunction_ = NetXAResource.XAFUNC_ROLLBACK;
-                xares_.xaRetValErrorAccumSQL(callInfo, 0);
-                callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
-                throw xares_.exceptionsOnXA;
-            }
-
-
-            // for all XA connectiions
-            // TODO:KATHEY - Do we need this?
-            setXAState(XA_T0_NOT_ASSOCIATED);
-        } else {
-            readLocalRollback_(); // non-XA connections
+        NetXACallInfo callInfo = netCon.xares_.callInfoArray_
+                [netCon.currXACallInfoOffset_];
+        callInfo.xaRetVal_ = XAResource.XA_OK; // initialize XARETVAL
+        readLocalXARollback_();
+
+        if (callInfo.xaRetVal_ != XAResource.XA_OK) { // xaRetVal has possible error, format it
+            callInfo.xaFunction_ = NetXAResource.XAFUNC_ROLLBACK;
+            netCon.xares_.xaRetValErrorAccumSQL(callInfo, 0);
+            callInfo.xaRetVal_ = XAResource.XA_OK; // re-initialize XARETVAL
+            throw netCon.xares_.exceptionsOnXA;
         }
-    }
 
-    synchronized public void close() throws SQLException {
-        // call super.close*() to do the close*
-        super.close();
-        if (open_) {
-            return; // still open, return
-        }
-        if (xares_ != null) {
-            xares_.removeXaresFromSameRMchain();
-        }
-    }
 
-    synchronized public void closeX() throws SQLException {
-        // call super.close*() to do the close*
-        super.closeX();
-        if (open_) {
-            return; // still open, return
-        }
-        if (xares_ != null) {
-            xares_.removeXaresFromSameRMchain();
-        }
-    }
-
-    synchronized public void closeForReuse() throws SqlException {
-        // call super.close*() to do the close*
-        super.closeForReuse();
-        if (open_) {
-            return; // still open, return
-        }
-        if (xares_ != null) {
-            xares_.removeXaresFromSameRMchain();
-        }
-    }
-
-    synchronized public void closeResources() throws SQLException {
-        // call super.close*() to do the close*
-        super.closeResources();
-        if (open_) {
-            return; // still open, return
-        }
-        if (xares_ != null) {
-            xares_.removeXaresFromSameRMchain();
-        }
+        // for all XA connectiions
+        // TODO:KATHEY - Do we need this?
+        netCon.setXAState(netCon.XA_T0_NOT_ASSOCIATED);
+    }
+
+    /**
+     * Returns underlying net connection
+     * @return NetConnection
+     */
+    public NetConnection getNetConnection () {
+        return netCon;
     }
 
     private void checkPlatformVersion() throws SqlException {
@@ -250,7 +196,8 @@
 
         supportedVersion = 8;
 
-        if (xaHostVersion_ >= supportedVersion) { // supported version, return
+        if (netCon.xaHostVersion_ >= supportedVersion) { 
+            // supported version, return
             return;
         }
 
@@ -259,7 +206,29 @@
         platform = "Linux, Unix, Windows";
         String versionMsg = "On " + platform + " XA supports version " +
                 supportedVersion + " and above, this is version " +
-                xaHostVersion_;
-        throw new SqlException(agent_.logWriter_, versionMsg);
+                netCon.xaHostVersion_;
+        throw new SqlException(netCon.agent_.logWriter_, versionMsg);
+    }
+    
+    /**
+     * Creates NetConnection for the supported version of jdbc.
+     * This method can be overwritten to return NetConnection
+     * of the supported jdbc version.
+     * @param netLogWriter 
+     * @param user 
+     * @param password 
+     * @param dataSource 
+     * @param rmId 
+     * @param isXAConn 
+     * @return NetConnection
+     */
+    protected NetConnection createNetConnection (NetLogWriter netLogWriter,
+                           String user,
+                           String password,
+                           org.apache.derby.jdbc.ClientDataSource dataSource,
+                           int rmId,
+                           boolean isXAConn) throws SqlException {        
+        return new NetConnection (netLogWriter, user, password, 
+                dataSource, rmId, isXAConn);
     }
 }

Added: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection40.java?rev=394106&view=auto
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection40.java (added)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection40.java Fri Apr 14 07:07:56 2006
@@ -0,0 +1,70 @@
+/*
+ 
+   Derby - Class org.apache.derby.client.net.NetXAConnection40
+ 
+   Copyright (c) 2006 The Apache Software Foundation or its licensors, where applicable.
+ 
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+ 
+ */
+package org.apache.derby.client.net;
+
+import org.apache.derby.client.am.SqlException;
+
+/**
+ * NetXAConnection for jdbc4.0.
+ */
+public class NetXAConnection40 extends NetXAConnection {
+    
+    /**
+     * creates NetXAConnection40.
+     * @param netLogWriter
+     * @param user
+     * @param password
+     * @param dataSource
+     * @param rmId
+     * @param isXAConn
+     * @return
+     */
+    public NetXAConnection40(NetLogWriter netLogWriter,
+            String user,
+            String password,
+            org.apache.derby.jdbc.ClientDataSource dataSource,
+            int rmId,
+            boolean isXAConn) throws SqlException {
+        super(netLogWriter, user, password,
+                dataSource, rmId, isXAConn);
+    }
+    
+    /**
+     * create and returns NetConnection40.
+     * of the supported jdbc version.
+     * @param netLogWriter
+     * @param user
+     * @param password
+     * @param dataSource
+     * @param rmId
+     * @param isXAConn
+     * @return NetConnection
+     */
+    protected NetConnection createNetConnection(NetLogWriter netLogWriter,
+            String user,
+            String password,
+            org.apache.derby.jdbc.ClientDataSource dataSource,
+            int rmId,
+            boolean isXAConn) throws SqlException {
+        return new NetConnection40(netLogWriter, user, password,
+                dataSource, rmId, isXAConn);
+    }
+    
+}

Propchange: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAConnection40.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java?rev=394106&r1=394105&r2=394106&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetXAResource.java Fri Apr 14 07:07:56 2006
@@ -93,7 +93,8 @@
     public org.apache.derby.client.am.SqlException exceptionsOnXA = null;
 
     XAConnection xaconn_;
-    org.apache.derby.client.net.NetXAConnection conn_;
+    org.apache.derby.client.net.NetXAConnection netXAConn_;
+    org.apache.derby.client.net.NetConnection conn_;
     int rmId_; // unique RmId generated by XAConnection
     // TODO: change to a single callInfo field (not an array)
     NetXACallInfo callInfoArray_[] =
@@ -114,11 +115,12 @@
                          org.apache.derby.client.net.NetXAConnection conn) {
         xaconn_ = xaconn;
         rmId_ = rmId;
-        conn_ = conn;
+        conn_ = conn.getNetConnection();
+        netXAConn_ = conn;
         rmIdx_ = userId;
         rmIdy_ = password;
-        port_ = conn.netAgent_.getPort();
-        ipaddr_ = conn.netAgent_.socket_.getLocalAddress().getHostAddress();
+        port_ = conn_.netAgent_.getPort();
+        ipaddr_ = conn_.netAgent_.socket_.getLocalAddress().getHostAddress();
         conn.setNetXAResource(this);
 
         // link the primary connection to the first XACallInfo element
@@ -132,7 +134,7 @@
 
         // initialize the first XACallInfo element with the information from the
         //  primary connection
-        callInfoArray_[0].actualConn_ = conn_;
+        callInfoArray_[0].actualConn_ = conn;
         callInfoArray_[0].currConnection_ = true;
         callInfoArray_[0].freeEntry_ = false;
         // ~~~ save conn_ connection variables in callInfoArray_[0]