db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r1694383 - in /db/derby/code/trunk/java: build/org/apache/derbyBuild/lastgoodjarcontents/ drda/org/apache/derby/impl/drda/ engine/org/apache/derby/catalog/ engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/iapi/services/i18n/ ...
Date Thu, 06 Aug 2015 00:36:20 GMT
Author: bpendleton
Date: Thu Aug  6 00:36:20 2015
New Revision: 1694383

URL: http://svn.apache.org/r1694383
Log:
DERBY-6802: Change NetworkServer code to use new MessageUtils class
DERBY-6823: Refactor uses of DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH

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

This change modifies several classes in the Network Server and Engine
code bases to use the new features of the MessageUtils class in the
shared code.

The intent of this change is that no behavior is altered. The same
algorithms, data structures, network protocols, etc. are in use;
the only difference is that the implementation of the error message
and exception encoding logic is now drawn from MessageUtils methods
rather than being spread over several classes in the Network Server
and Engine code.

Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbynet.jar.lastcontents
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbynet.jar.lastcontents
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Limits.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbynet.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbynet.jar.lastcontents?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbynet.jar.lastcontents
(original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbynet.jar.lastcontents
Thu Aug  6 00:36:20 2015
@@ -47,4 +47,5 @@ org.apache.derby.impl.tools.sysinfo.ZipI
 org.apache.derby.mbeans.drda.NetworkServerMBean.class
 org.apache.derby.shared.common.reference.MessageId.class
 org.apache.derby.shared.common.error.MessageUtils.class
+org.apache.derby.shared.common.error.ShutdownException.class
 org.apache.derby.tools.sysinfo.class

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbynet.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbynet.jar.lastcontents?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbynet.jar.lastcontents
(original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbynet.jar.lastcontents
Thu Aug  6 00:36:20 2015
@@ -46,6 +46,7 @@ org.apache.derby.impl.tools.sysinfo.Main
 org.apache.derby.impl.tools.sysinfo.ZipInfoProperties.class
 org.apache.derby.mbeans.drda.NetworkServerMBean.class
 org.apache.derby.shared.common.error.MessageUtils.class
+org.apache.derby.shared.common.error.ShutdownException.class
 org.apache.derby.shared.common.reference.MessageId.class
 org.apache.derby.shared.common.sanity.AssertFailure.class
 org.apache.derby.shared.common.sanity.SanityManager.class

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java Thu Aug  6
00:36:20 2015
@@ -21,7 +21,7 @@
 
 package org.apache.derby.impl.drda;
 import org.apache.derby.iapi.reference.DRDAConstants;
-import org.apache.derby.iapi.reference.Limits;
+import org.apache.derby.shared.common.error.MessageUtils;
 import org.apache.derby.shared.common.sanity.SanityManager;
 
 /**
@@ -251,7 +251,7 @@ class AppRequester
      */
 
     protected int supportedMessageParamLength() {
-        return Limits.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH;
+        return MessageUtils.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH;
     }
 
     /**

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Thu Aug 
6 00:36:20 2015
@@ -65,6 +65,7 @@ import org.apache.derby.iapi.services.in
 import org.apache.derby.iapi.services.monitor.ModuleFactory;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.shared.common.sanity.SanityManager;
+import org.apache.derby.shared.common.error.MessageUtils;
 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
 import org.apache.derby.iapi.tools.i18n.LocalizedResource;
 import org.apache.derby.iapi.util.StringUtil;
@@ -6518,31 +6519,21 @@ class DRDAConnThread extends Thread {
             StandardException ferry = StandardException.getArgumentFerry(se);
             if (ferry != null)
             {
-                String messageId = ferry.getMessageId();
-                // arguments are variable part of a message
-                Object[] args = ferry.getArguments();
-                for (int i = 0; args != null &&  i < args.length; i++) {
-                    sqlerrmc += args[i] + SQLERRMC_TOKEN_DELIMITER;
-                }
-                sqlerrmc += messageId;
+                sqlerrmc += MessageUtils.encodeMessageAndArgumentsAsSqlerrmc(
+                                ferry.getMessageId(),
+                                ferry.getArguments());
                 se = se.getNextException();
             }
             else
             {   
                 // this could happen for instance if an SQLException was thrown
                 // from a stored procedure.
-                StringBuilder sb = new StringBuilder();
-                sb.append(se.getLocalizedMessage());
+                sqlerrmc += MessageUtils.encodeExceptionAsSqlerrmc( se );
                 se = se.getNextException();
-                if (se != null) {
-                    sb.append(SQLERRMC_TOKEN_DELIMITER);
-                    sb.append("SQLSTATE: ").append(se.getSQLState());
-                }
-                sqlerrmc += sb.toString();
             }
             if (se != null)
             {
-                sqlerrmc += SystemProcedures.SQLERRMC_MESSAGE_DELIMITER + se.getSQLState()
+ ":";
+                sqlerrmc += MessageUtils.SQLERRMC_MESSAGE_DELIMITER + se.getSQLState() +
":";
             }
         } while (se != null);
         return sqlerrmc;

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Thu Aug  6 00:36:20 2015
@@ -83,6 +83,7 @@ import org.apache.derby.impl.jdbc.Util;
 import org.apache.derby.mbeans.VersionMBean;
 import org.apache.derby.mbeans.drda.NetworkServerMBean;
 import org.apache.derby.security.SystemPermission;
+import org.apache.derby.shared.common.error.MessageUtils;
 
 /** 
     
@@ -2146,7 +2147,7 @@ public final class NetworkServerControlI
                 ferry != null)
             {
                 locMsg.append(se.getSQLState()+":"+ 
-                    MessageService.getLocalizedMessage(
+                    MessageUtils.getLocalizedMessage(
                     currentSession.langUtil.getLocale(),
                     ferry.getMessageId(), ferry.getArguments()));
             }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/SystemProcedures.java Thu Aug
 6 00:36:20 2015
@@ -77,6 +77,7 @@ import org.apache.derby.iapi.sql.diction
 import org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission;
 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
 import org.apache.derby.iapi.sql.dictionary.UserDescriptor;
+import org.apache.derby.shared.common.error.MessageUtils;
 
 /**
 	Some system built-in procedures, and help routines.  Now used for network server.
@@ -96,14 +97,6 @@ public class SystemProcedures  {
 	private final static String DRIVER_TYPE_OPTION = "DATATYPE";
 	private final static String ODBC_DRIVER_OPTION = "'ODBC'";
 
-    // This token delimiter value is used to separate the tokens for multiple 
-    // error messages.  This is used in DRDAConnThread
-    /**
-     * <code>SQLERRMC_MESSAGE_DELIMITER</code> When message argument tokes are
sent,
-     * this value separates the tokens for mulitiple error messages 
-     */
-    public static final String SQLERRMC_MESSAGE_DELIMITER = new String(new char[] {(char)20,(char)20,(char)20});
-
 	/**
 	  Method used by Derby Network Server to get localized message (original call
 	  from jcc.
@@ -139,16 +132,16 @@ public class SystemProcedures  {
 		// translated and append to make the final result.
 		for (int index=0; ; numMessages++)
 		{
-			if (sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, index) == -1)
+			if (sqlerrmc.indexOf(MessageUtils.SQLERRMC_MESSAGE_DELIMITER, index) == -1)
 				break;
-			index = sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, index) + 
-                        SQLERRMC_MESSAGE_DELIMITER.length();
+			index = sqlerrmc.indexOf(MessageUtils.SQLERRMC_MESSAGE_DELIMITER, index) + 
+                        MessageUtils.SQLERRMC_MESSAGE_DELIMITER.length();
 		}
 
 		// Putting it here instead of prepareCall it directly is because inter-jar reference tool
 		// cannot detect/resolve this otherwise
 		if (numMessages == 1)
-			MessageService.getLocalizedMessage(sqlcode, errmcLen, sqlerrmc, sqlerrp, errd0, errd1,
+			MessageUtils.getLocalizedMessage(sqlcode, errmcLen, sqlerrmc, sqlerrp, errd0, errd1,
 											errd2, errd3, errd4, errd5, warn, sqlState, file,
 											localeStr, msg, rc);
 		else
@@ -158,7 +151,7 @@ public class SystemProcedures  {
 			String[] errMsg = new String[2];
 			for (int i=0; i<numMessages; i++)
 			{
-				endIdx = sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, startIdx);
+				endIdx = sqlerrmc.indexOf(MessageUtils.SQLERRMC_MESSAGE_DELIMITER, startIdx);
 				if (i == numMessages-1)				// last error message
 					sqlError = sqlerrmc.substring(startIdx);
 				else sqlError = sqlerrmc.substring(startIdx, endIdx);
@@ -171,7 +164,7 @@ public class SystemProcedures  {
 					msg[0] += " SQLSTATE: " + sqlState + ": ";
 				}
 
-				MessageService.getLocalizedMessage(sqlcode, (short)sqlError.length(), sqlError,
+				MessageUtils.getLocalizedMessage(sqlcode, (short)sqlError.length(), sqlError,
 											sqlerrp, errd0, errd1, errd2, errd3, errd4, errd5,
 											warn, sqlState, file, localeStr, errMsg, rc);
 
@@ -181,7 +174,7 @@ public class SystemProcedures  {
 						msg[0] = errMsg[0];
 					else msg[0] += errMsg[0];	// append the new message
 				}
-				startIdx = endIdx + SQLERRMC_MESSAGE_DELIMITER.length();
+				startIdx = endIdx + MessageUtils.SQLERRMC_MESSAGE_DELIMITER.length();
 			}
 		}
 	}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Limits.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Limits.java?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Limits.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Limits.java Thu Aug  6
00:36:20 2015
@@ -45,11 +45,6 @@ public interface Limits
 	public static final int DB2_MAX_ELEMENTS_IN_ORDER_BY = 1012;
 
 
-
-	// Warning. Changing this value will affect upgrade and the creation of the
-	// SQLCAMESSAGE procedure. See org.apache.derby.impl.sql.catalog.
-	public static final int DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH = 2400;
-
         /* Identifiers (Constraint, Cursor, Function/Procedure, Index,
          * Trigger, Column, Schema, Savepoint, Table and View names)
          * are limited to 128 */ 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/i18n/MessageService.java
Thu Aug  6 00:36:20 2015
@@ -82,120 +82,7 @@ public final class MessageService {
 		return formatMessage(getBundleForLocale(EN, messageId), messageId, arguments, false);
 	}
 
-	/**
-	  Method used by Derby Network Server to get localized message
-
-	  @param sqlcode	sqlcode, not used.
-	  @param errmcLen	sqlerrmc length
-	  @param sqlerrmc	sql error message tokens, variable part of error message (ie.,
-						arguments) plus messageId, separated by separator.
-	  @param sqlerrp	not used
-	  @param errd0		not used
-	  @param warn		not used
-	  @param sqlState	5-char sql state
-	  @param file		not used
-	  @param localeStr	client locale in string
-	  @param msg		OUTPUT parameter, localized error message
-	  @param rc			OUTPUT parameter, return code -- 0 for success
-	 */
-	public static void getLocalizedMessage(int sqlcode, short errmcLen, String sqlerrmc,
-										String sqlerrp, int errd0, int errd1, int errd2,
-										int errd3, int errd4, int errd5, String warn,
-										String sqlState, String file, String localeStr,
-										String[] msg, int[] rc)
-	{
-		//figure out client locale from input locale string
-
-		int _pos1 = localeStr.indexOf("_");		// "_" position
-
-		Locale locale = EN;		//default locale
-		if (_pos1 != -1)
-		{
-		    int _pos2 = localeStr.lastIndexOf("_");
-			String language = localeStr.substring(0, _pos1);
-			if (_pos2 == _pos1)
-			{
-				String country = localeStr.substring(_pos1 + 1);
-				locale = new Locale(language, country);
-			}
-			else
-			{
-				String country = localeStr.substring(_pos1 + 1, _pos2);
-				String variant = localeStr.substring(_pos2 + 1);
-				locale = new Locale(language, country, variant);
-			}
-		}
-
-		// get messageId and arguments, messageId is necessary for us to look up
-		// localized message from property file.  messageId was sent as the last
-		// token in the sqlerrmc.
-
-		String messageId = sqlState; 	//use sqlState if we don't have messageId
-		Object[] arguments = null;
-		if (sqlerrmc != null && sqlerrmc.length() > 0)
-		{
-			char [] sqlerrmc_chars = sqlerrmc.toCharArray();
-			int numArgs = 0, lastSepIdx = -1; // last separator index
-			for (int i = 0; i < sqlerrmc_chars.length; i++)
-			{
-				if (sqlerrmc_chars[i] == 20)	// separator
-				{
-					numArgs++;
-					lastSepIdx = i;
-				}
-			}
-			if (numArgs == 0)
-				messageId = new String(sqlerrmc_chars); //no args, only messageId then
-			else
-			{
-				messageId = new String(sqlerrmc_chars, lastSepIdx+1, sqlerrmc_chars.length-lastSepIdx-1);
-				arguments = new Object[numArgs];
-				for (int start = 0, arg = 0, i = 0; i < lastSepIdx + 1; i++)
-				{
-					if (i == lastSepIdx || sqlerrmc_chars[i] == 20)	// delimiter 
-					{
-						arguments[arg++] = new String(sqlerrmc_chars, start, i - start);
-						start = i + 1;
-					}
-				}
-			}
-		}
 
-		try {
-			msg[0] = formatMessage(getBundleForLocale(locale, messageId), messageId, arguments, true);
-			rc[0] = 0;
-			return;
-		} catch (MissingResourceException mre) {
-			// message does not exist in the requested locale
-			// most likely it does exist in our fake base class _en, so try that.
-		} catch (ShutdownException se) {
-		}
-		msg[0] = formatMessage(getBundleForLocale(EN, messageId), messageId, arguments, false);
-		rc[0] = 0;
-	}
-	
-	/**
-	  Method used by Derby Network Server to get localized message 
-
-	  @param locale		locale
-	  @param messageId	message id
-	  @param args		message arguments
-	 */
-	public static String getLocalizedMessage(Locale locale, String messageId, Object [] args)
-	{
-		String locMsg = null;
-
-		try {
-			locMsg = formatMessage(getBundleForLocale(locale, messageId), messageId, args, true);
-			return locMsg;
-		} catch (MissingResourceException mre) {
-			// message does not exist in the requested locale
-			// most likely it does exist in our fake base class _en, so try that.
-		} catch (ShutdownException se) {
-		}
-		locMsg = formatMessage(getBundleForLocale(EN, messageId), messageId, args, false);
-		return locMsg;
-	}
 
 	/**
 	 */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1694383&r1=1694382&r2=1694383&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Thu Aug  6 00:36:20 2015
@@ -165,6 +165,7 @@ import org.apache.derby.impl.sql.compile
 import org.apache.derby.impl.sql.compile.TableName;
 import org.apache.derby.impl.sql.depend.BasicDependencyManager;
 import org.apache.derby.impl.sql.execute.JarUtil;
+import org.apache.derby.shared.common.error.MessageUtils;
 
 /**
  * Standard database implementation of the data dictionary
@@ -11549,7 +11550,7 @@ public final class	DataDictionaryImpl
                     TypeDescriptor.INTEGER,
                     TypeDescriptor.SMALLINT,
 				DataTypeDescriptor.getCatalogType(
-						Types.VARCHAR, Limits.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH),
+						Types.VARCHAR, MessageUtils.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH),
 				DataTypeDescriptor.getCatalogType(Types.CHAR, 8),
                 TypeDescriptor.INTEGER,
                 TypeDescriptor.INTEGER,



Mime
View raw message