static String getCode(Throwable e) { if (e instanceof TeiidException) { return (((TeiidException) e).getCode()); } else if (e instanceof TeiidRuntimeException) { return ((TeiidRuntimeException) e).getCode(); } else if (e instanceof SQLException) { return ((SQLException)e).getSQLState(); } return null; }
/** * Construct an instance with a linked exception specified. If the exception is a {@link TeiidException} or a * TeoodRuntimeException, then the code will be set to the exception's code. * @param e An exception to chain to this exception */ public TeiidRuntimeException(final Throwable e) { super(( e instanceof java.lang.reflect.InvocationTargetException ) ? ((java.lang.reflect.InvocationTargetException)e).getTargetException().getMessage() : (e == null ? null : e.getMessage()), e); setCode(TeiidException.getCode(e)); }
static String getCode(Throwable e) { if (e instanceof TeiidException) { return (((TeiidException) e).getCode()); } else if (e instanceof TeiidRuntimeException) { return ((TeiidRuntimeException) e).getCode(); } else if (e instanceof SQLException) { return ((SQLException)e).getSQLState(); } return null; }
/** * Construct an instance with a linked exception specified. If the exception is a {@link TeiidException} or a * TeoodRuntimeException, then the code will be set to the exception's code. * @param e An exception to chain to this exception */ public TeiidRuntimeException(final Throwable e) { super(( e instanceof java.lang.reflect.InvocationTargetException ) ? ((java.lang.reflect.InvocationTargetException)e).getTargetException().getMessage() : (e == null ? null : e.getMessage()), e); setCode(TeiidException.getCode(e)); }
public TeiidException(Throwable e, String message) { super(message, e); setCode(getCode(e)); }
public TeiidException(Throwable e, String message) { super(message, e); setCode(getCode(e)); }
private Throwable addCancelCode(Throwable exception) { if (exception instanceof TeiidException) { TeiidException te = (TeiidException)exception; if (SQLStates.QUERY_CANCELED.equals(te.getCode())) { return exception; } } TeiidProcessingException tpe = new TeiidProcessingException(exception); tpe.setCode(SQLStates.QUERY_CANCELED); return tpe; }
} else if (exception instanceof TeiidProcessingException) { sqlState = SQLStates.USAGE_ERROR; if (SQLStates.QUERY_CANCELED.equals(((TeiidException) exception).getCode())) { sqlState = SQLStates.QUERY_CANCELED;
private Throwable addCancelCode(Throwable exception) { String reason = null; synchronized (this) { reason = this.cancelReason; } if (exception instanceof TeiidException) { TeiidException te = (TeiidException)exception; if (SQLStates.QUERY_CANCELED.equals(te.getCode()) && EquivalenceUtil.areEqual(reason, te.getMessage())) { return exception; } } TeiidProcessingException tpe = new TeiidProcessingException(reason); tpe.initCause(exception); tpe.setCode(SQLStates.QUERY_CANCELED); return tpe; }
private Throwable addCancelCode(Throwable exception) { String reason = null; synchronized (this) { reason = this.cancelReason; } if (exception instanceof TeiidException) { TeiidException te = (TeiidException)exception; if (SQLStates.QUERY_CANCELED.equals(te.getCode()) && EquivalenceUtil.areEqual(reason, te.getMessage())) { return exception; } } TeiidProcessingException tpe = new TeiidProcessingException(reason); tpe.initCause(exception); tpe.setCode(SQLStates.QUERY_CANCELED); return tpe; }
/** * Used to wrap warnings/exceptions into SQLWarning. * The chain of warnings is translated into a chain of SQLWarnings. * @param reason String object which is the description of the warning. * @param ex Throwable object which needs to be wrapped. */ static SQLWarning createWarning(Throwable ex) { String sourceName = null; String modelName = null; if(ex instanceof SourceWarning) { SourceWarning exception = (SourceWarning)ex; if (exception.isPartialResultsError()) { PartialResultsWarning warning = new PartialResultsWarning(JDBCPlugin.Util.getString("WarningUtil.Failures_occurred")); //$NON-NLS-1$ warning.addConnectorFailure(exception.getConnectorBindingName(), TeiidSQLException.create(exception)); return warning; } ex = exception.getCause(); sourceName = exception.getConnectorBindingName(); modelName = exception.getModelName(); } String code = null; if (ex instanceof TeiidException) { code = ((TeiidException)ex).getCode(); } return new TeiidSQLWarning(ex.getMessage(), code, ex, sourceName, modelName); }
/** * Used to wrap warnings/exceptions into SQLWarning. * The chain of warnings is translated into a chain of SQLWarnings. * @param reason String object which is the description of the warning. * @param ex Throwable object which needs to be wrapped. */ static SQLWarning createWarning(Throwable ex) { String sourceName = null; String modelName = null; if(ex instanceof SourceWarning) { SourceWarning exception = (SourceWarning)ex; if (exception.isPartialResultsError()) { PartialResultsWarning warning = new PartialResultsWarning(JDBCPlugin.Util.getString("WarningUtil.Failures_occurred")); //$NON-NLS-1$ warning.addConnectorFailure(exception.getConnectorBindingName(), TeiidSQLException.create(exception)); return warning; } ex = exception.getCause(); sourceName = exception.getConnectorBindingName(); modelName = exception.getModelName(); } String code = null; if (ex instanceof TeiidException) { code = ((TeiidException)ex).getCode(); } return new TeiidSQLWarning(ex.getMessage(), code, ex, sourceName, modelName); }
@Test public void testMetaMatrixExceptionWithMessage() { final TeiidException err = new TeiidException("Test"); //$NON-NLS-1$ assertNull(err.getCode()); assertEquals("Test", err.getMessage()); //$NON-NLS-1$ } public static enum Event implements BundleUtil.Event {
@Test public void testMetaMatrixExceptionWithCodeAndMessage() { final TeiidException err = new TeiidException(Event.Code, "Test"); //$NON-NLS-1$ assertEquals("Code", err.getCode()); //$NON-NLS-1$ assertEquals("Code Test", err.getMessage()); //$NON-NLS-1$ }
@Test public void testMetaMatrixExceptionWithNullThrowable() { final TeiidException err = new TeiidException((Throwable)null); assertNull(err.getCode()); assertNull(err.getMessage()); }
@Test public void testMetaMatrixExceptionWithExceptionAndCodeAndMessage() { final TeiidException child = new TeiidException(Event.propertyValuePhrase, "Child"); //$NON-NLS-1$ final TeiidException err = new TeiidException(Event.Code,child, "Test"); //$NON-NLS-1$ assertEquals("Code", err.getCode()); //$NON-NLS-1$ assertEquals("Code Test", err.getMessage()); //$NON-NLS-1$ } }
@Test public void testMetaMatrixExceptionWithExceptionAndMessage() { final TeiidException child = new TeiidException(Event.propertyValuePhrase, "Child"); //$NON-NLS-1$ final TeiidException err = new TeiidException(child, "Test"); //$NON-NLS-1$ assertEquals("propertyValuePhrase", err.getCode()); //$NON-NLS-1$ assertEquals("propertyValuePhrase Test", err.getMessage()); //$NON-NLS-1$ }
@Test public void testCodeAsVendorCode() { TeiidException sqlexception = new TeiidException(Event.TEIID21, "foo"); //$NON-NLS-1$ String message = "top level message"; //$NON-NLS-1$ TeiidSQLException exception = TeiidSQLException.create(sqlexception, message); assertEquals(sqlexception.getCode(), exception.getTeiidCode()); assertEquals(21, exception.getErrorCode()); }