db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r388558 - in /db/derby/code/trunk/java/client/org/apache/derby/client: am/SQLExceptionFactory.java am/SQLExceptionFactory40.java am/SqlException.java net/ClientJDBCObjectFactoryImpl40.java
Date Fri, 24 Mar 2006 15:16:20 GMT
Author: rhillegas
Date: Fri Mar 24 07:16:17 2006
New Revision: 388558

URL: http://svn.apache.org/viewcvs?rev=388558&view=rev
Log:
Committing rev 2 of Anurag's patch for DERBY-1140: JDBC4 SQLException triage for the network
client.

Added:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
  (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory.java?rev=388558&r1=388557&r2=388558&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory.java Fri
Mar 24 07:16:17 2006
@@ -35,4 +35,20 @@
         return sqlException.getSQLException();
     }
     
+    /**
+     * creates SQLException initialized with all the params received from the 
+     * caller. This method will be overwritten to support jdbc version specific 
+     * exception class.
+     * @param message 
+     * @param sqlState SQL 
+     * @param errCode derby error code
+     * @param next next excewption for chaining
+     * @param cause root cause of the exception
+     * @return SQLException
+     */
+    public SQLException getSQLException (String message, String sqlState, 
+            int errCode) {
+        return new SQLException (message, sqlState, errCode);           
+    }    
 }
+ 

Added: db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java?rev=388558&view=auto
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
(added)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
Fri Mar 24 07:16:17 2006
@@ -0,0 +1,82 @@
+/*
+
+   Derby - Class org.apache.derby.client.am.SQLExceptionFactory40
+
+   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.am;
+
+import java.sql.SQLDataException;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLIntegrityConstraintViolationException;
+import java.sql.SQLInvalidAuthorizationSpecException;
+import java.sql.SQLSyntaxErrorException;
+import java.sql.SQLTransactionRollbackException;
+import java.sql.SQLTransientConnectionException;
+
+/**
+ * SQLException factory class to create jdbc 40 exception classes
+ */
+
+public class SQLExceptionFactory40 extends SQLExceptionFactory {
+    
+    /**
+     * creates jdbc4.0 SQLException and its subclass based on sql state
+     * 0A                          java.sql.SQLFeatureNotSupportedException
+     * 08                          java.sql.SQLTransientConnectionException
+     * 22                          java.sql.SQLDataException
+     * 28                          java.sql.SQLInvalidAuthorizationSpecException
+     * 40                          java.sql.SQLTransactionRollbackException
+     * 42                          java.sql.SQLSyntaxErrorException
+     * 
+     * @param message description of the 
+     * @param sqlState 
+     * @param errCode derby error code
+     * @param cause root cause of the exception
+     * @return SQLException
+     */
+    public SQLException getSQLException (String message, String sqlState, 
+                                                            int errCode) {        
+        SQLException ex = null;
+        if (sqlState == null) {
+            ex = new SQLException(message, sqlState, errCode); 
+        } else if (sqlState.startsWith("08")) {
+            //none of the sqlstate supported by derby belongs to
+            //NonTransientConnectionException
+            ex = new SQLTransientConnectionException(message, sqlState, errCode);
+        } else if (sqlState.startsWith("22")) {
+            ex = new SQLDataException(message, sqlState, errCode);
+        } else if (sqlState.startsWith("23")) {
+            ex = new SQLIntegrityConstraintViolationException(message, sqlState,
+                    errCode);
+        } else if (sqlState.startsWith("28")) {
+            ex = new SQLInvalidAuthorizationSpecException(message, sqlState,
+                    errCode);
+        } else if (sqlState.startsWith("40")) {
+            ex = new SQLTransactionRollbackException(message, sqlState,
+                    errCode);
+        } else if (sqlState.startsWith("42")) {
+            ex = new SQLSyntaxErrorException(message, sqlState, errCode);
+        } else if (sqlState.startsWith ("0A")) {
+            ex = new SQLFeatureNotSupportedException(message, sqlState, 
+                    errCode);
+        } else {
+            ex = new SQLException(message, sqlState, errCode); 
+        }
+        return ex;
+    }
+}

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

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=388558&r1=388557&r2=388558&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Fri Mar 24
07:16:17 2006
@@ -85,6 +85,11 @@
     public static String CLIENT_MESSAGE_RESOURCE_NAME =
         "org.apache.derby.loc.clientmessages";
     
+    //SQLException factory initialised with default factory
+    //It will be over written by the SQLException factory of the 
+    //supported jdbc version    
+    protected static SQLExceptionFactory 
+            exceptionFactory = new SQLExceptionFactory ();
     
     /** 
      *  The message utility instance we use to find messages
@@ -290,7 +295,7 @@
                         
         // When we have support for JDBC 4 SQLException subclasses, this is
         // where we decide which exception to create
-        SQLException sqle = new SQLException(getMessage(), getSQLState(), 
+        SQLException sqle = exceptionFactory.getSQLException(getMessage(), getSQLState(),

             getErrorCode());
 
         // If we're in a runtime that supports chained exceptions, set the cause 
@@ -431,6 +436,14 @@
         } else {
             return new SqlException(logWriter, getMessage(), getSQLState(), getErrorCode());
// client error
         }
+    }
+    
+    /**
+     * Sets the exceptionFactory to be used for creating SQLException
+     * @param factory SQLExceptionFactory
+     */
+    public static void setExceptionFactory (SQLExceptionFactory factory) {
+        exceptionFactory = factory;
     }
 }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java?rev=388558&r1=388557&r2=388558&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl40.java
Fri Mar 24 07:16:17 2006
@@ -29,6 +29,7 @@
 import org.apache.derby.client.am.PreparedStatement40;
 import org.apache.derby.client.am.LogWriter;
 import org.apache.derby.client.am.Agent;
+import org.apache.derby.client.am.SQLExceptionFactory40;
 import org.apache.derby.client.am.Section;
 import org.apache.derby.client.am.SqlException;
 import org.apache.derby.client.am.Cursor;
@@ -40,6 +41,14 @@
  * and returns the JDBC4.0 specific classes
  */
 public class ClientJDBCObjectFactoryImpl40 implements ClientJDBCObjectFactory{
+    
+    /**
+     * Sets SQLExceptionFactpry40  om SqlException to make sure jdbc40 
+     * exception and sub classes are thrown when running with jdbc4.0 support
+     */
+    public ClientJDBCObjectFactoryImpl40 () {
+        SqlException.setExceptionFactory (new SQLExceptionFactory40 ());
+    }
     /**
      * Returns an instance of org.apache.derby.client.ClientPooledConnection40 
      */



Mime
View raw message