db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r388778 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/SQLExceptionFactory40.java engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java shared/org/apache/derby/shared/common/reference/SQLState.java
Date Sat, 25 Mar 2006 16:07:40 GMT
Author: rhillegas
Date: Sat Mar 25 08:07:40 2006
New Revision: 388778

URL: http://svn.apache.org/viewcvs?rev=388778&view=rev
Log:
Commit my patch, attached to DERBY-1140, which eliminates magic strings in the JDBC4 SQLException
factories.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java

Modified: 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=388778&r1=388777&r2=388778&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory40.java
Sat Mar 25 08:07:40 2006
@@ -19,6 +19,8 @@
 */
 package org.apache.derby.client.am;
 
+import org.apache.derby.shared.common.reference.SQLState;
+
 import java.sql.SQLDataException;
 import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
@@ -54,24 +56,24 @@
         SQLException ex = null;
         if (sqlState == null) {
             ex = new SQLException(message, sqlState, errCode); 
-        } else if (sqlState.startsWith("08")) {
+        } else if (sqlState.startsWith(SQLState.CONNECTIVITY_PREFIX)) {
             //none of the sqlstate supported by derby belongs to
             //NonTransientConnectionException
             ex = new SQLTransientConnectionException(message, sqlState, errCode);
-        } else if (sqlState.startsWith("22")) {
+        } else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
             ex = new SQLDataException(message, sqlState, errCode);
-        } else if (sqlState.startsWith("23")) {
+        } else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
             ex = new SQLIntegrityConstraintViolationException(message, sqlState,
                     errCode);
-        } else if (sqlState.startsWith("28")) {
+        } else if (sqlState.startsWith(SQLState.AUTHORIZATION_PREFIX)) {
             ex = new SQLInvalidAuthorizationSpecException(message, sqlState,
                     errCode);
-        } else if (sqlState.startsWith("40")) {
+        } else if (sqlState.startsWith(SQLState.TRANSACTION_PREFIX)) {
             ex = new SQLTransactionRollbackException(message, sqlState,
                     errCode);
-        } else if (sqlState.startsWith("42")) {
+        } else if (sqlState.startsWith(SQLState.LSE_COMPILATION_PREFIX)) {
             ex = new SQLSyntaxErrorException(message, sqlState, errCode);
-        } else if (sqlState.startsWith ("0A")) {
+        } else if (sqlState.startsWith (SQLState.UNSUPPORTED_PREFIX)) {
             ex = new SQLFeatureNotSupportedException(message, sqlState, 
                     errCode);
         } else {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/SQLExceptionFactory40.java?rev=388778&r1=388777&r2=388778&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
Sat Mar 25 08:07:40 2006
@@ -27,7 +27,9 @@
 import java.sql.SQLSyntaxErrorException;
 import java.sql.SQLTransactionRollbackException;
 import java.sql.SQLTransientConnectionException;
+import java.sql.SQLFeatureNotSupportedException;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.shared.common.reference.SQLState;
 
 /**
  * SQLExceptionFactory40 overwrites getSQLException method
@@ -39,6 +41,7 @@
     /**
      * overwrites super class method to create JDBC4 exceptions      
      * SQLSTATE CLASS (prefix)     Exception
+     * 0A                          java.sql.SQLFeatureNotSupportedException
      * 08                          java.sql.SQLTransientConnectionException
      * 22                          java.sql.SQLDataException
      * 28                          java.sql.SQLInvalidAuthorizationSpecException
@@ -61,25 +64,27 @@
             SQLException next, int severity, Throwable t, Object[] args) {
         String sqlState = StandardException.getSQLStateFromIdentifier(messageId);
         SQLException ex = new SQLException(message, sqlState, severity, t);
-        if (sqlState.startsWith("08")) {
+        if (sqlState.startsWith(SQLState.CONNECTIVITY_PREFIX)) {
             //none of the sqlstate supported by derby belongs to
             //NonTransientConnectionException
             ex = new SQLTransientConnectionException(message, sqlState,
                     severity, t);
-        } else if (sqlState.startsWith("22")) {
+        } else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
             ex = new SQLDataException(message, sqlState, severity, t);
-        } else if (sqlState.startsWith("23")) {
+        } else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
             ex = new SQLIntegrityConstraintViolationException(message, sqlState,
                     severity, t);
-        } else if (sqlState.startsWith("28")) {
+        } else if (sqlState.startsWith(SQLState.AUTHORIZATION_PREFIX)) {
             ex = new SQLInvalidAuthorizationSpecException(message, sqlState,
                     severity, t);
         }        
-        else if (sqlState.startsWith("40")) {
+        else if (sqlState.startsWith(SQLState.TRANSACTION_PREFIX)) {
             ex = new SQLTransactionRollbackException(message, sqlState,
                     severity, t);
-        } else if (sqlState.startsWith("42")) {
+        } else if (sqlState.startsWith(SQLState.LSE_COMPILATION_PREFIX)) {
             ex = new SQLSyntaxErrorException(message, sqlState, severity, t);
+        } else if (sqlState.startsWith(SQLState.UNSUPPORTED_PREFIX)) {
+            ex = new SQLFeatureNotSupportedException(message, sqlState, severity, t);
         }
         
         if (next != null) {

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=388778&r1=388777&r2=388778&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Sat Mar 25 08:07:40 2006
@@ -427,6 +427,8 @@
 	/*
 	** RawStore - Transactions.Basic transaction exceptions
 	*/
+	String TRANSACTION_PREFIX="40";
+
 	String XACT_PROTOCOL_VIOLATION                              = "40XT0";
 	String XACT_COMMIT_EXCEPTION                                = "40XT1";
 	String XACT_ROLLBACK_EXCEPTION                              = "40XT2";
@@ -562,6 +564,7 @@
 	/*
 	** Connectivity - Connection Exceptions: 08XXX
 	*/
+	String CONNECTIVITY_PREFIX="08";
 
 	String	ERROR_CLOSE = "08003";
 
@@ -664,6 +667,11 @@
 	// 40XC0 - 40XCZ
 	String LANG_DEAD_STATEMENT                                         = "40XC0";
 
+	/*
+	** SQL Data exceptions
+	*/
+	String SQL_DATA_PREFIX="22";
+	
 	String LANG_MISSING_PARMS                                          = "07000";
 	String LANG_SCALAR_SUBQUERY_CARDINALITY_VIOLATION                  = "21000";
 	String LANG_STRING_TRUNCATION                                      = "22001";
@@ -686,6 +694,13 @@
 	String LANG_INVALID_ESCAPE_SEQUENCE                                = "22025";
 	String LANG_INVALID_TRIM_SET                                       = "22027";
 	String LANG_ESCAPE_IS_NULL                                  	   = "22501";
+
+
+	/*
+	** Integrity violations.
+	*/
+	String INTEGRITY_VIOLATION_PREFIX="23";
+	
 	String LANG_NULL_INTO_NON_NULL                                     = "23502";
 	String LANG_DUPLICATE_KEY_CONSTRAINT                               = "23505";
 	String LANG_FK_VIOLATION                                           = "23503";
@@ -1338,6 +1353,8 @@
 	/*
 		SQL standard 0A - feature not supported
 	*/
+	String UNSUPPORTED_PREFIX="0A";
+
     String NOT_IMPLEMENTED                                          = "0A000.S";
     String JDBC_METHOD_NOT_IMPLEMENTED                              = "0AX01.S";
 
@@ -1346,6 +1363,8 @@
 	/*
 	** Authorization and Authentication
 	*/
+	String AUTHORIZATION_PREFIX="28";
+	
 	String AUTH_DATABASE_CONNECTION_REFUSED                            = "04501.C";
 	String AUTH_SET_CONNECTION_READ_ONLY_IN_ACTIVE_XACT                = "25501";
 	String AUTH_WRITE_WITH_READ_ONLY_CONNECTION                        = "25502";



Mime
View raw message