public static TeiidSQLException create(Throwable exception) { if (exception instanceof TeiidSQLException) { return (TeiidSQLException)exception; } return create(exception, exception.getMessage()); }
@Override public void setAutoCommit(boolean autoCommit) throws SQLException { //TODO: detect if attempted set conflicts with current txn state throw new TeiidSQLException(); }
/** * @see org.teiid.jdbc.api.SQLException#isSystemErrorState() * @since 4.3 */ public boolean isSystemErrorState() { return SQLStates.isSystemErrorState(getSQLState()); }
private TeiidSQLException(SQLException ex, String message, boolean addChildren) { super(message, ex.getSQLState() == null ? SQLStates.DEFAULT : ex.getSQLState(), ex.getErrorCode(), ex); if (addChildren) { SQLException childException = ex.getNextException(); // this a child to the SQLException constructed from reason while (childException != null) { if (childException instanceof TeiidSQLException) { super.setNextException(ex); break; } super.setNextException(new TeiidSQLException(childException, getMessage(childException, null),false)); childException = childException.getNextException(); } } }
getContext().addWarning(TeiidSQLException.create(e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31266))); TeiidSQLException tse = TeiidSQLException.create(e); GroupSymbol gs = new GroupSymbol(program.getExceptionGroup()); this.currentVarContext.setValue(exceptionSymbol(gs, 0), tse.getSQLState()); this.currentVarContext.setValue(exceptionSymbol(gs, 1), tse.getErrorCode()); this.currentVarContext.setValue(exceptionSymbol(gs, 2), tse.getTeiidCode()); this.currentVarContext.setValue(exceptionSymbol(gs, 3), tse); this.currentVarContext.setValue(exceptionSymbol(gs, 4), tse.getCause()); continue;
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 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$ }
throw TeiidSQLException.create(resultsMsg.getException()); getDQP().closeRequest(getCurrentRequestID()); } catch (TeiidProcessingException e) { throw TeiidSQLException.create(e); } catch (TeiidComponentException e) { throw TeiidSQLException.create(e); TeiidSQLException exe = TeiidSQLException.create(resultsMsg.getException()); BatchUpdateException batchUpdateException = new BatchUpdateException(exe.getMessage(), exe.getSQLState(), exe.getErrorCode(), updateCounts, exe); this.updateCounts=null; throw batchUpdateException;
TeiidSQLException ex = TeiidSQLException.create(e); throw new BatchUpdateException(e.getMessage(), ex.getSQLState(), ex.getErrorCode(), allUpdateCounts==null?new int[0]:allUpdateCounts, e); } catch (BatchUpdateException e) { if (allUpdateCounts == null) {
@Test public void testCreate() { TeiidSQLException exception = TeiidSQLException.create(new Exception()); assertEquals(exception.getMessage(), Exception.class.getName()); assertNotNull(exception.getSQLState()); assertEquals(exception.getSQLState(), "38000"); //$NON-NLS-1$ assertEquals(exception, TeiidSQLException.create(exception)); }
@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 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()); }
@Test public void testExceptionAndWarning() throws Exception { String ddl = "create virtual procedure vproc (x integer) returns integer as begin declare exception e = sqlexception 'hello'; raise sqlwarning e; raise sqlexception 'hello world' sqlstate 'abc', 1 chain e; end;"; TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl); String sql = "call vproc(1)"; //$NON-NLS-1$ ProcessorPlan plan = getProcedurePlan(sql, tm); HardcodedDataManager dataManager = new HardcodedDataManager(tm); try { helpTestProcess(plan, null, dataManager, tm); fail(); } catch (TeiidProcessingException e) { TeiidSQLException tsw = (TeiidSQLException) plan.getContext().getAndClearWarnings().get(0); assertEquals("hello", tsw.getMessage()); assertEquals(e.getCause().getCause(), tsw); TeiidSQLException tse = (TeiidSQLException)e.getCause(); assertEquals("hello world", tse.getMessage()); assertEquals("abc", tse.getSQLState()); assertEquals(1, tse.getErrorCode()); } }
public static TeiidSQLException create(Throwable exception, String message) { message = getMessage(exception, message); Throwable origException = exception; if (exception instanceof TeiidSQLException return new TeiidSQLException((SQLException) exception, message, true); exception = findRootException(exception); sqlState = determineSQLState(exception, sqlState); TeiidSQLException tse = new TeiidSQLException(origException, message, sqlState, errorCode); tse.teiidCode = code; return tse;
getClass().getClassLoader()); } catch (TeiidException e) { throw TeiidSQLException.create(e, JDBCPlugin.Util.gs("module_load_failed"));//$NON-NLS-1$ } catch (TeiidSQLException e) { logger.log(Level.FINE, "Could not create connection", e); //$NON-NLS-1$ throw TeiidSQLException.create(e, e.getMessage());
@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()); }
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); }
/** * @see java.lang.Object#toString() */ public String toString() { try { return buildURL().getJDBCURL(); } catch (TeiidSQLException e) { return e.getMessage(); } }
getContext().addWarning(TeiidSQLException.create(e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31266))); TeiidSQLException tse = TeiidSQLException.create(e); GroupSymbol gs = new GroupSymbol(program.getExceptionGroup()); this.currentVarContext.setValue(exceptionSymbol(gs, 0), tse.getSQLState()); this.currentVarContext.setValue(exceptionSymbol(gs, 1), tse.getErrorCode()); this.currentVarContext.setValue(exceptionSymbol(gs, 2), tse.getTeiidCode()); this.currentVarContext.setValue(exceptionSymbol(gs, 3), tse); this.currentVarContext.setValue(exceptionSymbol(gs, 4), tse.getCause()); continue;