List:Commits« Previous MessageNext Message »
From:mmatthews Date:December 12 2007 7:23pm
Subject:Connector/J commit: r6694 - branches/branch_5_1/src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
   branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties
Log:
Use nested exceptions for causation relationships, externalized some error messages.

Modified: branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java	2007-12-05 19:18:51 UTC (rev 6693)
+++ branches/branch_5_1/src/com/mysql/jdbc/ConnectionImpl.java	2007-12-12 19:23:30 UTC (rev 6694)
@@ -760,15 +760,12 @@
 				mesg.append("Unable to connect to database.");
 			}
 
-			mesg.append("Underlying exception: \n\n");
-			mesg.append(ex.getClass().getName());
-
-			if (!getParanoid()) {
-				mesg.append(Util.stackTraceToString(ex));
-			}
-
-			throw SQLError.createSQLException(mesg.toString(),
+			SQLException sqlEx = SQLError.createSQLException(mesg.toString(),
 					SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE);
+			
+			sqlEx.initCause(ex);
+			
+			throw sqlEx;
 		}
 	}
 
@@ -2113,14 +2110,12 @@
 				
 				if (!connectionGood) {
 					// We've really failed!
-					throw SQLError.createSQLException(
-							"Could not create connection to database server due to underlying exception: '"
-									+ connectionNotEstablishedBecause
-									+ "'."
-									+ (getParanoid() ? ""
-											: Util
-													.stackTraceToString(connectionNotEstablishedBecause)),
+					SQLException chainedEx = SQLError.createSQLException(
+							Messages.getString("Connection.UnableToConnect"),
 							SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE);
+					chainedEx.initCause(connectionNotEstablishedBecause);
+					
+					throw chainedEx;
 				}
 			} else {
 				double timeout = getInitialTimeout();
@@ -2253,16 +2248,13 @@
 
 				if (!connectionGood) {
 					// We've really failed!
-					throw SQLError.createSQLException(
-							"Server connection failure during transaction. Due to underlying exception: '"
-									+ connectionException
-									+ "'."
-									+ (getParanoid() ? ""
-											: Util
-													.stackTraceToString(connectionException))
-									+ "\nAttempted reconnect "
-									+ getMaxReconnects() + " times. Giving up.",
+					SQLException chainedEx = SQLError.createSQLException(
+							Messages.getString("Connection.UnableToConnectWithRetries",
+									new Object[] {new Integer(getMaxReconnects())}),
 							SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE);
+					chainedEx.initCause(connectionException);
+					
+					throw chainedEx;
 				}
 			}
 
@@ -2581,19 +2573,12 @@
 					cleanup(ex);
 				}
 
-				String exceptionType = ex.getClass().getName();
-				String exceptionMessage = ex.getMessage();
-
-				if (!getParanoid()) {
-					exceptionMessage += "\n\nNested Stack Trace:\n";
-					exceptionMessage += Util.stackTraceToString(ex);
-				}
-
-				throw new java.sql.SQLException(
-						"Error during query: Unexpected Exception: "
-								+ exceptionType + " message given: "
-								+ exceptionMessage,
+				SQLException sqlEx = SQLError.createSQLException(
+						Messages.getString("Connection.UnexpectedException"),
 						SQLError.SQL_STATE_GENERAL_ERROR);
+				sqlEx.initCause(ex);
+				
+				throw sqlEx;
 			} finally {
 				if (getMaintainTimeStats()) {
 					this.lastQueryFinishedTime = System.currentTimeMillis();
@@ -5264,8 +5249,13 @@
 		try {
 			this.io.sendCommand(MysqlDefs.SHUTDOWN, null, null, false, null);
 		} catch (Exception ex) {
-			throw SQLError.createSQLException("Unhandled exception '" + ex.toString()
-					+ "'", SQLError.SQL_STATE_GENERAL_ERROR);
+			SQLException sqlEx = SQLError.createSQLException(
+					Messages.getString("Connection.UnhandledExceptionDuringShutdown"),
+					SQLError.SQL_STATE_GENERAL_ERROR);
+			
+			sqlEx.initCause(ex);
+			
+			throw sqlEx;
 		}
 	}
 

Modified: branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties
===================================================================
--- branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties	2007-12-05 19:18:51 UTC (rev 6693)
+++ branches/branch_5_1/src/com/mysql/jdbc/LocalizedErrorMessages.properties	2007-12-12 19:23:30 UTC (rev 6694)
@@ -422,6 +422,12 @@
 InvalidLoadBalanceStrategy=Invalid load balancing strategy '{0}'.
 Connection.Connection.BadValueInServerVariables=Invalid value '{1}' for server variable named '{0}', falling back to sane default of '{2}'.
 
+Connection.UnableToConnect=Could not create connection to database server.
+Connection.UnableToConnectWithRetries=Could not create connection to database server. \
+Attempted reconnect {0} times. Giving up.
+Connection.UnexpectedException=Unexpected exception encountered during query.
+Connection.UnhandledExceptionDuringShutdown=Unexpected exception during server shutdown.
+
 #
 # ConnectionProperty Categories
 #

Thread
Connector/J commit: r6694 - branches/branch_5_1/src/com/mysql/jdbcmmatthews12 Dec