Hi, Tomohito, here is the patch, I'll also try to put it on JIRA again

TomohitoNakayama wrote:

Hello.

I try to get http://issues.apache.org/jira/secure/attachment/12311443/DERBY-412.diff and failed.
Jira seems to have some problem....

Next is log of downloading ....

Request:
GET http://issues.apache.org/jira/secure/attachment/12311443/DERBY-412.diff HTTP/1.0 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Referer: http://issues.apache.org/jira/browse/DERBY-412
Accept-Language: ja
Proxy-Connection: Keep-Alive
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; i-NavFourF; .NET CLR 2.0.40607)
Host: issues.apache.org
Cookie: seraph.os.cookie=GlMlJlOlPmMiPiKiOiIiRiMi; JSESSIONID=2E4F5F17ADA0CB9EEF8783685971D156


Response:
HTTP/1.1 404 Could not find specified attachment: null
Date: Wed, 03 Aug 2005 10:08:34 GMT
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1075
Proxy-Connection: close
Connection: close

<html><head><title>Apache Tomcat/5.0.30 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - Could not find specified attachment: null</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Could not find specified attachment: null</u></p><p><b>description</b> <u>The requested resource (Could not find specified attachment: null) is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/5.0.30</h3></body></html>


Can you redo uploading new patch?

Best regards.

/*

        Tomohito Nakayama
        [EMAIL PROTECTED]
        [EMAIL PROTECTED]
        [EMAIL PROTECTED]

        Naka
        http://www5.ocn.ne.jp/~tomohito/TopPage.html

*/
----- Original Message ----- From: "David Van Couvering" <[EMAIL PROTECTED]>
To: "Derby Development" <[email protected]>
Sent: Wednesday, August 03, 2005 3:16 AM
Subject: DERBY-412 (Connection.toString() formatting) patch uploaded


FYI, I attached another patch for DERBY-412, based on Tomohito's
comments.  Tomohito, would you be willing to review the changes?

I don't think I can commit yet (I'm a little  unclear on my current
status), so perhaps you could also commit it if it looks good, Tomohito?

Thanks,

David



--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.7/60 - Release Date: 2005/07/28



Index: java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
===================================================================
--- java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (revision 
226839)
+++ java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (working copy)
@@ -145,7 +145,7 @@
        private int resultSetId;
     
     /** Cached string representation of the connection id */
-    private String idString;
+    private String connString;
 
 
        //////////////////////////////////////////////////////////
@@ -1919,7 +1919,8 @@
 
     /**
      * Get a String representation that uniquely identifies
-     * this connection
+     * this connection.  Include the same information that is
+     * printed in the log for various trace and error messages.
      *
      * In Derby the "physical" connection is a LanguageConnectionContext, 
      * or LCC.
@@ -1928,18 +1929,27 @@
      * Note that this is a big aid in debugging, because much of the
      * engine trace and log code prints the LCC id. 
      *
-     * @return a string representation of the unique id for the
-     *    underlying LanguageConnectionContext
+     * @return a string representation for this connection
      */
     public String toString()
     {
-        if ( idString == null )
+        if ( connString == null )
         {
-            idString = 
-              Integer.toString(getLanguageConnection().getInstanceNumber());
-        }
+            
+            LanguageConnectionContext lcc = getLanguageConnection();
+
+            connString = 
+              this.getClass().getName() + "@" + this.hashCode() + " " +
+                lcc.xidStr +                  
+                    lcc.getTransactionExecute().getTransactionIdString() + 
+                    "), " +
+                lcc.lccStr + 
+                    Integer.toString(lcc.getInstanceNumber()) + "), " +
+                lcc.dbnameStr + lcc.getDbname() + "), " +
+                lcc.drdaStr + lcc.getDrdaID() + ") ";
+        }       
         
-        return idString;
+        return connString;
     }
 
 
Index: java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
===================================================================
--- java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java      
(revision 226839)
+++ java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java      
(working copy)
@@ -51,6 +51,7 @@
 
        protected final BrokeredConnectionControl control;
        private boolean isClosed;
+        private String connString;
 
        /**
                Maintain state as seen by this Connection handle, not the state
@@ -486,33 +487,30 @@
        }
             
     /**
-     * Get the string representation for the underlying physical
-     * connection.
-     *
-     *  When a physical connection is created, it is assigned a unique id 
-     *  that is unchanged for the lifetime of the connection. When an 
-     *  application calls Connection.toString(), it gets the string 
-     *  representation of the underlying physical connection, regardless 
-     *  of whether the application has a reference to the physical connection 
-     *  itself or a reference to a proxy connection (aka brokered connection) 
-     *  that wraps the physical connection.
-     *
-     *  Since this BrokeredConnection is a proxy connection, we return the
-     *  string value of its underlying physical connection
+     * Get the string representation for this connection.  Return
+     * the class name/hash code and various debug information.
      * 
-     * @return unique string representation of the underlying
-     *   physical connection
+     * @return unique string representation for this connection
      */
     public String toString() 
     {
-        try
+        if ( connString == null )
         {
-            return getRealConnection().toString();
+            String wrappedString;
+            try
+            {
+                wrappedString = getRealConnection().toString();
+            }
+            catch ( SQLException e )
+            {
+                wrappedString = "<none>";
+            }
+            
+            connString = this.getClass().getName() + "@" + this.hashCode() +
+                ", Wrapped Connection = " + wrappedString;
         }
-        catch ( SQLException e )
-        {
-            return "<no connection>";
-        }
+        
+        return connString;
     }
 
        protected int getJDBCLevel() { return 2;}
Index: java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
===================================================================
--- java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java        
(revision 226839)
+++ java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java        
(working copy)
@@ -63,8 +63,8 @@
     /** The id for this connection.  */
     private int connectionId;
     
-    /** String representation of id */
-    private String idString;
+    /** the connection string */
+    private String connString;
     
        private Vector eventListener; // who wants to know I am closed or error
 
@@ -459,12 +459,18 @@
      */
     public String toString()
     {
-        if ( idString == null )
+        if ( connString == null )
         {
-            idString = Integer.toString(connectionId);
-        }
+            String physicalConnString = isActive ?
+                realConnection.toString() : "<none>";
+            
+            connString = 
+              this.getClass().getName() + "@" + this.hashCode() + " " +
+                "(ID = " + connectionId + "), " +
+                "Physical Connection = " + physicalConnString;
+        }    
         
-        return idString;
+        return connString;
     }
 
 }
Index: 
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml
===================================================================
--- java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml  
(revision 226839)
+++ java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml  
(working copy)
@@ -119,8 +119,9 @@
       srcdir="${derby.testing.src.dir}"
       destdir="${out.dir}">
       <classpath>
+        <pathelement path="${java13compile.classpath}"/>
+        <pathelement location="${oro}"/>
         <pathelement location="${jta1_2}"/>
-        <pathelement path="${java13compile.classpath}"/>
       </classpath>
       <!--exclude name=""/-->
       <include name="${this.dir}/checkDataSource.java"/>
Index: 
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
===================================================================
--- 
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
       (revision 226839)
+++ 
java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/checkDataSource.java
       (working copy)
@@ -24,6 +24,8 @@
 import org.apache.derby.jdbc.EmbeddedSimpleDataSource;
 import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
 import org.apache.derby.jdbc.EmbeddedXADataSource;
+import org.apache.derby.iapi.jdbc.BrokeredConnection;
+import org.apache.derby.impl.jdbc.EmbedConnection;
 
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -49,13 +51,33 @@
 import java.io.*;
 import java.util.Hashtable;
 import java.util.Iterator;
-
+import org.apache.oro.text.perl.Perl5Util;
 import javax.naming.*;
 import javax.naming.directory.*;
 
 public class checkDataSource
 { 
+    /**
+     * A hashtable of opened connections.  This is used when checking to
+     * make sure connection strings are unique; we need to make sure all
+     * the connections are closed when we are done, so they are stored
+     * in this hashtable
+     */
     protected static Hashtable conns = new Hashtable();
+    
+    /**
+     * This is a utility that knows how to do pattern matching.  Used
+     * in checking the format of a connection string
+     */
+    protected static Perl5Util p5u = new Perl5Util();
+    
+    /** The expected format of a connection string. In English:
+     * "<classname>@<hashcode> (XID=<xid>), (SESSION = <sessionid>),
+     *  (DATABASE=<dbname>), (DRDAID = <drdaid>)"
+     */
+    private static final String CONNSTRING_FORMAT = "[EMAIL PROTECTED] " +
+        "\\(XID = .*\\), \\(SESSIONID = [0-9]+\\), " +
+        "\\(DATABASE = [A-Za-z]+\\), \\(DRDAID = .+\\)";
 
        public static void main(String[] args) throws Exception {
 
@@ -841,8 +863,9 @@
     /**
      * Make sure this connection's string is unique (DERBY-243)
      */
-    protected void checkToString(Connection conn) throws Exception
+    protected static void checkToString(Connection conn) throws Exception
     {
+        checkStringFormat(conn);
         String str = conn.toString();
 
         if ( conns.containsKey(str))
@@ -853,11 +876,89 @@
         conns.put(str, conn);
     }
     
+    /** 
+     * Check the format of a pooled connection
+     **/
+    protected static void checkStringFormat(PooledConnection pc) throws 
Exception
+    {
+        String prefix = checkStringPrefix(pc);
+        String connstr = pc.toString();
+        String format = "/" + prefix + 
+            " \\(ID = [0-9]+\\), Physical Connection = " +
+            "<none>|" + CONNSTRING_FORMAT + "/";
+        
+        if ( ! p5u.match(format, connstr) )
+        {
+            throw new Exception( "Connection.toString() (" + connstr + ") " +
+              "does not match expected format (" + format + ")");
+        }
+    }
+    
     /**
+     * Check the format for the toString() of a Connection that is an
+     * instance of BrokeredConnection.  This is different, as the Brokered
+     * Connection prints out its class name and then the toString() value
+     * of the underlying, wrapped connection.
+     */
+    protected static void checkStringFormat(BrokeredConnection conn) throws 
Exception
+    {
+        String connstr = conn.toString();
+        String prefix = checkStringPrefix(connstr);
+        
+        String format = "/" + prefix + ", Wrapped Connection = " + 
+            "<none>|" + CONNSTRING_FORMAT + "/";
+
+        if ( ! p5u.match(format, connstr) )
+        {
+            throw new Exception( "Connection.toString() (" + connstr + ") " +
+                "does not match expected format (" + format + ")");
+        }
+    }
+        
+     /**
+     * Check the format of the connection string.  This is the default test
+     * to run if this is not a BrokeredConnection class
+     */
+    protected static void checkStringFormat(Connection conn) throws Exception
+    {
+        String prefix = checkStringPrefix(conn);
+        
+        String str = conn.toString();        
+       
+        // See if the connection string matches the format pattern    
+        if ( ! p5u.match("/" + CONNSTRING_FORMAT + "/", str) )
+        {
+            throw new Exception( "Connection.toString() (" + str + ") " +
+                "does not match expected format (" + CONNSTRING_FORMAT + ")");
+        }
+    }
+    
+    /**
+     * Make sure the connection string starts with the right prefix, which
+     * is the [EMAIL PROTECTED]
+     *
+     * @return the expected prefix string, this is used in further string
+     *   format checking
+     */
+    protected static String checkStringPrefix(Object conn) throws Exception
+    {
+        String connstr = conn.toString();
+        String prefix = conn.getClass().getName() + "@" + conn.hashCode();
+        if ( ! connstr.startsWith(prefix) )
+        {
+            throw new Exception("Connection class and hash code for " +
+                "connection string (" + connstr + ") does not match expected " 
+
+                "(" + prefix + ")");
+        }  
+        
+        return prefix;
+    }
+    
+    /**
      * Clear out and close connections in the connections
      * hashtable. 
      */
-    protected void clearConnections() throws SQLException
+    protected static void clearConnections() throws SQLException
     {
         java.util.Iterator it = conns.values().iterator();
         while ( it.hasNext() )
@@ -872,7 +973,7 @@
      * Get connections  using ij.startJBMS() and make sure
      * they're unique
      */
-    protected void checkJBMSToString() throws Exception
+    protected static void checkJBMSToString() throws Exception
     {
         clearConnections();
         // Open ten connections rather than just two to
@@ -893,7 +994,7 @@
      * Check uniqueness of connection strings coming from a
      * DataSouce
      */
-    protected void checkToString(DataSource ds) throws Exception
+    protected static void checkToString(DataSource ds) throws Exception
     {
         clearConnections();
         
@@ -912,7 +1013,7 @@
      * We want to check the PooledConnection as well as the
      * underlying physical connection. 
      */
-    protected void checkToString(ConnectionPoolDataSource pds)
+    protected static void checkToString(ConnectionPoolDataSource pds)
         throws Exception
     {
         int numConnections = 10;
@@ -923,6 +1024,7 @@
         for ( int i = 0 ; i < numConnections ; i++ )
         {
             PooledConnection pc = pds.getPooledConnection();
+            checkStringFormat(pc);
             String str = pc.toString();
             if ( pooledConns.get(str) != null )
             {
@@ -952,26 +1054,12 @@
             pc.close();
         }
         pooledConns.clear();
-        
-        // Now check that two connections from the same 
-        // PooledConnection have the same string value
-        PooledConnection pc = pds.getPooledConnection();
-        Connection conn = pc.getConnection();
-        String str = conn.toString();
-        conn = pc.getConnection();
-        if ( ! conn.toString().equals(str) )
-        {
-            throw new Exception("Two connections from the " +
-              "same pooled connection have different string " +
-              "values: " + str + ", " + conn.toString());
-        }
-        pc.close();
     }
     
     /**
      * Check uniqueness of strings for an XA data source
      */
-    protected void checkToString(XADataSource xds) throws Exception
+    protected static void checkToString(XADataSource xds) throws Exception
     {
         int numConnections = 10;
         
@@ -981,6 +1069,7 @@
         for ( int i = 0 ; i < numConnections ; i++ )
         {
             XAConnection xc = xds.getXAConnection();
+            checkStringFormat(xc);
             String str = xc.toString();
             if ( xaConns.get(str) != null )
             {
@@ -1010,20 +1099,6 @@
             xc.close();
         }
         xaConns.clear();
-        
-        // Now check that two connections from the same 
-        // XAConnection have the same string value
-        XAConnection xc = xds.getXAConnection();
-        Connection conn = xc.getConnection();
-        String str = conn.toString();
-        conn = xc.getConnection();
-        if ( ! conn.toString().equals(str) )
-        {
-            throw new Exception("Two connections from the " +
-              "same pooled connection have different string " +
-              "values: " + str + ", " + conn.toString());
-        }
-        xc.close();
     }
     
        protected static void checkConnectionPreCloseS(String dsName, 
Connection conn) throws SQLException {
begin:vcard
fn:David Van Couvering
n:Van Couvering;David
org:Sun Microsystems, Inc.;Database Technology Group
email;internet:[EMAIL PROTECTED]
title:Senior Staff Software Engineer
tel;work:510-550-6819
tel;cell:510-684-7281
x-mozilla-html:TRUE
version:2.1
end:vcard

Reply via email to