Author: shawkins
Date: 2011-06-08 14:28:42 -0400 (Wed, 08 Jun 2011)
New Revision: 3236
Modified:
branches/7.4.x/client/src/main/java/org/teiid/jdbc/SQLStates.java
branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestSQLException.java
branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidException.java
branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java
branches/7.4.x/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
Log:
TEIID-97 adding state for timeout/cancel with various exception clean ups.
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/SQLStates.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/SQLStates.java 2011-06-08 18:23:36
UTC (rev 3235)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/SQLStates.java 2011-06-08 18:28:42
UTC (rev 3236)
@@ -82,6 +82,8 @@
* conforms to the subclass DataDirect uses for SocketExceptions.
*/
public static final String CONNECTION_EXCEPTION_STALE_CONNECTION = "08S01";
//$NON-NLS-1$
+
+ public static final String QUERY_CANCELED = "57014"; //$NON-NLS-1$
// Class 28 - invalid authorization specification
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java 2011-06-08
18:23:36 UTC (rev 3235)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -32,6 +32,7 @@
import org.teiid.client.ProcedureErrorInstructionException;
import org.teiid.client.security.InvalidSessionException;
import org.teiid.client.security.LogonException;
+import org.teiid.client.util.ExceptionUtil;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
@@ -102,10 +103,13 @@
return new TeiidSQLException((SQLException) exception, message, true);
}
String sqlState = SQLStates.DEFAULT;
-
- exception = findRootException(exception);
-
- sqlState = determineSQLState(exception, sqlState);
+ TeiidException te = ExceptionUtil.getExceptionOfType(exception, TeiidException.class);
+ if (te != null && te.getCode() != null) {
+ sqlState = te.getCode();
+ } else {
+ exception = findRootException(exception);
+ sqlState = determineSQLState(exception, sqlState);
+ }
return new TeiidSQLException(origException, message, sqlState);
}
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestSQLException.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestSQLException.java 2011-06-08
18:23:36 UTC (rev 3235)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestSQLException.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -22,6 +22,8 @@
package org.teiid.jdbc;
+import static org.junit.Assert.*;
+
import java.io.IOException;
import java.net.ConnectException;
import java.net.MalformedURLException;
@@ -31,23 +33,21 @@
import java.net.UnknownHostException;
import java.sql.SQLException;
-import junit.framework.TestCase;
-
+import org.junit.Test;
import org.teiid.client.ProcedureErrorInstructionException;
-import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidException;
-import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.net.CommunicationException;
import org.teiid.net.ConnectionException;
-public class TestSQLException extends TestCase {
+public class TestSQLException {
/*
* Test method for 'com.metamatrix.jdbc.MMSQLException.MMSQLException()'
*/
- public void testMMSQLException() {
+ @Test public void testMMSQLException() {
TeiidSQLException e = new TeiidSQLException();
String sqlState = e.getSQLState();
Throwable cause = e.getCause();
@@ -82,7 +82,7 @@
* Tests various simple exceptions to see if the expected SQLState is
* returend.
*/
- public void testCreateThrowable_01() {
+ @Test public void testCreateThrowable_01() {
testCreateThrowable(new CommunicationException(
"A test MM Communication Exception"), //$NON-NLS-1$
SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
@@ -133,7 +133,7 @@
* Tests various nested exceptions to see if the expected SQLState is
* returend.
*/
- public void testCreateThrowable_02() {
+ @Test public void testCreateThrowable_02() {
testCreateThrowable(
new CommunicationException(new ConnectException(
"A test java.net.ConnectException"), //$NON-NLS-1$
@@ -150,7 +150,7 @@
SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
}
- public void testCreateThrowable3() {
+ @Test public void testCreateThrowable3() {
TeiidSQLException e = testCreateThrowable(
new TeiidException(
new TeiidRuntimeException(
@@ -180,31 +180,15 @@
Throwable nestedException = e.getCause();
SQLException nextException = e.getNextException();
- assertTrue("Expected MMSQLException.getSQLState() to return \""
//$NON-NLS-1$
- + esqlState + "\" but got \"" + sqlState + "\"
instead.", //$NON-NLS-1$ //$NON-NLS-2$
- sqlState.compareTo(esqlState) == 0);
- assertTrue("Expected MMSQLException.getCause() to return [" //$NON-NLS-1$
- + (ecause != null ? ecause.getClass().getName() : "<null>")
//$NON-NLS-1$
- + "] but got [" //$NON-NLS-1$
- + (cause != null ? cause.getClass().getName() : "<unknown>")
//$NON-NLS-1$
- + "] instead.", cause == ecause); //$NON-NLS-1$
- assertTrue(
- "Expected MMSQLException.getErrorCode() to return [0] but got ["
//$NON-NLS-1$
- + errorCode + "] instead.", errorCode == 0); //$NON-NLS-1$
- assertTrue("Expected MMSQLException.getNestedException() to return ["
//$NON-NLS-1$
- + (ecause != null ? ecause.getClass().getName() : "<null>")
//$NON-NLS-1$
- + "] but got [" //$NON-NLS-1$
- + (nestedException != null ? nestedException.getClass()
- .getName() : "<unknown>") + "] instead.", //$NON-NLS-1$
//$NON-NLS-2$
- nestedException == ecause);
- assertTrue(
- "Expected MMSQLException.getNextException() to return <null> but got a
SQLException with message \"" //$NON-NLS-1$
- + (nextException != null ? nextException.getMessage()
- : "") + "\" instead.", nextException == null);
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(esqlState, sqlState);
+ assertEquals(ecause, cause);
+ assertEquals(0, errorCode);
+ assertEquals(nestedException, ecause);
+ assertNull(nextException);
return e;
}
- public void testCreate() {
+ @Test public void testCreate() {
TeiidSQLException exception = TeiidSQLException.create(new Exception());
assertEquals(exception.getMessage(), Exception.class.getName());
@@ -214,7 +198,7 @@
assertEquals(exception, TeiidSQLException.create(exception));
}
- public void testCreateFromSQLException() {
+ @Test public void testCreateFromSQLException() {
SQLException sqlexception = new SQLException("foo", "21");
//$NON-NLS-1$ //$NON-NLS-2$
SQLException nested = new SQLException("bar"); //$NON-NLS-1$
@@ -230,5 +214,15 @@
assertEquals(exception.getNextException().getMessage(),
sqlexception.getMessage());
assertEquals(exception.getNextException().getNextException().getMessage(),
nested.getMessage());
}
+
+ @Test public void testCodeAsSQLState() {
+ TeiidException sqlexception = new TeiidException("foo",
"21"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ String message = "top level message"; //$NON-NLS-1$
+
+ TeiidSQLException exception = TeiidSQLException.create(sqlexception, message);
+
+ assertEquals(sqlexception.getCode(), exception.getSQLState());
+ }
}
Modified: branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidException.java
===================================================================
--- branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidException.java 2011-06-08
18:23:36 UTC (rev 3235)
+++ branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidException.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -58,7 +58,7 @@
public TeiidException(Throwable e, String message) {
super(message, e);
- setCode(e);
+ setCode(getCode(e));
}
public TeiidException(Throwable e, String errorCode, String message) {
@@ -82,14 +82,15 @@
this.originalType = originalType;
}
- private void setCode(Throwable e) {
+ static String getCode(Throwable e) {
if (e instanceof TeiidException) {
- this.code = (((TeiidException) e).getCode());
+ return (((TeiidException) e).getCode());
} else if (e instanceof TeiidRuntimeException) {
- this.code = ((TeiidRuntimeException) e).getCode();
+ return ((TeiidRuntimeException) e).getCode();
} else if (e instanceof SQLException) {
- this.code = Integer.toString(((SQLException)e).getErrorCode());
+ return ((SQLException)e).getSQLState();
}
+ return null;
}
public String getMessage() {
Modified:
branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java
===================================================================
---
branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java 2011-06-08
18:23:36 UTC (rev 3235)
+++
branches/7.4.x/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -22,10 +22,6 @@
package org.teiid.core;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.sql.SQLException;
-
import org.teiid.core.util.ExceptionUtil;
@@ -40,26 +36,9 @@
public class TeiidRuntimeException extends RuntimeException {
public static final long serialVersionUID = -4035276728007979320L;
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
public static final String CAUSED_BY_STRING =
CorePlugin.Util.getString("RuntimeException.Caused_by"); //$NON-NLS-1$
//############################################################################################################################
- //# Static Methods
#
-
//############################################################################################################################
-
- /**
- * Utility method to get the name of a class, without package information.
- *
- * @param cls The class to get the name of
- * @return The name of the class, without package info
- */
- public static String getClassShortName( Class cls ) {
- if ( cls == null ) return EMPTY_STRING;
- String className = cls.getName();
- return className.substring( className.lastIndexOf('.')+1 );
- }
-
-
//############################################################################################################################
//# Variables
#
//############################################################################################################################
@@ -86,19 +65,6 @@
super(message);
}
- /**
- * Construct an instance with the specified error code and message. If the message
is actually a key, the actual message will
- * be retrieved from a resource bundle using the key, and the specified parameters
will be substituted for placeholders within
- * the message.
- * @param code The error code
- * @param message The error message or a resource bundle key
- */
- public TeiidRuntimeException(final int code, final String message) {
- super(message);
- // The following setCode call should be executed after setting the message
- setCode(code);
- }
-
public TeiidRuntimeException(final String code, final String message) {
super(message);
// The following setCode call should be executed after setting the message
@@ -125,23 +91,10 @@
*/
public TeiidRuntimeException(final Throwable e, final String message) {
super(message, e);
- setCode(e);
+ setCode(TeiidException.getCode(e));
}
/**
- * Construct an instance with the linked exception, error code, and error message
specified. If the message is actually a
- * key, the error message will be retrieved from a resource bundle using the key.
- * @param e The exception to chain to this exception
- * @param code The error code
- * @param message The error message or a resource bundle key
- */
- public TeiidRuntimeException(final Throwable e, final int code, final String message)
{
- super(message, e);
- // The following setCode call should be executed after setting the message
- setCode(code);
- }
-
- /**
* Construct an instance with the linked exception, error code, and error message
specified. If the specified
* exception is a {@link TeiidException} or a MetaMatrixRuntimeException, the code
will
* be set to the exception's code.
@@ -164,6 +117,7 @@
* Get the exception which is linked to this exception.
*
* @return The linked exception
+ * @deprecated use {@link #getCause()} instead
*/
public Throwable getChild() {
return this.getCause();
@@ -175,47 +129,13 @@
* @return The error code
*/
public String getCode() {
- if (code == null) {
- return "0"; //$NON-NLS-1$
- }
return this.code;
}
- public int getIntCode() {
- if (code == null) {
- return 0;
- }
- try {
- return Integer.parseInt(code);
- } catch (NumberFormatException e) {
-
- }
- return 0;
- }
-
- /**
- * Set the error code.
- *
- * @param code The error code
- */
- private void setCode( int code ) {
- this.code = Integer.toString(code);
- }
-
private void setCode( String code ) {
this.code = code;
}
- private void setCode(Throwable e) {
- if (e instanceof TeiidException) {
- this.code = (((TeiidException) e).getCode());
- } else if (e instanceof TeiidRuntimeException) {
- this.code = ((TeiidRuntimeException) e).getCode();
- } else if (e instanceof SQLException) {
- this.code = Integer.toString(((SQLException)e).getErrorCode());
- }
- }
-
/**
* Returns a string representation of this class.
*
@@ -225,12 +145,4 @@
return ExceptionUtil.getLinkedMessages(this);
}
- public void superPrintStackTrace(PrintStream output) {
- super.printStackTrace(output);
- }
-
- public void superPrintStackTrace(PrintWriter output) {
- super.printStackTrace(output);
- }
-
}
Modified:
branches/7.4.x/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
===================================================================
---
branches/7.4.x/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java 2011-06-08
18:23:36 UTC (rev 3235)
+++
branches/7.4.x/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -63,16 +63,16 @@
public void testMetaMatrixRuntimeExceptionWithNullThrowable() {
final TeiidRuntimeException err = new TeiidRuntimeException((Throwable)null);
- assertNull(err.getChild());
- assertEquals("0", err.getCode()); //$NON-NLS-1$
+ assertNull(err.getCause());
+ assertNull(err.getCode());
assertNull(err.getMessage());
}
public void testMetaMatrixRuntimeExceptionWithMessage() {
final TeiidRuntimeException err = new TeiidRuntimeException("Test");
//$NON-NLS-1$
- assertNull(err.getChild());
- assertEquals("0", err.getCode()); //$NON-NLS-1$
+ assertNull(err.getCause());
+ assertNull(err.getCode());
assertEquals("Test", err.getMessage()); //$NON-NLS-1$
}
@@ -80,7 +80,7 @@
public void testMetaMatrixRuntimeExceptionWithCodeAndMessage() {
final String code = "1234"; //$NON-NLS-1$
final TeiidRuntimeException err = new TeiidRuntimeException(code,
"Test"); //$NON-NLS-1$
- assertNull(err.getChild());
+ assertNull(err.getCause());
assertEquals(code, err.getCode());
assertEquals("Test", err.getMessage()); //$NON-NLS-1$
@@ -90,7 +90,7 @@
final String code = "1234"; //$NON-NLS-1$
final TeiidRuntimeException child = new TeiidRuntimeException(code,
"Child"); //$NON-NLS-1$
final TeiidRuntimeException err = new TeiidRuntimeException(child,
"Test"); //$NON-NLS-1$
- assertSame(child, err.getChild());
+ assertSame(child, err.getCause());
assertEquals(code, err.getCode());
assertEquals("Test", err.getMessage()); //$NON-NLS-1$
@@ -100,7 +100,7 @@
final String code = "1234"; //$NON-NLS-1$
final TeiidRuntimeException child = new TeiidRuntimeException(code,
"Child"); //$NON-NLS-1$
final TeiidRuntimeException err = new TeiidRuntimeException(child,
"Code", "Test"); //$NON-NLS-1$ //$NON-NLS-2$
- assertSame(child, err.getChild());
+ assertSame(child, err.getCause());
assertEquals("Code", err.getCode()); //$NON-NLS-1$
assertEquals("Test", err.getMessage()); //$NON-NLS-1$
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-06-08
18:23:36 UTC (rev 3235)
+++
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -57,8 +57,6 @@
import org.teiid.dqp.message.AtomicRequestMessage;
import org.teiid.dqp.message.AtomicResultsMessage;
import org.teiid.events.EventDistributor;
-import org.teiid.logging.LogConstants;
-import org.teiid.logging.LogManager;
import org.teiid.metadata.Table;
import org.teiid.query.function.source.XMLSystemFunctions;
import org.teiid.query.processor.relational.RelationalNodeUtil;
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-06-08
18:23:36 UTC (rev 3235)
+++
branches/7.4.x/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -58,6 +58,7 @@
import org.teiid.dqp.service.TransactionContext;
import org.teiid.dqp.service.TransactionService;
import org.teiid.dqp.service.TransactionContext.Scope;
+import org.teiid.jdbc.SQLStates;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
@@ -223,7 +224,7 @@
state = ProcessingState.PROCESSING;
processNew();
if (isCanceled) {
- this.processingException = new
TeiidProcessingException(QueryPlugin.Util.getString("QueryProcessor.request_cancelled",
this.requestID)); //$NON-NLS-1$
+ this.processingException = new
TeiidProcessingException(SQLStates.QUERY_CANCELED,
QueryPlugin.Util.getString("QueryProcessor.request_cancelled", this.requestID));
//$NON-NLS-1$
state = ProcessingState.CLOSE;
}
}
@@ -626,10 +627,24 @@
}
LogManager.logDetail(LogConstants.CTX_DQP, processingException, "Sending error to
client", requestID); //$NON-NLS-1$
ResultsMessage response = new ResultsMessage(requestMsg);
- response.setException(processingException);
+ Throwable exception = this.processingException;
+ if (isCanceled) {
+ exception = addCancelCode(exception);
+ }
+ response.setException(exception);
setAnalysisRecords(response);
receiver.receiveResults(response);
}
+
+ private Throwable addCancelCode(Throwable exception) {
+ if (exception instanceof TeiidException) {
+ TeiidException te = (TeiidException)exception;
+ if (SQLStates.QUERY_CANCELED.equals(te.getCode())) {
+ return exception;
+ }
+ }
+ return new TeiidProcessingException(exception, SQLStates.QUERY_CANCELED,
exception.getMessage());
+ }
@Override
protected boolean shouldPause() {
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java 2011-06-08
18:23:36 UTC (rev 3235)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/QueryProcessor.java 2011-06-08
18:28:42 UTC (rev 3236)
@@ -34,6 +34,7 @@
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.util.Assertion;
+import org.teiid.jdbc.SQLStates;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
@@ -130,7 +131,7 @@
while(currentTime < context.getTimeSliceEnd() || context.isNonBlocking()) {
if (requestCanceled) {
- throw new
TeiidProcessingException(QueryPlugin.Util.getString("QueryProcessor.request_cancelled",
getProcessID())); //$NON-NLS-1$
+ throw new TeiidProcessingException(SQLStates.QUERY_CANCELED,
QueryPlugin.Util.getString("QueryProcessor.request_cancelled", getProcessID()));
//$NON-NLS-1$
}
if (currentTime > context.getTimeoutEnd()) {
throw new TeiidProcessingException("Query timed out");
//$NON-NLS-1$