db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r804059 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java java/engine/org/apache/derby/impl/jdbc/Util.java
Date Thu, 13 Aug 2009 23:25:18 GMT
Author: kmarsden
Date: Thu Aug 13 23:25:17 2009
New Revision: 804059

URL: http://svn.apache.org/viewvc?rev=804059&view=rev
Log:
DERBY-1191 (partial) Some SQLExceptions, for example those generated from BrokeredStatements,
do not print to derby.log even when derby.stream.error.logSeverityLevel=0

Here is a patch that takes the approach of adding a public static void logAndThrowSQLException(SQLException
se) method and then calling that instead of just throwing the exception.

The initial patch only uses the method for EmbedConnection.checkForTransactionInProgress()
which is the most important exception to log after the fix for DERBY-3319.
Merged from trunk with:

svn merge -r 803947:803948   https://svn.apache.org/repos/asf/db/derby/code/trunk

Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/Util.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 13 23:25:17 2009
@@ -1 +1 @@
-/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794955,795166,796020,796027,797147,800523
+/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794955,795166,796020,796027,797147,800523,803948

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=804059&r1=804058&r2=804059&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
Thu Aug 13 23:25:17 2009
@@ -1803,7 +1803,10 @@
     public void checkForTransactionInProgress() throws SQLException {
         if (!isClosed() && (rootConnection == this) &&
                 !autoCommit && !transactionIsIdle()) {
-            throw newSQLException(SQLState.CANNOT_CLOSE_ACTIVE_CONNECTION);
+            // DERBY-1191 partial fix. Make sure this  exception is logged with
+            // derby.stream.error.logSeverityLevel=0 so users can see changes needed
+            // after the DERBY-3319 fix.
+            Util.logAndThrowSQLException(newSQLException(SQLState.CANNOT_CLOSE_ACTIVE_CONNECTION));
         }
     }
 

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/Util.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/Util.java?rev=804059&r1=804058&r2=804059&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/Util.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/jdbc/Util.java Thu Aug 13
23:25:17 2009
@@ -21,15 +21,20 @@
 
 package org.apache.derby.impl.jdbc;
 
+import org.apache.derby.iapi.error.ErrorStringBuilder;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.i18n.MessageService;
 
+import org.apache.derby.iapi.services.property.PropertyUtil;
 import org.apache.derby.iapi.services.sanity.SanityManager;
+import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
+import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.types.TypeId;
 
 import org.apache.derby.iapi.error.ExceptionSeverity;
 
+import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.reference.MessageId;
 import org.apache.derby.iapi.reference.JDBC40Translation;
@@ -68,6 +73,9 @@
     private static SQLExceptionFactory exceptionFactory = 
                                     new SQLExceptionFactory ();
 
+
+	private static int logSeverityLevel = PropertyUtil.getSystemInt(Property.LOG_SEVERITY_LEVEL,
+		SanityManager.DEBUG ? 0 : ExceptionSeverity.SESSION_SEVERITY);
 	/*
 	** Methods of Throwable
 	*/
@@ -75,6 +83,53 @@
 	// class implementation
 
     /**
+     * Log SQLException to the error log if the severity exceeds the 
+     * logSeverityLevel  and then throw it.  This method can be used for 
+     * logging JDBC exceptions to derby.log DERBY-1191.
+     * 
+     * @param se SQLException to log and throw
+     * @throws SQLException
+     */
+    public static void logAndThrowSQLException(SQLException se) throws SQLException {
+    	if (se.getErrorCode() >= logSeverityLevel){
+    	logSQLException(se);
+    	}
+    	throw se;
+    }
+    
+	/**
+	 * Log an SQLException to the error log or to the console if there is no
+	 * error log available.
+	 * This method could perhaps be optimized to have a static shared
+	 * ErrorStringBuilder and synchronize the method, but this works for now.
+	 * 
+	 * @param se SQLException to log
+	 */
+	private static void logSQLException(SQLException se) {
+    	if (se == null)
+    		return;
+    	String message = se.getMessage();
+    	String sqlstate = se.getSQLState();
+    	if ((sqlstate != null) && (sqlstate.equals(SQLState.LOGIN_FAILED)) &&

+    			(message != null) && (message.equals("Connection refused : java.lang.OutOfMemoryError")))
			
+    		return;
+
+    	HeaderPrintWriter errorStream = Monitor.getStream();
+    	if (errorStream == null) {
+    		se.printStackTrace();
+    		return;
+    	}
+    	ErrorStringBuilder	errorStringBuilder = new ErrorStringBuilder(errorStream.getHeader());
+    	errorStringBuilder.append("\nERROR " +  se.getSQLState() + ": "  + se.getMessage() +
"\n");
+    	errorStringBuilder.stackTrace(se);
+    	errorStream.print(errorStringBuilder.get().toString());
+    	errorStream.flush();
+    	errorStringBuilder.reset();
+
+    }
+
+	
+	/**
      * This looks up the message and sqlstate values and calls
      * the SQLExceptionFactory method to generate
      * the appropriate exception off of them.



Mime
View raw message