db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r803948 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc: EmbedConnection.java Util.java
Date Thu, 13 Aug 2009 17:05:53 GMT
Author: kmarsden
Date: Thu Aug 13 17:05:52 2009
New Revision: 803948

URL: http://svn.apache.org/viewvc?rev=803948&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.



Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=803948&r1=803947&r2=803948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Thu Aug
13 17:05:52 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/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java?rev=803948&r1=803947&r2=803948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java Thu Aug 13 17:05:52
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