private XAException handleError(Exception e,String logMsg) { logger.log(Level.FINE, logMsg, e); if(e instanceof TeiidSQLException){ Throwable ex = ((TeiidSQLException)e).getCause(); if(ex instanceof XAException){ return (XAException)ex; } if (ex instanceof XATransactionException) { return ((XATransactionException)ex).getXAException(); } } return new XAException(XAException.XAER_RMERR); }
private XAException handleError(Exception e,String logMsg) { logger.log(Level.FINE, logMsg, e); if(e instanceof TeiidSQLException){ Throwable ex = ((TeiidSQLException)e).getCause(); if(ex instanceof XAException){ return (XAException)ex; } if (ex instanceof XATransactionException) { return ((XATransactionException)ex).getXAException(); } } return new XAException(XAException.XAER_RMERR); }
@Test public void testCreateThrowable3() { TeiidSQLException e = testCreateThrowable( new TeiidException( new SocketTimeoutException( "A test MM Invalid Session Exception"), //$NON-NLS-1$ "Test MetaMatrixRuntimeException with a InvalidSessionException in it"), //$NON-NLS-1$ SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION); //test to ensure that wrapping mmsqlexceptions works TeiidSQLException e1 = TeiidSQLException.create(e, "new message"); //$NON-NLS-1$ assertEquals("new message", e1.getMessage()); //$NON-NLS-1$ testCreateThrowable(((TeiidSQLException)e1.getCause()).getCause(), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION); }
@Test public void testCreateFromSQLException() { SQLException sqlexception = new SQLException("foo", "21"); //$NON-NLS-1$ //$NON-NLS-2$ SQLException nested = new SQLException("bar"); //$NON-NLS-1$ sqlexception.setNextException(nested); String message = "top level message"; //$NON-NLS-1$ TeiidSQLException exception = TeiidSQLException.create(sqlexception, message); exception.printStackTrace(); assertEquals(sqlexception, exception.getCause()); assertEquals(exception.getMessage(), message); assertEquals(exception.getSQLState(), sqlexception.getSQLState()); assertEquals(exception.getNextException().getMessage(), nested.getMessage()); } public static enum Event implements BundleUtil.Event {
@Test public void testMMSQLException() { TeiidSQLException e = new TeiidSQLException(); String sqlState = e.getSQLState(); Throwable cause = e.getCause(); int errorCode = e.getErrorCode(); Throwable nestedException = e.getCause(); SQLException nextException = e.getNextException(); assertTrue( "Expected MMSQLException.getSQLState() to return <null> but got \"" //$NON-NLS-1$ + sqlState + "\" instead.", sqlState == null); //$NON-NLS-1$ assertTrue( "Expected MMSQLException.getCause() to return <null> but got [" //$NON-NLS-1$ + (cause != null ? cause.getClass().getName() : "<unknown>") + "] instead.", cause == null); //$NON-NLS-1$ //$NON-NLS-2$ 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 <null> but got [" //$NON-NLS-1$ + (nestedException != null ? nestedException.getClass() .getName() : "<unknown>") + "] instead.", //$NON-NLS-1$ //$NON-NLS-2$ nestedException == null); 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$ }
private TeiidSQLException testCreateThrowable(Throwable ecause, String esqlState) { TeiidSQLException e = TeiidSQLException.create(ecause); if (ecause.getClass() == TeiidSQLException.class) { ecause = null; } String sqlState = e.getSQLState(); Throwable cause = e.getCause(); int errorCode = e.getErrorCode(); Throwable nestedException = e.getCause(); SQLException nextException = e.getNextException(); assertEquals(esqlState, sqlState); assertEquals(ecause, cause); assertEquals(0, errorCode); assertEquals(nestedException, ecause); assertNull(nextException); return e; }
@Test public void testExceptionHandling() throws Exception { String ddl = "create virtual procedure vproc (x integer) returns integer as begin " + "raise sqlexception 'hello world' sqlstate 'abc', 1;" + "exception e " + "raise sqlwarning sqlexception 'caught' chain e.exception; " + "\"return\" = 1;"+ "end;"; TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl); String sql = "call vproc(1)"; //$NON-NLS-1$ ProcessorPlan plan = getProcedurePlan(sql, tm); HardcodedDataManager dataManager = new HardcodedDataManager(tm); helpTestProcess(plan, new List[] {Arrays.asList(1)}, dataManager, tm); TeiidSQLException tse = (TeiidSQLException)plan.getContext().getAndClearWarnings().get(0); assertEquals("caught", tse.getMessage()); assertEquals("hello world", tse.getCause().getMessage()); }
this.currentVarContext.setValue(exceptionSymbol(gs, 2), tse.getTeiidCode()); this.currentVarContext.setValue(exceptionSymbol(gs, 3), tse); this.currentVarContext.setValue(exceptionSymbol(gs, 4), tse.getCause()); continue;
this.currentVarContext.setValue(exceptionSymbol(gs, 2), tse.getTeiidCode()); this.currentVarContext.setValue(exceptionSymbol(gs, 3), tse); this.currentVarContext.setValue(exceptionSymbol(gs, 4), tse.getCause()); continue;
this.currentVarContext.setValue(exceptionSymbol(gs, 2), tse.getTeiidCode()); this.currentVarContext.setValue(exceptionSymbol(gs, 3), tse); this.currentVarContext.setValue(exceptionSymbol(gs, 4), tse.getCause()); continue;