[teiid-commits] teiid SVN: r4093 - in branches/7.7.x: client/src/test/java/org/teiid/client/util and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu May 10 10:41:06 EDT 2012


Author: shawkins
Date: 2012-05-10 10:41:05 -0400 (Thu, 10 May 2012)
New Revision: 4093

Modified:
   branches/7.7.x/client/src/main/java/org/teiid/client/util/ExceptionHolder.java
   branches/7.7.x/client/src/test/java/org/teiid/client/util/TestExceptionHolder.java
   branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java
   branches/7.7.x/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml
Log:
TEIID-2007 adding conditional warning fix

Modified: branches/7.7.x/client/src/main/java/org/teiid/client/util/ExceptionHolder.java
===================================================================
--- branches/7.7.x/client/src/main/java/org/teiid/client/util/ExceptionHolder.java	2012-05-10 13:23:52 UTC (rev 4092)
+++ branches/7.7.x/client/src/main/java/org/teiid/client/util/ExceptionHolder.java	2012-05-10 14:41:05 UTC (rev 4093)
@@ -22,14 +22,8 @@
 
 package org.teiid.client.util;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
+import java.io.*;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -72,23 +66,27 @@
 
 		if (this.exception == null) {
 			Throwable t = buildException(classNames, message, stackTrace, code);
-			if (t == null) {
-				if (causeHolder != null) {
-					this.exception = causeHolder.exception;
-				}
+			if (causeHolder != null) {
+				t.initCause(causeHolder.exception);
 			}
-			else {
-				if (causeHolder != null) {
-					t.initCause(causeHolder.exception);
+			this.exception = t;
+			
+			if (this.exception instanceof SQLException) {
+				try {
+					int count = in.readInt();
+					for (int i = 0; i < count; i++) {
+						ExceptionHolder next = (ExceptionHolder)in.readObject();
+						if (next.exception instanceof SQLException) {
+							((SQLException)this.exception).setNextException((SQLException) next.exception);
+						}
+					}
+				} catch (EOFException e) {
+					
+				} catch (OptionalDataException e) {
+					
 				}
-				this.exception = t;
 			}
 		}
-
-		if (this.exception == null) {
-			this.exception = new TeiidRuntimeException(message);
-			this.exception.setStackTrace(stackTrace);
-		}		
 	}
 	
 	@Override
@@ -126,6 +124,22 @@
 		else {
 			out.writeObject(null);
 		}
+		// handle SQLException chains
+		if (exception instanceof SQLException) {
+			SQLException se = (SQLException)exception;
+			SQLException next = se.getNextException();
+			int count = 0;
+			while (next != null) {
+				count++;
+				next = next.getNextException();
+			}
+			out.writeInt(count);
+			next = se.getNextException();
+			while (next != null) {
+				out.writeObject(new ExceptionHolder(next, true));
+				next = next.getNextException();
+			}
+		}
 	}
 	
 	public Throwable getException() {
@@ -133,30 +147,32 @@
 	}
 		
 	private Throwable buildException(List<String> classNames, String message, StackTraceElement[] stackTrace, String code) {
-		if (classNames.isEmpty()) {
-			return null;
+		String originalClass = Exception.class.getName();
+		
+		if (!classNames.isEmpty()) {
+			originalClass = classNames.get(0);
 		}
 		
-		String originalClass = classNames.get(0);
-		
 		List<String> args = Arrays.asList(CorePlugin.Util.getString("ExceptionHolder.converted_exception", message, originalClass)); //$NON-NLS-1$
 		
 		Throwable result = null;
 		for (String className : classNames) {
 			try {
 				result = (Throwable)ReflectionHelper.create(className, args, ExceptionHolder.class.getClassLoader());
-				result.setStackTrace(stackTrace);
 				break;
 			} catch (TeiidException e1) {
 				//
 			}
 		}
 		
-		if (result instanceof TeiidException) {
+		if (result == null) {
+			result = new TeiidRuntimeException(args.get(0));
+		} else if (result instanceof TeiidException) {
 			((TeiidException)result).setCode(code);
 			((TeiidException)result).setOriginalType(classNames.get(0));
 		}
 		
+		result.setStackTrace(stackTrace);
 		return result;
 	}
 	

Modified: branches/7.7.x/client/src/test/java/org/teiid/client/util/TestExceptionHolder.java
===================================================================
--- branches/7.7.x/client/src/test/java/org/teiid/client/util/TestExceptionHolder.java	2012-05-10 13:23:52 UTC (rev 4092)
+++ branches/7.7.x/client/src/test/java/org/teiid/client/util/TestExceptionHolder.java	2012-05-10 14:41:05 UTC (rev 4093)
@@ -1,3 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
 package org.teiid.client.util;
 
 import static org.junit.Assert.*;
@@ -18,7 +40,7 @@
 import org.teiid.core.util.ReflectionHelper;
 import org.teiid.core.util.UnitTestUtil;
 
-
+ at SuppressWarnings("nls")
 public class TestExceptionHolder {
 	
 	@SuppressWarnings("all")
@@ -72,12 +94,43 @@
         assertTrue(e instanceof BadException2);
         assertEquals("Remote org.teiid.client.util.TestExceptionHolder$BadException2: I have foreign exception embedded in me", e.getMessage()); //$NON-NLS-1$
         
-        // now unknown exception is not found, so promote known SQL exception up
         e = e.getCause();
+        assertTrue(e instanceof TeiidRuntimeException);
+        
+        e = e.getCause();
         assertTrue(e instanceof SQLException);
+        
         assertEquals("Remote java.sql.SQLException: something bad happended", e.getMessage()); //$NON-NLS-1$
-	}	
+	}
 	
+	@Test public void testSQLExceptionChain() throws Exception {
+		ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
+		Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); //$NON-NLS-1$
+		SQLException se = new SQLException("something bad happended");
+		se.initCause(obj); //$NON-NLS-1$
+		SQLException se1 = new SQLException("something else bad happended");
+		se1.initCause(obj); //$NON-NLS-1$
+		se.setNextException(se1);
+		
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(new ExceptionHolder(se, false)); //$NON-NLS-1$
+        oos.flush();
+        
+        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
+        ExceptionHolder holder = (ExceptionHolder)ois.readObject();
+        Throwable e = holder.getException();
+        assertTrue(e instanceof SQLException);
+        assertEquals("Remote java.sql.SQLException: something bad happended", e.getMessage()); //$NON-NLS-1$
+        
+        assertTrue(e.getCause() instanceof TeiidRuntimeException);
+        
+        e = ((SQLException)e).getNextException();
+        assertTrue(e instanceof SQLException);
+        
+        assertEquals("Remote java.sql.SQLException: something else bad happended", e.getMessage()); //$NON-NLS-1$
+	}
+	
 	@Test public void testDeserializationUnknownChildException2() throws Exception {
 		ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
 		ArrayList<String> args = new ArrayList<String>();
@@ -93,7 +146,7 @@
         ExceptionHolder holder = (ExceptionHolder)ois.readObject();
         Throwable e = holder.getException();
         assertTrue(e instanceof TeiidRuntimeException);
-        assertEquals("Unknown Exception", e.getMessage()); //$NON-NLS-1$
+        assertEquals("Remote test.UnknownException: Unknown Exception", e.getMessage()); //$NON-NLS-1$
 	}	
 	
 	private static class NotSerializable {

Modified: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java	2012-05-10 13:23:52 UTC (rev 4092)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCBaseExecution.java	2012-05-10 14:41:05 UTC (rev 4093)
@@ -30,6 +30,7 @@
 import java.sql.Statement;
 import java.util.List;
 
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.language.Command;
 import org.teiid.language.Literal;
 import org.teiid.logging.LogConstants;
@@ -49,7 +50,8 @@
     // Fields
     // ===========================================================================================================================
 
-    // Passed to constructor
+    private static final boolean ADD_EACH_WARNING = PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.addEachJDBCWarning", true); //$NON-NLS-1$
+	// Passed to constructor
     protected Connection connection;
     protected ExecutionContext context;
     protected JDBCExecutionFactory executionFactory;
@@ -190,15 +192,23 @@
     
     public void addStatementWarnings() throws SQLException {
     	SQLWarning warning = this.statement.getWarnings();
-    	while (warning != null) {
-    		SQLWarning toAdd = warning;
-    		warning = toAdd.getNextWarning();
-    		toAdd.setNextException(null);
-    		if (LogManager.isMessageToBeRecorded(LogConstants.CTX_CONNECTOR, MessageLevel.DETAIL)) {
-    			LogManager.logDetail(LogConstants.CTX_CONNECTOR, context.getRequestIdentifier() + " Warning: ", warning); //$NON-NLS-1$
-    		}
-    		context.addWarning(toAdd);
-    	}
+		if (ADD_EACH_WARNING) {
+			while (warning != null) {
+	    		if (LogManager.isMessageToBeRecorded(LogConstants.CTX_CONNECTOR, MessageLevel.DETAIL)) {
+	    			LogManager.logDetail(LogConstants.CTX_CONNECTOR, context.getRequestIdentifier() + " Warning: ", warning); //$NON-NLS-1$
+	    		}
+	    		context.addWarning(warning);
+	    		warning = warning.getNextWarning();
+	    	}
+		} else if (warning != null) {
+			context.addWarning(warning);
+			if (LogManager.isMessageToBeRecorded(LogConstants.CTX_CONNECTOR, MessageLevel.DETAIL)) {
+		    	while (warning != null) {
+					LogManager.logDetail(LogConstants.CTX_CONNECTOR, context.getRequestIdentifier() + " Warning: ", warning); //$NON-NLS-1$
+		    		warning = warning.getNextWarning();
+		    	}
+			}
+		}
     	this.statement.clearWarnings();
     }
 }

Modified: branches/7.7.x/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml
===================================================================
--- branches/7.7.x/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml	2012-05-10 13:23:52 UTC (rev 4092)
+++ branches/7.7.x/documentation/admin-guide/src/main/docbook/en-US/content/appendix-c.xml	2012-05-10 14:41:05 UTC (rev 4093)
@@ -45,5 +45,11 @@
 			Set to true to compare strings as if PAD SPACE collation is being used, that is strings are effectively right padded to the same length for comparison.  If this property is set, it is not necessary to use the trimStrings translator option.
 			</para>
 		</listitem>
+		<listitem>
+			<para><emphasis>org.teiid.addEachJDBCWarning</emphasis> - defaults to true.  
+			Set to false to add only the Warning root.  This should be used if you are using a socket connection and your JDBC sources produce numerous warnings.  See also issue <ulink url="https://issues.jboss.org/browse/TEIID-2007">TEIID-2007</ulink>.
+			</para>
+			<note><para>For Teiid 8.x this property no longer exists and the default behavior is to add only the Warning root.</para></note>
+		</listitem>
 	</itemizedlist>
 </appendix>
\ No newline at end of file



More information about the teiid-commits mailing list