[libpostgresql-jdbc-java] 12/15: Use slightly different SQL State error codes for the different types of connection setup failures to indicate which can be retried and which cannot.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:20:56 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_4_703
in repository libpostgresql-jdbc-java.

commit d21d365cc68a5759dc61a8d42a94d21833f959f1
Author: Kris Jurka <books at ejurka.com>
Date:   Thu Mar 31 03:06:49 2011 +0000

    Use slightly different SQL State error codes for the different
    types of connection setup failures to indicate which can be
    retried and which cannot.
    
    Per discussion with Donald Fraser and Kevin Grittner.
---
 org/postgresql/core/v2/ConnectionFactoryImpl.java | 14 ++++++-------
 org/postgresql/core/v3/ConnectionFactoryImpl.java | 20 +++++++++----------
 org/postgresql/util/PSQLState.java                | 24 ++++++++++++++++++++++-
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/org/postgresql/core/v2/ConnectionFactoryImpl.java b/org/postgresql/core/v2/ConnectionFactoryImpl.java
index 2ef00fe..d8c9965 100644
--- a/org/postgresql/core/v2/ConnectionFactoryImpl.java
+++ b/org/postgresql/core/v2/ConnectionFactoryImpl.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v2/ConnectionFactoryImpl.java,v 1.17 2008/09/30 03:42:48 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v2/ConnectionFactoryImpl.java,v 1.18 2009/06/02 00:22:58 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -102,7 +102,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
             // Added by Peter Mount <peter at retep.org.uk>
             // ConnectException is thrown when the connection cannot be made.
             // we trap this an return a more meaningful message for the end user
-            throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_REJECTED, cex);
+            throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_UNABLE_TO_CONNECT, cex);
         }
         catch (IOException ioe)
         {
@@ -156,7 +156,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
 
             // Server doesn't even know about the SSL handshake protocol
             if (requireSSL)
-                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
+                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
 
             // We have to reconnect to continue.
             pgStream.close();
@@ -168,7 +168,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
 
             // Server does not support ssl
             if (requireSSL)
-                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
+                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
 
             return pgStream;
 
@@ -181,7 +181,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
             return pgStream;
 
         default:
-            throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.CONNECTION_FAILURE);
+            throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.PROTOCOL_VIOLATION);
         }
     }
 
@@ -320,7 +320,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
                 break;
 
             default:
-                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
             }
         }
     }
@@ -358,7 +358,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
                 break;
 
             default:
-                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
             }
         }
     }
diff --git a/org/postgresql/core/v3/ConnectionFactoryImpl.java b/org/postgresql/core/v3/ConnectionFactoryImpl.java
index e1db7b7..fe9b42a 100644
--- a/org/postgresql/core/v3/ConnectionFactoryImpl.java
+++ b/org/postgresql/core/v3/ConnectionFactoryImpl.java
@@ -4,7 +4,7 @@
 * Copyright (c) 2004, Open Cloud Limited.
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/ConnectionFactoryImpl.java,v 1.19 2008/11/29 07:40:30 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/v3/ConnectionFactoryImpl.java,v 1.20 2009/06/02 00:22:58 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -133,7 +133,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
             // Added by Peter Mount <peter at retep.org.uk>
             // ConnectException is thrown when the connection cannot be made.
             // we trap this an return a more meaningful message for the end user
-            throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_REJECTED, cex);
+            throw new PSQLException (GT.tr("Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections."), PSQLState.CONNECTION_UNABLE_TO_CONNECT, cex);
         }
         catch (IOException ioe)
         {
@@ -185,7 +185,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
 
             // Server doesn't even know about the SSL handshake protocol
             if (requireSSL)
-                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
+                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
 
             // We have to reconnect to continue.
             pgStream.close();
@@ -197,7 +197,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
 
             // Server does not support ssl
             if (requireSSL)
-                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_FAILURE);
+                throw new PSQLException(GT.tr("The server does not support SSL."), PSQLState.CONNECTION_REJECTED);
 
             return pgStream;
 
@@ -210,7 +210,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
             return pgStream;
 
         default:
-            throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.CONNECTION_FAILURE);
+            throw new PSQLException(GT.tr("An error occured while setting up the SSL connection."), PSQLState.PROTOCOL_VIOLATION);
         }
     }
 
@@ -399,7 +399,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
                 break;
 
             default:
-                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
             }
         }
     }
@@ -442,7 +442,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
                 // BackendKeyData
                 int l_msgLen = pgStream.ReceiveInteger4();
                 if (l_msgLen != 12)
-                    throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+                    throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
 
                 int pid = pgStream.ReceiveInteger4();
                 int ckey = pgStream.ReceiveInteger4();
@@ -488,7 +488,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
                 else if (name.equals("client_encoding"))
                 {
                     if (!value.equals("UNICODE"))
-                        throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+                        throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
                     pgStream.setEncoding(Encoding.getDatabaseEncoding("UNICODE"));
                 }
                 else if (name.equals("standard_conforming_strings"))
@@ -498,7 +498,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
                     else if (value.equals("off"))
                         protoConnection.setStandardConformingStrings(false);
                     else
-                        throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+                        throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
                 }
 
                 break;
@@ -506,7 +506,7 @@ public class ConnectionFactoryImpl extends ConnectionFactory {
             default:
                 if (logger.logDebug())
                     logger.debug("invalid message type=" + (char)beresp);
-                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.CONNECTION_UNABLE_TO_CONNECT);
+                throw new PSQLException(GT.tr("Protocol error.  Session setup failed."), PSQLState.PROTOCOL_VIOLATION);
             }
         }
     }
diff --git a/org/postgresql/util/PSQLState.java b/org/postgresql/util/PSQLState.java
index f64e1b4..373738a 100644
--- a/org/postgresql/util/PSQLState.java
+++ b/org/postgresql/util/PSQLState.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2003-2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/util/PSQLState.java,v 1.12 2007/12/01 12:50:45 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/util/PSQLState.java,v 1.13 2008/01/08 06:56:31 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -37,12 +37,34 @@ public class PSQLState implements java.io.Serializable
 
     public final static PSQLState INVALID_PARAMETER_TYPE = new PSQLState("07006");
 
+    /**
+     * We could establish a connection with the server for unknown reasons.
+     * Could be a network problem.
+     */
     public final static PSQLState CONNECTION_UNABLE_TO_CONNECT = new PSQLState("08001");
+
     public final static PSQLState CONNECTION_DOES_NOT_EXIST = new PSQLState("08003");
+
+    /**
+     * The server rejected our connection attempt.  Usually an authentication
+     * failure, but could be a configuration error like asking for a SSL
+     * connection with a server that wasn't built with SSL support.
+     */
     public final static PSQLState CONNECTION_REJECTED = new PSQLState("08004");
+    
+    /**
+     * After a connection has been established, it went bad.
+     */
     public final static PSQLState CONNECTION_FAILURE = new PSQLState("08006");
     public final static PSQLState CONNECTION_FAILURE_DURING_TRANSACTION = new PSQLState("08007");
+
+    /**
+     * The server sent us a response the driver was not prepared for and
+     * is either bizarre datastream corruption, a driver bug, or
+     * a protocol violation on the server's part.
+     */
     public final static PSQLState PROTOCOL_VIOLATION = new PSQLState("08P01");
+
     public final static PSQLState COMMUNICATION_ERROR = new PSQLState("08S01");
 
     public final static PSQLState NOT_IMPLEMENTED = new PSQLState("0A000");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list