Search in sources :

Example 1 with ProcedureErrorInstructionException

use of org.teiid.client.ProcedureErrorInstructionException in project teiid by teiid.

the class TestSQLException method testCreateThrowable_01.

/*
	 * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
	 * 
	 * Tests various simple exceptions to see if the expected SQLState is
	 * returend.
	 */
@Test
public void testCreateThrowable_01() {
    testCreateThrowable(new CommunicationException(// $NON-NLS-1$
    "A test MM Communication Exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectionException("A test MM Connection Exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new IOException(// $NON-NLS-1$
    "A test Generic java.io.IOException"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(new MalformedURLException(// $NON-NLS-1$
    "A test java.net.MalformedURLException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new TeiidException("A test Generic MM Core Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(// $NON-NLS-1$
    new TeiidException("A test MM Exception"), SQLStates.DEFAULT);
    testCreateThrowable(new TeiidProcessingException(// $NON-NLS-1$
    "A test Generic MM Query Processing Exception"), SQLStates.USAGE_ERROR);
    testCreateThrowable(new TeiidRuntimeException("A test MM Runtime Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new TeiidSQLException("A test Generic MM SQL Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new NoRouteToHostException(// $NON-NLS-1$
    "A test java.net.NoRouteToHostException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new NullPointerException("A test NPE"), SQLStates.DEFAULT);
    testCreateThrowable(new ProcedureErrorInstructionException(// $NON-NLS-1$
    "A test SQL Procedure Error exception"), SQLStates.VIRTUAL_PROCEDURE_ERROR);
    testCreateThrowable(new SocketTimeoutException(// $NON-NLS-1$
    "A test socket timeout exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new UnknownHostException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
}
Also used : MalformedURLException(java.net.MalformedURLException) CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) NoRouteToHostException(java.net.NoRouteToHostException) TeiidException(org.teiid.core.TeiidException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionException(org.teiid.net.ConnectionException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 2 with ProcedureErrorInstructionException

use of org.teiid.client.ProcedureErrorInstructionException in project teiid by teiid.

the class ProcedurePlan method processProcedure.

/**
 * <p>Process the procedure, using the stack of Programs supplied by the
 * ProcessorEnvironment.  With each pass through the loop, the
 * current Program is gotten off the top of the stack, and the
 * current instruction is gotten from that program; each call
 * to an instruction's process method may alter the Program
 * Stack and/or the current instruction pointer of a Program,
 * so it's important that this method's loop refer to the
 * call stack of the ProcessorEnvironment each time, and not
 * cache things in local variables.  If the current Program's
 * current instruction is null, then it's time to pop that
 * Program off the stack.</p>
 *
 * @return List a single tuple containing one Integer: the update
 * count resulting from the procedure execution.
 */
private TupleSource processProcedure() throws TeiidComponentException, TeiidProcessingException, BlockedException {
    // execute plan
    ProgramInstruction inst = null;
    while (!this.programs.empty()) {
        Program program = peek();
        inst = program.getCurrentInstruction();
        if (inst == null) {
            // $NON-NLS-1$
            LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Finished program", program);
            // look ahead to see if we need to process in place
            VariableContext vc = this.cursorStates.getParentContext();
            CursorState last = (CursorState) this.cursorStates.getValue(null);
            if (last != null) {
                if (last.resultsBuffer == null && (last.usesLocalTemp || !txnTupleSources.isEmpty())) {
                    last.resultsBuffer = bufferMgr.createTupleBuffer(last.processor.getOutputElements(), getContext().getConnectionId(), TupleSourceType.PROCESSOR);
                    last.returning = true;
                }
                if (last.returning) {
                    while (last.ts.hasNext()) {
                        List<?> tuple = last.ts.nextTuple();
                        last.resultsBuffer.addTuple(tuple);
                    }
                    last.resultsBuffer.close();
                    last.ts = last.resultsBuffer.createIndexedTupleSource(true);
                    last.returning = false;
                }
            }
            this.pop(true);
            continue;
        }
        try {
            getContext().setCurrentTimestamp(System.currentTimeMillis());
            if (inst instanceof RepeatedInstruction) {
                // $NON-NLS-1$
                LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Executing repeated instruction", inst);
                RepeatedInstruction loop = (RepeatedInstruction) inst;
                if (loop.testCondition(this)) {
                    // $NON-NLS-1$
                    LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Passed condition, executing program " + loop.getNestedProgram());
                    inst.process(this);
                    this.push(loop.getNestedProgram());
                    continue;
                }
                // $NON-NLS-1$
                LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Exiting repeated instruction", inst);
                loop.postInstruction(this);
            } else {
                // $NON-NLS-1$
                LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Executing instruction", inst);
                inst.process(this);
                this.evaluator.close();
            }
        } catch (TeiidComponentException e) {
            throw e;
        } catch (Exception e) {
            // processing or teiidsqlexception
            boolean atomic = program.isAtomic();
            while (program.getExceptionGroup() == null) {
                this.pop(false);
                if (this.programs.empty()) {
                    // reached the top without a handler, so throw
                    if (e instanceof TeiidProcessingException) {
                        throw (TeiidProcessingException) e;
                    }
                    throw new ProcedureErrorInstructionException(QueryPlugin.Event.TEIID30167, e);
                }
                program = peek();
                atomic |= program.isAtomic();
            }
            try {
                // allow the current program to go out of scope
                this.pop(false);
                if (atomic) {
                    TransactionContext tc = this.getContext().getTransactionContext();
                    if (tc != null && tc.getTransactionType() != Scope.NONE) {
                        // a non-completing atomic block under a higher level transaction
                        // this will not work correctly until we support
                        // checkpoints/subtransactions
                        tc.getTransaction().setRollbackOnly();
                        getContext().addWarning(TeiidSQLException.create(e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31266)));
                    }
                }
            } catch (IllegalStateException | SystemException | TeiidComponentException e1) {
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_DQP, "Caught exception while rolling back transaction", e1);
            } catch (Throwable e1) {
                LogManager.logWarning(LogConstants.CTX_DQP, e1);
            }
            if (e instanceof RuntimeException) {
                LogManager.logWarning(LogConstants.CTX_DQP, e);
            } else {
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_DQP, "Caught exception in exception hanlding block", e);
            }
            if (program.getExceptionProgram() == null) {
                continue;
            }
            Program exceptionProgram = program.getExceptionProgram();
            this.push(exceptionProgram);
            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;
        }
        program.incrementProgramCounter();
    }
    CursorState last = (CursorState) this.cursorStates.getValue(null);
    if (last == null) {
        return CollectionTupleSource.createNullTupleSource();
    }
    return last.ts;
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) VariableContext(org.teiid.query.sql.util.VariableContext) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) BlockedException(org.teiid.common.buffer.BlockedException) XATransactionException(org.teiid.client.xa.XATransactionException) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) SystemException(javax.transaction.SystemException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TransactionContext(org.teiid.dqp.service.TransactionContext) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidComponentException(org.teiid.core.TeiidComponentException)

Aggregations

ProcedureErrorInstructionException (org.teiid.client.ProcedureErrorInstructionException)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 NoRouteToHostException (java.net.NoRouteToHostException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 SystemException (javax.transaction.SystemException)1 Test (org.junit.Test)1 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)1 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)1 XATransactionException (org.teiid.client.xa.XATransactionException)1 BlockedException (org.teiid.common.buffer.BlockedException)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidException (org.teiid.core.TeiidException)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 TransactionContext (org.teiid.dqp.service.TransactionContext)1 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)1 CommunicationException (org.teiid.net.CommunicationException)1