db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r757811 - in /db/derby/code/trunk/java: client/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Tue, 24 Mar 2009 14:10:33 GMT
Author: kristwaa
Date: Tue Mar 24 14:10:30 2009
New Revision: 757811

URL: http://svn.apache.org/viewvc?rev=757811&view=rev
Log:
DERBY-4070: Embedded and client data sources throw different exception when a connection attribute
is badly formatted.
The client data sources will now catch the more specific exception and wrap
it in a more general one. This is consistent with the embedded driver.
Patch file: derby-4070-1d-ds_exception_handling.diff


Modified:
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java?rev=757811&r1=757810&r2=757811&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Tue Mar
24 14:10:30 2009
@@ -33,6 +33,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
+import java.sql.SQLException;
 import javax.naming.Referenceable;
 import javax.naming.Reference;
 import javax.naming.NamingException;
@@ -46,6 +47,7 @@
 import org.apache.derby.client.net.NetConfiguration;
 import org.apache.derby.client.net.NetLogWriter;
 import org.apache.derby.client.ClientDataSourceFactory;
+import org.apache.derby.shared.common.error.ExceptionUtil;
 import org.apache.derby.shared.common.reference.Attribute;
 import org.apache.derby.shared.common.reference.SQLState;
 
@@ -1152,4 +1154,54 @@
             sslMode = getClientSSLMode(prop);
         }
     }
+
+    /**
+     * Handles common error situations that can happen when trying to
+     * obtain a physical connection to the server, and which require special
+     * handling.
+     * <p>
+     * If this method returns normally, the exception wasn't handled and should
+     * be handled elsewhere or be re-thrown.
+     *
+     * @param logWriter log writer, may be {@code null}
+     * @param sqle exception to handle
+     * @throws SQLException handled exception (if any)
+     */
+    protected final void handleConnectionException(LogWriter logWriter,
+                                                   SqlException sqle)
+            throws SQLException {
+        // See DERBY-4070
+        if (sqle.getSQLState().equals(
+                ExceptionUtil.getSQLStateFromIdentifier(
+                    SQLState.INVALID_ATTRIBUTE_SYNTAX))) {
+            // Wrap this in SQLState.MALFORMED_URL exception to be
+            // consistent with the embedded driver.
+            throw new SqlException(logWriter,
+                    new ClientMessageId(SQLState.MALFORMED_URL),
+                    constructUrl(), sqle).getSQLException();
+
+        }
+    }
+
+    /**
+     * Constructs the JDBC connection URL from the state of the data source.
+     *
+     * @return The JDBC connection URL.
+     */
+    private String constructUrl() {
+        StringBuffer sb = new StringBuffer(64);
+        // To support subSubProtocols, the protocol addition below must be
+        // changed.
+        sb.append(Attribute.DNC_PROTOCOL);
+        sb.append(serverName);
+        sb.append(':');
+        sb.append(portNumber);
+        sb.append('/');
+        sb.append(databaseName);
+        if (connectionAttributes != null) {
+            sb.append(';');
+            sb.append(connectionAttributes);
+        }
+        return sb.toString();
+    }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java?rev=757811&r1=757810&r2=757811&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientConnectionPoolDataSource.java
Tue Mar 24 14:10:30 2009
@@ -71,9 +71,10 @@
 
     // Attempt to establish a physical database connection that can be used as a pooled connection.
     public PooledConnection getPooledConnection() throws SQLException {
+        LogWriter dncLogWriter = null;
         try
         {
-            LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
+            dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
             if (dncLogWriter != null) {
                 dncLogWriter.traceEntry(this, "getPooledConnection");
             }
@@ -85,15 +86,19 @@
         }
         catch ( SqlException se )
         {
+            // The method below may throw an exception.
+            handleConnectionException(dncLogWriter, se);
+            // If the exception wasn't handled so far, re-throw it.
             throw se.getSQLException();
         }
     }
 
     // Standard method that establishes the initial physical connection using CPDS properties.
     public PooledConnection getPooledConnection(String user, String password) throws SQLException
{
+        LogWriter dncLogWriter = null;
         try
         {
-            LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
+            dncLogWriter = super.computeDncLogWriterForNewConnection("_cpds");
             if (dncLogWriter != null) {
                 dncLogWriter.traceEntry(this, "getPooledConnection", user, "<escaped>");
             }
@@ -105,6 +110,9 @@
         }
         catch ( SqlException se )
         {
+            // The method below may throw an exception.
+            handleConnectionException(dncLogWriter, se);
+            // If the exception wasn't handled so far, re-throw it.
             throw se.getSQLException();
         }
     }

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java?rev=757811&r1=757810&r2=757811&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDataSource.java Tue Mar 24
14:10:30 2009
@@ -25,10 +25,12 @@
 import java.sql.SQLException;
 import javax.sql.DataSource;
 
+import org.apache.derby.client.am.ClientMessageId;
 import org.apache.derby.client.am.LogWriter;
 import org.apache.derby.client.am.SqlException;
 import org.apache.derby.client.net.NetConnection;
 import org.apache.derby.client.net.NetLogWriter;
+import org.apache.derby.shared.common.error.ExceptionUtil;
 
 /**
  * ClientDataSource is a simple data source implementation
@@ -179,9 +181,10 @@
         // This log writer may be narrowed to the connection-level
         // This log writer will be passed to the agent constructor.
         
+        LogWriter dncLogWriter = null;
         try
         {
-            LogWriter dncLogWriter = super.computeDncLogWriterForNewConnection("_sds");
+            dncLogWriter = super.computeDncLogWriterForNewConnection("_sds");
             updateDataSourceValues(tokenizeAttributes(getConnectionAttributes(), null));
             return ClientDriver.getFactory().newNetConnection
                     ((NetLogWriter) dncLogWriter, user,
@@ -189,6 +192,9 @@
         }
         catch(SqlException se)
         {
+            // The method below may throw an exception.
+            handleConnectionException(dncLogWriter, se);
+            // If the exception wasn't handled so far, re-throw it.
             throw se.getSQLException();
         }
         

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java?rev=757811&r1=757810&r2=757811&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientXADataSource.java Tue Mar
24 14:10:30 2009
@@ -66,13 +66,18 @@
     }
 
     public XAConnection getXAConnection(String user, String password) throws SQLException
{
+        NetLogWriter dncLogWriter = null;
         try
         {
-            NetLogWriter dncLogWriter = (NetLogWriter) super.computeDncLogWriterForNewConnection("_xads");
+            dncLogWriter = (NetLogWriter)
+                    super.computeDncLogWriterForNewConnection("_xads");
             return getXAConnectionX(dncLogWriter, this, user, password);
         }
         catch ( SqlException se )
         {
+            // The method below may throw an exception.
+            handleConnectionException(dncLogWriter, se);
+            // If the exception wasn't handled so far, re-throw it.
             throw se.getSQLException();
         }
     }    

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java?rev=757811&r1=757810&r2=757811&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
Tue Mar 24 14:10:30 2009
@@ -247,10 +247,7 @@
             ds.getConnection();
             fail ("should have seen an error");
         } catch (SQLException e) {
-            if (usingEmbedded())
-                assertSQLState("XJ028", e);
-            else if (usingDerbyNetClient())
-                assertSQLState("XJ212", e);
+            assertSQLState("XJ028", e);
         } 
     } // End testBadConnectionAttributeSyntax
         



Mime
View raw message