db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1694492 - in /db/derby/code/trunk/java: build/org/apache/derbyBuild/lastgoodjarcontents/ client/org/apache/derby/client/am/ shared/org/apache/derby/shared/common/error/
Date Thu, 06 Aug 2015 13:47:16 GMT
Author: bpendleton
Date: Thu Aug  6 13:47:16 2015
New Revision: 1694492

URL: http://svn.apache.org/r1694492
Log:
DERBY-6803: Change Sqlca and SqlException to call MessageUtils

This patch was contributed by Abhinav Gupta (abhinavgupta2004 at gmail dot com)

This patch modifies the code in the client libraries
which analyzes the error or exception information in
the sqlerrmc message data, to use the new features of
the MessageUtils shared code to decode the message format.

In particular, the code can now locate and decode the
arguments as well as the message id, and therefore can
include those arguments when constructing a custom
Derby-specific subclass of SQLIntegrityConstraintViolationException.



Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyclient.jar.lastcontents
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyclient.jar.lastcontents
    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/am/Sqlca.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/error/DerbySQLIntegrityConstraintViolationException.java

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyclient.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyclient.jar.lastcontents?rev=1694492&r1=1694491&r2=1694492&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyclient.jar.lastcontents
(original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyclient.jar.lastcontents
Thu Aug  6 13:47:16 2015
@@ -166,6 +166,9 @@ org.apache.derby.jdbc.ClientXADataSource
 org.apache.derby.jdbc.ClientXADataSourceInterface.class
 org.apache.derby.shared.common.error.ExceptionSeverity.class
 org.apache.derby.shared.common.error.ExceptionUtil.class
+org.apache.derby.shared.common.error.ShutdownException.class
+org.apache.derby.shared.common.error.MessageUtils.class
+org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException.class
 org.apache.derby.shared.common.i18n.MessageUtil.class
 org.apache.derby.shared.common.reference.Attribute.class
 org.apache.derby.shared.common.reference.JDBC40Translation.class

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyclient.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyclient.jar.lastcontents?rev=1694492&r1=1694491&r2=1694492&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyclient.jar.lastcontents
(original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyclient.jar.lastcontents
Thu Aug  6 13:47:16 2015
@@ -166,7 +166,9 @@ org.apache.derby.jdbc.ClientXADataSource
 org.apache.derby.jdbc.ClientXADataSourceInterface.class
 org.apache.derby.shared.common.error.ExceptionSeverity.class
 org.apache.derby.shared.common.error.ExceptionUtil.class
+org.apache.derby.shared.common.error.ShutdownException.class
 org.apache.derby.shared.common.error.MessageUtils.class
+org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException.class
 org.apache.derby.shared.common.i18n.MessageUtil.class
 org.apache.derby.shared.common.reference.Attribute.class
 org.apache.derby.shared.common.reference.JDBC40Translation.class

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SQLExceptionFactory.java?rev=1694492&r1=1694491&r2=1694492&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 Thu
Aug  6 13:47:16 2015
@@ -32,6 +32,7 @@ import java.sql.SQLNonTransientConnectio
 import java.sql.SQLSyntaxErrorException;
 import java.sql.SQLTimeoutException;
 import java.sql.SQLTransactionRollbackException;
+import org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException;
 
 
 /**
@@ -60,7 +61,7 @@ public class SQLExceptionFactory {
      * @param errCode derby error code
      */
     public SQLException getSQLException (String message, String sqlState, 
-                                                            int errCode) { 
+                                         int errCode, Object []args) { 
         SQLException ex = null;
         if (sqlState == null) {
             ex = new SQLException(message, sqlState, errCode); 
@@ -71,8 +72,8 @@ public class SQLExceptionFactory {
         } else if (sqlState.startsWith(SQLState.SQL_DATA_PREFIX)) {
             ex = new SQLDataException(message, sqlState, errCode);
         } else if (sqlState.startsWith(SQLState.INTEGRITY_VIOLATION_PREFIX)) {
-            ex = new SQLIntegrityConstraintViolationException(message, sqlState,
-                    errCode);
+            ex = new DerbySQLIntegrityConstraintViolationException(message, sqlState,
+                    errCode, args[0], args[1]);
         } else if (sqlState.startsWith(SQLState.AUTHORIZATION_SPEC_PREFIX)) {
             ex = new SQLInvalidAuthorizationSpecException(message, sqlState,
                     errCode);

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=1694492&r1=1694491&r2=1694492&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 Thu Aug 
6 13:47:16 2015
@@ -319,7 +319,7 @@ public class SqlException extends Except
         // When we have support for JDBC 4 SQLException subclasses, this is
         // where we decide which exception to create
         SQLException sqle = exceptionFactory.getSQLException(getMessage(), getSQLState(),

-            getErrorCode());
+            getErrorCode(), getArgs());
         sqle.initCause(this);
 
         // Set up the nextException chain
@@ -352,6 +352,12 @@ public class SqlException extends Except
         return "ERROR " + getSQLState() + ": " + getMessage();
     }
 
+    private Object []getArgs() {
+        if( sqlca_ != null )
+            return ((Sqlca)sqlca_).getArgs(messageNumber_);
+        return null;
+    }
+
     @Override
     public String getMessage() {
         if ( wrappedException_ != null )

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java?rev=1694492&r1=1694491&r2=1694492&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java Thu Aug  6 13:47:16
2015
@@ -27,6 +27,7 @@ import java.util.Locale;
 import org.apache.derby.client.net.Typdef;
 import org.apache.derby.shared.common.error.ExceptionSeverity;
 import org.apache.derby.shared.common.reference.SQLState;
+import org.apache.derby.shared.common.error.MessageUtils;
 
 public abstract class Sqlca {
 
@@ -64,12 +65,11 @@ public abstract class Sqlca {
 
     /**
      * Character sequence that separates the different messages in the errmc.
-     * @see org.apache.derby.catalog.SystemProcedures#SQLERRMC_MESSAGE_DELIMITER
+     * @see org.apache.derby.shared.common.error.MessageUtils#SQLERRMC_MESSAGE_DELIMITER
      */
     private static final String sqlErrmcDelimiter__ = "\u0014\u0014\u0014";
 
-    /** Token delimiter for SQLERRMC. */
-    private final static String SQLERRMC_TOKEN_DELIMITER = "\u0014";
+    
 
     // JDK stack trace calls e.getMessage(), so we must set some state on the sqlca that
says return tokens only.
     private boolean returnTokensOnlyInMessageText_ = false;
@@ -255,6 +255,13 @@ public abstract class Sqlca {
         return getSqlState();
     }
 
+    public Object [] getArgs(int messageNumber) {
+        if (sqlErrmcMessages_ != null)
+	    return MessageUtils.getArgs(getSqlState(messageNumber),
+                                        sqlErrmcMessages_[messageNumber] );
+        return null;
+    }
+
     // Gets the formatted message, can throw an exception.
     private String getMessage(int messageNumber) throws SqlException {
         // should this be traced to see if we are calling a stored proc?
@@ -412,7 +419,7 @@ public abstract class Sqlca {
     DataTruncation getDataTruncation() {
         // The network server has serialized all the parameters needed by
         // the constructor in the SQLERRMC field.
-        String[] tokens = getSqlErrmc().split(SQLERRMC_TOKEN_DELIMITER);
+        String[] tokens = getSqlErrmc().split(MessageUtils.SQLERRMC_TOKEN_DELIMITER);
         return new DataTruncation(
                 Integer.parseInt(tokens[0]),                // index
                 Boolean.valueOf(tokens[1]).booleanValue(),  // parameter

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/error/DerbySQLIntegrityConstraintViolationException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/error/DerbySQLIntegrityConstraintViolationException.java?rev=1694492&r1=1694491&r2=1694492&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/error/DerbySQLIntegrityConstraintViolationException.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/error/DerbySQLIntegrityConstraintViolationException.java
Thu Aug  6 13:47:16 2015
@@ -35,6 +35,18 @@ public  class  DerbySQLIntegrityConstrai
 		constraintName = argsTwo.toString();
 	}
 
+       public  DerbySQLIntegrityConstraintViolationException(
+			String reason,
+			String SQLState,
+			int vendorCode,
+			Object argsOne,
+			Object argsTwo)
+	{
+		super( reason, SQLState, vendorCode );
+		tableName = argsOne.toString();
+		constraintName = argsTwo.toString();
+	}
+
 	public String getTableName() { return tableName; }
 	public String getConstraintName() { return constraintName; }
 



Mime
View raw message