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 da...@apache.org on 2006/02/18 00:32:23 UTC

svn commit: r378657 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/

Author: davidvc
Date: Fri Feb 17 15:32:20 2006
New Revision: 378657

URL: http://svn.apache.org/viewcvs?rev=378657&view=rev
Log:
DERBY-840: Message internationalization for client driver.  Originally
submitted by V. Narayanan, with some changes applied by myself.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/EncryptionManager.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
    db/derby/code/trunk/java/client/org/apache/derby/loc/clientmessages_en.properties
    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/DatabaseMetaData.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java?rev=378657&r1=378656&r2=378657&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/DatabaseMetaData.java Fri Feb 17 15:32:20 2006
@@ -20,9 +20,11 @@
 
 package org.apache.derby.client.am;
 
+import java.sql.SQLException;
+
 import org.apache.derby.jdbc.ClientDataSource;
+import org.apache.derby.shared.common.reference.SQLState;
 
-import java.sql.SQLException;
 
 // Note:
 //   Tag members using the strictest visibility.
@@ -1371,7 +1373,9 @@
         checkForClosedConnectionX();
         // check input params, table and columnNamePattern cannot be null
         if (table == null) {
-            throw new SqlException(agent_.logWriter_, "getColumnPrivileges(): null not allowed for table name");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL)); 
+
         }
 
         PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLCOLPRIVILEGES(?,?,?,?,?)");
@@ -1469,7 +1473,9 @@
         //
         // validate input table, which can not be null
         if (table == null) {
-            throw new SqlException(agent_.logWriter_, "getBestRowIdentifier(): null not allowed for table name");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL)); 
+
         }
         PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSPECIALCOLUMNS(?,?,?,?,?,?,?)");
 
@@ -1514,7 +1520,9 @@
 
         // validate input table, which can not be null
         if (table == null) {
-            throw new SqlException(agent_.logWriter_, "getBestRowIdentifier(): null not allowed for table name");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL)); 
+
         }
         PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSPECIALCOLUMNS(?,?,?,?,?,?,?)");
 
@@ -1563,7 +1571,9 @@
 
         // validate the input table name
         if (table == null) {
-            throw new SqlException(agent_.logWriter_, "getIndexInfo(): null not allowed for table name");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL)); 
+
         }
         PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLPRIMARYKEYS(?,?,?,?)");
 
@@ -1725,11 +1735,15 @@
 
         // check input params, primaryTable and foreignTable cannot be null
         if (primaryTable == null) {
-            throw new SqlException(agent_.logWriter_, "getCrossReference(): null not allowed for primary table name");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.PRIMARY_TABLE_NAME_IS_NULL)); 
+
         }
 
         if (foreignTable == null) {
-            throw new SqlException(agent_.logWriter_, "getCrossReference(): null not allowed for foreign table name");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.FOREIGN_TABLE_NAME_IS_NULL)); 
+
         }
 
         PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLFOREIGNKEYS(?,?,?,?,?,?,?)");
@@ -1818,7 +1832,8 @@
 
         // validate the input table name
         if (table == null) {
-            throw new SqlException(agent_.logWriter_, "getIndexInfo(): null not allowed for table name");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.TABLE_NAME_CANNOT_BE_NULL)); 
         }
         PreparedStatement cs = prepareMetaDataQuery("SYSIBM.SQLSTATISTICS(?,?,?,?,?,?)");
 
@@ -2323,7 +2338,9 @@
     private void checkForClosedConnectionX() throws SqlException {
         if (connection_.isClosedX()) {
             agent_.checkForDeferredExceptions();
-            throw new SqlException(agent_.logWriter_, "DatabaseMetaData method called after connection was closed");
+            throw new SqlException(agent_.logWriter_,
+                new MessageId(SQLState.NO_CURRENT_CONNECTION)); 
+
         } else {
             agent_.checkForDeferredExceptions();
         }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/EncryptionManager.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/EncryptionManager.java?rev=378657&r1=378656&r2=378657&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/EncryptionManager.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/EncryptionManager.java Fri Feb 17 15:32:20 2006
@@ -22,6 +22,8 @@
 
 import java.security.Provider;
 import java.security.Security;
+import org.apache.derby.shared.common.reference.SQLState;
+
 
 // This class is get used when using encrypted password and/or userid mechanism.
 // The <b>EncryptionManager</b> classs uses Diffie_Hellman algorithm to get the publick key and
@@ -105,18 +107,9 @@
             keyPair_ = keyPairGenerator_.generateKeyPair();
             keyAgreement_ = javax.crypto.KeyAgreement.getInstance("DH", providerName);
             keyAgreement_.init(keyPair_.getPrivate());
-        } catch (java.security.NoSuchProviderException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.NoSuchProviderException is caught" +
-                    " when initializing EncryptionManager '" + e.getMessage() + "'");
-        } catch (java.security.NoSuchAlgorithmException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.NoSuchAlgorithmException is caught" +
-                    " when initializing EncryptionManager '" + e.getMessage() + "'");
-        } catch (java.security.InvalidAlgorithmParameterException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidAlgorithmParameterException is caught" +
-                    " when initializing EncryptionManager '" + e.getMessage() + "'");
-        } catch (java.security.InvalidKeyException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidKeyException is caught" +
-                    " when initializing EncryptionManager '" + e.getMessage() + "'");
+        } catch (java.security.GeneralSecurityException e) {
+            throw new SqlException(agent_.logWriter_, 
+                new MessageId(SQLState.SECURITY_EXCEPTION_ENCOUNTERED), e); 
         }
     }
 
@@ -214,7 +207,10 @@
         byte temp;
         int changeParity;
         if (key.length != 8) {
-            throw new SqlException(agent_.logWriter_, "DES key has the wrong length");
+            throw new SqlException(agent_.logWriter_, 
+                new MessageId(SQLState.DES_KEY_HAS_WRONG_LENGTH), 
+                new Integer(8), new Integer(key.length)); 
+                        
         }
         for (int i = 0; i < 8; i++) {
             temp = key[i];
@@ -297,28 +293,19 @@
                     key[i] = newKey[i + 12];
                 }
             } else {
-                throw new SqlException(agent_.logWriter_, "sharedSecret key length error " + sharedSecret.length);
+                throw new SqlException(agent_.logWriter_, 
+                    new MessageId(SQLState.SHARED_KEY_LENGTH_ERROR),
+                    new Integer(sharedSecret.length)); 
             }
 
             //we do parity check here and flip the parity bit if the byte has even number of 1s
             keyParityCheck(key);
             return key;
-        }/*
-          catch (java.security.NoSuchProviderException e) {
-            throw new SqlException (agent_.logWriter_, e, "java.security.NoSuchProviderException is caught "
-                                    + "when encrypting data '" + e.getMessage() + "'");
-          }*/ catch (java.security.NoSuchAlgorithmException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.NoSuchAlgorithmException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.spec.InvalidKeySpecException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidKeySpecException is caught "
-                    + "when encrypting data");
-        } catch (java.security.InvalidKeyException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidKeyException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
         }
-
-
+        catch (java.security.GeneralSecurityException e) {
+            throw new SqlException(agent_.logWriter_, 
+                new MessageId(SQLState.SECURITY_EXCEPTION_ENCOUNTERED), e);
+        }
     }
 
     // This method encrypts the usreid/password with the middle 8 bytes of
@@ -373,31 +360,20 @@
 
             //Execute the final phase of encryption
             cipherText = cipher.doFinal(plainText);
-        } catch (java.security.NoSuchProviderException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.NoSuchProviderException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.NoSuchAlgorithmException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.NoSuchAlgorithmException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.InvalidKeyException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidKeyException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
         } catch (javax.crypto.NoSuchPaddingException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.NoSuchPaddingException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
+            throw new SqlException(agent_.logWriter_, 
+                        new MessageId(SQLState.CRYPTO_NO_SUCH_PADDING)); 
         } catch (javax.crypto.BadPaddingException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.BadPaddingException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.InvalidAlgorithmParameterException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidAlgorithmParameterException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
+            throw new SqlException(agent_.logWriter_, 
+                        new MessageId(SQLState.CRYPTO_BAD_PADDING)); 
         } catch (javax.crypto.IllegalBlockSizeException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.IllegalBlockSizeException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.spec.InvalidKeySpecException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.IllegalBlockSizeException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
+            throw new SqlException(agent_.logWriter_, 
+                        new MessageId(SQLState.CRYPTO_ILLEGAL_BLOCK_SIZE)); 
+        } catch (java.security.GeneralSecurityException e) {
+            throw new SqlException(agent_.logWriter_, 
+                new MessageId(SQLState.SECURITY_EXCEPTION_ENCOUNTERED), e); 
         }
+
         return cipherText;
     }
 
@@ -454,30 +430,18 @@
 
             //Execute the final phase of encryption
             plainText = cipher.doFinal(cipherText);
-        } catch (java.security.NoSuchProviderException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.NoSuchProviderException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.NoSuchAlgorithmException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.NoSuchAlgorithmException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.InvalidKeyException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidKeyException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
         } catch (javax.crypto.NoSuchPaddingException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.NoSuchPaddingException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
+            throw new SqlException(agent_.logWriter_, 
+                        new MessageId(SQLState.CRYPTO_NO_SUCH_PADDING)); 
         } catch (javax.crypto.BadPaddingException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.BadPaddingException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.InvalidAlgorithmParameterException e) {
-            throw new SqlException(agent_.logWriter_, e, "java.security.InvalidAlgorithmParameterException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
+            throw new SqlException(agent_.logWriter_, 
+                        new MessageId(SQLState.CRYPTO_BAD_PADDING)); 
         } catch (javax.crypto.IllegalBlockSizeException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.IllegalBlockSizeException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
-        } catch (java.security.spec.InvalidKeySpecException e) {
-            throw new SqlException(agent_.logWriter_, e, "javax.crypto.IllegalBlockSizeException is caught "
-                    + "when encrypting data '" + e.getMessage() + "'");
+            throw new SqlException(agent_.logWriter_, 
+                        new MessageId(SQLState.CRYPTO_ILLEGAL_BLOCK_SIZE)); 
+        } catch (java.security.GeneralSecurityException e) {
+            throw new SqlException(agent_.logWriter_, 
+                new MessageId(SQLState.SECURITY_EXCEPTION_ENCOUNTERED), e); 
         }
         return plainText;
     }

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=378657&r1=378656&r2=378657&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 Feb 17 15:32:20 2006
@@ -115,6 +115,11 @@
             ExceptionUtil.getSQLStateFromIdentifier(msgid.msgid),
             ExceptionUtil.getSeverityFromIdentifier(msgid.msgid));
     }
+
+    public SqlException(LogWriter logWriter, MessageId messageId, Throwable cause)
+    {
+        this(logWriter,messageId,null,cause);
+    }
     
     public SqlException(LogWriter logwriter, MessageId msgid, Object[] args)
     {
@@ -123,7 +128,7 @@
     
     public SqlException (LogWriter logwriter, MessageId msgid)
     {
-        this(logwriter, msgid, null);
+        this(logwriter, msgid, (Object[])null);
     }
     
     public SqlException(LogWriter logwriter, MessageId msgid, Object arg1)

Modified: db/derby/code/trunk/java/client/org/apache/derby/loc/clientmessages_en.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/loc/clientmessages_en.properties?rev=378657&r1=378656&r2=378657&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/loc/clientmessages_en.properties (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/loc/clientmessages_en.properties Fri Feb 17 15:32:20 2006
@@ -58,10 +58,17 @@
 XN006.S=Invalid parameter: calendar is null.
 XN009.S=Invalid argument: parameter index {0} is not an OUT or INOUT parameter.
 XN010.S=Parameter 1 is the return clause of the stored procedure call. It can only be registered as an integer type.
+XN100.S=Table name can not be null
+XN104.S=Shared key length is invalid: {0}.
+XN105.S=DES key has the wrong length, expected length {0}, got length {1}.
+XN106.S=No such padding 
+XN107.S=Bad Padding
+XN108.S=Illegal Block Size
+XN110.S=Primary table name can not be null
+XN111.S=Foreign table name can not be null
+XN112.S=Security exception encountered, see next exception for details.
 
 XN151.S=Unable to open file {0} : {1}
-
-
 
 #  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 #

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=378657&r1=378656&r2=378657&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 Fri Feb 17 15:32:20 2006
@@ -1515,7 +1515,15 @@
     String CALENDAR_IS_NULL                                         = "XN006.S";
     String PARAM_NOT_OUT_OR_INOUT                                   = "XN009.S";
     String RETURN_PARAM_MUST_BE_INT                                 = "XN010.S";
-    
+    String TABLE_NAME_CANNOT_BE_NULL                                = "XN100.S";
+    String SHARED_KEY_LENGTH_ERROR                                  = "XN104.S";
+    String DES_KEY_HAS_WRONG_LENGTH                                 = "XN105.S";
+    String CRYPTO_NO_SUCH_PADDING                                   = "XN106.S";
+    String CRYPTO_BAD_PADDING                                       = "XN107.S";
+    String CRYPTO_ILLEGAL_BLOCK_SIZE                                = "XN108.S";
+    String PRIMARY_TABLE_NAME_IS_NULL                               = "XN110.S";
+    String FOREIGN_TABLE_NAME_IS_NULL                               = "XN111.S";
+    String SECURITY_EXCEPTION_ENCOUNTERED                           = "XN112.S";
     String UNABLE_TO_OPEN_FILE = "XN151.S";
     
 	/*