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 dj...@apache.org on 2008/02/25 17:02:53 UTC

svn commit: r630903 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/error/DerbySQLException.java iapi/error/StandardException.java impl/jdbc/EmbedSQLException.java impl/jdbc/SQLExceptionFactory.java impl/jdbc/SQLExceptionFactory40.java

Author: djd
Date: Mon Feb 25 08:02:51 2008
New Revision: 630903

URL: http://svn.apache.org/viewvc?rev=630903&view=rev
Log:
DERBY-3451 A new interface called DerbySQLException has been added to org.apache.derby.iapi.error.
The EmbedSQLException class has been modified to implement this interface.
The StandardException calls the isSimpleWrapper method on the DerbySQLException interface, thereby avoiding a need to reference EmbedSQLException.

A new static method getArgumentFerry() has been added to StandardExcepion. This performs the same task as the current getArgumentFerry() method in SQLExceptionFactory and SQLExceptionFactory40.
SQLExceptionFactory.getArgumentFerry() has been amended to call StandardException.getArgumentFerry().
SQLExceptionFactory40.getArgumentFerry() has been removed.
StandardException.getArgumentFerry() now handles the pre-JDBC3 and post-JDBC4 scenarios (in the pre-JDBC4 scenario, the passed argument is a DerbySQLException, which is returned immediately), so there is no need to override this functionality.

This change allows us to avoid having a dependency between StandardException and Util.
As the getArgumentFerry() method now checks for DerbySQLException rather than EmbedSQLException, it is able to avoid dependency on EmbedSQLException.

Patch contributed by Dibyendu Majumdar Email: dibyendu at mazumdar dot demon dot co dot uk (no ILCA on file but minor patch - reorganizing existing code, ALv2 flag checked on patch in jira attachement)

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/DerbySQLException.java   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedSQLException.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java

Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/DerbySQLException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/DerbySQLException.java?rev=630903&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/DerbySQLException.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/DerbySQLException.java Mon Feb 25 08:02:51 2008
@@ -0,0 +1,38 @@
+/*
+
+   Derby - Class org.apache.derby.iapi.error.DerbySQLException
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you 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.iapi.error;
+
+/**
+ * DerbySQLException should be implemented by Derby's SQLException
+ * sub classes to allow the exception handling mechanism to distinguish between
+ * ordinary SQLExceptions and Derby generated ones. 
+ * @see org.apache.derby.impl.jdbc.EmbedSQLException
+ */
+public interface DerbySQLException {
+	
+	/**
+	 * Returns true if this instance of DerbySQLException wraps
+     * a StandardException object.
+	 * @return true if this exception wraps a StandardException object
+	 */
+    public boolean isSimpleWrapper();
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/DerbySQLException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java?rev=630903&r1=630902&r2=630903&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java Mon Feb 25 08:02:51 2008
@@ -21,17 +21,13 @@
 
 package org.apache.derby.iapi.error;
 
-import org.apache.derby.iapi.reference.SQLState;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
 
-import org.apache.derby.impl.jdbc.EmbedSQLException;
-import org.apache.derby.impl.jdbc.Util;
-import org.apache.derby.iapi.error.ExceptionSeverity;
+import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.i18n.MessageService;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-
 /**
 	StandardException is the root of all exceptions that are handled
 	in a standard fashion by the database code, mainly in the language code.
@@ -440,21 +436,48 @@
             se.initCause(t);
         return se;
     }
+    
+    
+	/**
+	 * Unpack the exception, looking for an DerbySQLException, which carries
+	 * the Derby messageID and arguments. 
+	 * @see org.apache.derby.impl.jdbc.SQLExceptionFactory
+	 * @see org.apache.derby.impl.jdbc.SQLExceptionFactory40
+	 * @see org.apache.derby.impl.jdbc.Util
+	 */
+	public static SQLException	getArgumentFerry(SQLException se)
+	{
+		if (se instanceof DerbySQLException) {
+			/*
+			 * Cater for pre-JDBC4 scenario.
+			 */
+			return se;
+		}
+		/*
+		 * See DERBY-1178 for background information.
+		 * In JDBC4, the DerbySQLException may be wrapped by a SQLException.
+		 */
+		Throwable	cause = se.getCause();
+
+		if ( (cause == null) || !(cause instanceof DerbySQLException ))	{ return se; }
+		else	{ return (SQLException) cause; }
+	}
+
 
 	public static StandardException unexpectedUserException(Throwable t)
 	{
         // If the exception is an SQLException generated by Derby, it has an
-        // argument ferry which is an EmbedSQLException. Use this to check
+        // argument ferry which is an DerbySQLException. Use this to check
         // whether the exception was generated by Derby.
-        EmbedSQLException ferry = null;
+        DerbySQLException ferry = null;
         if (t instanceof SQLException) {
             SQLException sqle =
-                Util.getExceptionFactory().getArgumentFerry((SQLException) t);
-            if (sqle instanceof EmbedSQLException) {
-                ferry = (EmbedSQLException) sqle;
+                getArgumentFerry((SQLException) t);
+            if (sqle instanceof DerbySQLException) {
+                ferry = (DerbySQLException) sqle;
             }
         }
-
+        
 		/*
 		** If we have a SQLException that isn't an EmbedSQLException
 		** (i.e. it didn't come from Derby), then we check
@@ -483,7 +506,7 @@
 		// Look for simple wrappers for 3.0.1 - will be cleaned up in main
 		if (ferry != null) {
 			if (ferry.isSimpleWrapper()) {
-				Throwable wrapped = ferry.getCause();
+				Throwable wrapped = ((SQLException)ferry).getCause();
 				if (wrapped instanceof StandardException)
 					return (StandardException) wrapped;
 			}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedSQLException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedSQLException.java?rev=630903&r1=630902&r2=630903&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedSQLException.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedSQLException.java Mon Feb 25 08:02:51 2008
@@ -21,11 +21,10 @@
 
 package org.apache.derby.impl.jdbc;
 
-import org.apache.derby.iapi.error.StandardException;
-
+import org.apache.derby.iapi.error.DerbySQLException;
 import java.sql.SQLException;
-import java.io.PrintStream;
-import java.io.PrintWriter;
+
+import org.apache.derby.iapi.error.StandardException;
 
 /**
 	This class is what gets send over the wire in client/server
@@ -37,7 +36,7 @@
     on the server side and it also decreases the size of client
     jar file tremendously.
 */
-public class EmbedSQLException extends SQLException {
+public class EmbedSQLException extends SQLException implements DerbySQLException {
 
 	private transient Object[] arguments;
 	private String messageId;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory.java?rev=630903&r1=630902&r2=630903&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory.java Mon Feb 25 08:02:51 2008
@@ -56,7 +56,7 @@
 	 */
 	public	SQLException	getArgumentFerry(SQLException se)
 	{
-		return se;
+		return StandardException.getArgumentFerry(se);
 	}
 
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java?rev=630903&r1=630902&r2=630903&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java Mon Feb 25 08:02:51 2008
@@ -102,22 +102,6 @@
     }        
 
 	/**
-	 * Unpack the exception, looking for an EmbedSQLException which carries
-	 * the Derby messageID and args which we will serialize across DRDA so
-	 * that the client can reconstitute a SQLException with appropriate text.
-	 * If we are running JDBC4, then the
-	 * passed-in exception will hopefully wrap an informative EmbedSQLException.
-	 * See wrapArgsForTransportAcrossDRDA() below.
-	 */
-	public	SQLException	getArgumentFerry(SQLException se)
-	{
-		Throwable	cause = se.getCause();
-
-		if ( (cause == null) || !(cause instanceof EmbedSQLException ))	{ return se; }
-		else	{ return (SQLException) cause; }
-	}
-
-	/**
 	 * <p>
 	 * The following method helps handle DERBY-1178. The problem is that we may
 	 * need to serialize our final SQLException across the DRDA network layer.