Search in sources :

Example 6 with XATransactionException

use of org.teiid.client.xa.XATransactionException in project teiid by teiid.

the class Request method getTransactionContext.

TransactionContext getTransactionContext(boolean startAutoWrap) throws TeiidComponentException {
    if (this.transactionContext != null) {
        return this.transactionContext;
    }
    TransactionContext tc = transactionService.getOrCreateTransactionContext(workContext.getSessionId());
    if (tc.getTransactionType() == TransactionContext.Scope.REQUEST && this.workContext.isDerived()) {
        // to a sub-request, request scope should appear as global - which means associated and non-suspendable
        tc = tc.clone();
        tc.setTransactionType(TransactionContext.Scope.INHERITED);
    }
    // $NON-NLS-1$
    Assertion.assertTrue(tc.getTransactionType() != TransactionContext.Scope.REQUEST, "Transaction already associated with request.");
    // If local or global transaction is not started.
    if (tc.getTransactionType() == Scope.NONE && !requestMsg.isNoExec()) {
        if (!startAutoWrap) {
            return null;
        }
        Boolean startAutoWrapTxn = false;
        if (RequestMessage.TXN_WRAP_ON.equals(requestMsg.getTxnAutoWrapMode())) {
            startAutoWrapTxn = true;
        } else if (RequestMessage.TXN_WRAP_DETECT.equals(requestMsg.getTxnAutoWrapMode())) {
            boolean transactionalRead = requestMsg.getTransactionIsolation() == Connection.TRANSACTION_REPEATABLE_READ || requestMsg.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE;
            startAutoWrapTxn = processPlan.requiresTransaction(transactionalRead);
            if (startAutoWrapTxn == null) {
                startAutoWrapTxn = false;
            }
        }
        if (startAutoWrapTxn) {
            try {
                transactionService.begin(tc);
            } catch (XATransactionException err) {
                throw new TeiidComponentException(QueryPlugin.Event.TEIID30493, err);
            }
        }
    }
    tc.setIsolationLevel(requestMsg.getTransactionIsolation());
    this.transactionContext = tc;
    return this.transactionContext;
}
Also used : TransactionContext(org.teiid.dqp.service.TransactionContext) TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 7 with XATransactionException

use of org.teiid.client.xa.XATransactionException in project teiid by teiid.

the class RequestWorkItem method close.

/**
 * Client close is currently implemented as asynch.
 * Any errors that occur will not make it to the client, instead we just log them here.
 */
protected void close() {
    long rowcount = -1;
    try {
        cancelCancelTask();
        if (moreWorkTask != null) {
            moreWorkTask.cancel(false);
            moreWorkTask = null;
        }
        if (this.resultsBuffer != null) {
            if (this.processor != null) {
                try {
                    CommandContext.pushThreadLocalContext(this.processor.getContext());
                    this.processor.closeProcessing();
                    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_DQP, "Removing tuplesource for the request " + requestID);
                    }
                    rowcount = resultsBuffer.getRowCount();
                    if (this.cid == null || !this.doneProducingBatches) {
                        resultsBuffer.remove();
                    }
                    for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
                        connectorRequest.fullyCloseSource();
                    }
                    CommandContext cc = this.processor.getContext();
                    cc.close();
                } catch (Throwable t) {
                    // guard against unexpected exceptions in close
                    handleThrowable(t);
                } finally {
                    CommandContext.popThreadLocalContext();
                }
            }
            this.resultsBuffer = null;
            if (!this.lobStreams.isEmpty()) {
                List<LobWorkItem> lobs = null;
                synchronized (lobStreams) {
                    lobs = new ArrayList<LobWorkItem>(this.lobStreams.values());
                }
                for (LobWorkItem lobWorkItem : lobs) {
                    lobWorkItem.close();
                }
            }
        }
        boolean isActive = false;
        if (this.transactionState == TransactionState.ACTIVE) {
            isActive = true;
            this.transactionState = TransactionState.DONE;
        }
        if (transactionContext != null) {
            if (transactionContext.getTransactionType() == TransactionContext.Scope.REQUEST) {
                if (!isActive) {
                    LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31200, transactionContext.getTransactionId()));
                }
                try {
                    this.transactionService.rollback(transactionContext);
                } catch (XATransactionException e1) {
                    LogManager.logWarning(LogConstants.CTX_DQP, e1, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30028));
                }
            } else if (transactionContext.getTransactionType() != TransactionContext.Scope.NONE) {
                suspend();
            }
        }
        synchronized (this) {
            if (this.processingException == null && this.resultsReceiver != null) {
                // sanity check to ensure that something will be sent to the client
                setCanceledException();
            }
        }
    } catch (Throwable t) {
        handleThrowable(t);
    } finally {
        isClosed = true;
        dqpCore.removeRequest(this);
        if (this.processingException != null) {
            sendError();
        }
        dqpCore.logMMCommand(this, Event.END, rowcount, this.timer.stop());
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 8 with XATransactionException

use of org.teiid.client.xa.XATransactionException in project teiid by teiid.

the class ForEachRowPlan method close.

@Override
public void close() throws TeiidComponentException {
    if (this.queryProcessor != null) {
        this.queryProcessor.closeProcessing();
        if (this.rowProcessor != null) {
            this.rowProcessor.closeProcessing();
        }
    }
    if (this.planContext != null) {
        TransactionService ts = this.getContext().getTransactionServer();
        try {
            ts.resume(planContext);
            ts.rollback(planContext);
            this.planContext = null;
        } catch (XATransactionException e) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30165, e);
        }
    }
}
Also used : TransactionService(org.teiid.dqp.service.TransactionService) TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 9 with XATransactionException

use of org.teiid.client.xa.XATransactionException in project teiid by teiid.

the class ProcedurePlan method pop.

/**
 * @param success
 * @throws TeiidComponentException
 * @throws XATransactionException
 */
public void pop(boolean success) throws TeiidComponentException {
    this.evaluator.close();
    Program program = this.programs.pop();
    VariableContext vc = this.currentVarContext;
    VariableContext cs = this.cursorStates;
    try {
        this.currentVarContext = this.currentVarContext.getParentContext();
        this.cursorStates = this.cursorStates.getParentContext();
        TempTableStore tempTableStore = program.getTempTableStore();
        this.getContext().setTempTableStore(tempTableStore.getParentTempTableStore());
        tempTableStore.removeTempTables();
        if (program.startedTxn()) {
            TransactionService ts = this.getContext().getTransactionServer();
            TransactionContext tc = this.blockContext;
            this.blockContext = null;
            try {
                ts.resume(tc);
                for (WeakReference<DataTierTupleSource> ref : txnTupleSources) {
                    DataTierTupleSource dtts = ref.get();
                    if (dtts != null) {
                        dtts.fullyCloseSource();
                    }
                }
                this.txnTupleSources.clear();
                if (success) {
                    ts.commit(tc);
                } else {
                    ts.rollback(tc);
                }
            } catch (XATransactionException e) {
                throw new TeiidComponentException(QueryPlugin.Event.TEIID30165, e);
            }
        }
    } finally {
        removeAllCursors(cs);
    }
}
Also used : TempTableStore(org.teiid.query.tempdata.TempTableStore) TransactionService(org.teiid.dqp.service.TransactionService) TransactionContext(org.teiid.dqp.service.TransactionContext) DataTierTupleSource(org.teiid.dqp.internal.process.DataTierTupleSource) TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException) VariableContext(org.teiid.query.sql.util.VariableContext)

Example 10 with XATransactionException

use of org.teiid.client.xa.XATransactionException in project teiid by teiid.

the class BatchedUpdatePlan method close.

/**
 * @see org.teiid.query.processor.ProcessorPlan#close()
 * @since 4.2
 */
public void close() throws TeiidComponentException {
    // if the plan opened but the atomic request got cancelled then close the last plan node.
    TransactionService ts = this.getContext().getTransactionServer();
    if (planIndex < updatePlans.length && planOpened[planIndex]) {
        try {
            updatePlans[planIndex].close();
        } catch (TeiidComponentException e) {
            LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
        }
        if (this.planContexts[planIndex] != null) {
            try {
                ts.resume(this.planContexts[planIndex]);
                ts.rollback(this.planContexts[planIndex]);
            } catch (XATransactionException e) {
                LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
            }
            this.planContexts[planIndex] = null;
        }
    }
}
Also used : TransactionService(org.teiid.dqp.service.TransactionService) TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException)

Aggregations

XATransactionException (org.teiid.client.xa.XATransactionException)11 TeiidComponentException (org.teiid.core.TeiidComponentException)6 TransactionContext (org.teiid.dqp.service.TransactionContext)4 TransactionService (org.teiid.dqp.service.TransactionService)3 SystemException (javax.transaction.SystemException)2 Transaction (javax.transaction.Transaction)2 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 NotSupportedException (javax.resource.NotSupportedException)1 WorkException (javax.resource.spi.work.WorkException)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 DQP (org.teiid.client.DQP)1 LogonResult (org.teiid.client.security.LogonResult)1 SessionToken (org.teiid.client.security.SessionToken)1 DataTierTupleSource (org.teiid.dqp.internal.process.DataTierTupleSource)1 ServerConnection (org.teiid.net.ServerConnection)1