Search in sources :

Example 1 with XATransactionException

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

the class TestSocketServiceRegistry method testXATransactionExceptionConversion.

public void testXATransactionExceptionConversion() throws Exception {
    Method m = DQP.class.getMethod("recover", new Class[] { Integer.TYPE });
    Throwable t = ExceptionUtil.convertException(m, new TeiidComponentException());
    assertTrue(t instanceof XATransactionException);
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) Method(java.lang.reflect.Method) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 2 with XATransactionException

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

the class RequestWorkItem method requestCancel.

public boolean requestCancel(String reason) throws TeiidComponentException {
    synchronized (this) {
        if (this.isCanceled || this.closeRequested) {
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logDetail(LogConstants.CTX_DQP, "Ignoring cancel for", requestID, "since request is already cancelled/closed");
            return false;
        }
        this.isCanceled = true;
        this.cancelReason = QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30563, requestID, reason);
    }
    LogManager.logDetail(LogConstants.CTX_DQP, cancelReason);
    if (this.processor != null) {
        this.processor.requestCanceled();
    }
    // Cancel Connector atomic requests
    try {
        for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
            connectorRequest.cancelRequest();
        }
    } finally {
        try {
            if (transactionService != null) {
                try {
                    transactionService.cancelTransactions(requestID.getConnectionID(), true);
                } catch (XATransactionException err) {
                    throw new TeiidComponentException(QueryPlugin.Event.TEIID30544, err);
                }
            }
        } finally {
            this.moreWork();
        }
    }
    return true;
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 3 with XATransactionException

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

the class TransactionServerImpl method beginDirect.

private void beginDirect(TransactionContext tc) throws XATransactionException {
    try {
        transactionManager.begin();
        Transaction tx = transactionManager.suspend();
        tc.setTransaction(tx);
        tc.setCreationTime(System.currentTimeMillis());
    } catch (javax.transaction.NotSupportedException err) {
        throw new XATransactionException(QueryPlugin.Event.TEIID30528, err);
    } catch (SystemException err) {
        throw new XATransactionException(QueryPlugin.Event.TEIID30528, err);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 4 with XATransactionException

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

the class TransactionServerImpl method end.

/**
 * Global Transaction
 */
public void end(final String threadId, XidImpl xid, int flags, boolean singleTM) throws XATransactionException {
    TransactionContext tc = checkXAState(threadId, xid, true, true);
    try {
        switch(flags) {
            case XAResource.TMSUSPEND:
                {
                    tc.getSuspendedBy().add(threadId);
                    break;
                }
            case XAResource.TMSUCCESS:
                {
                    // TODO: should close all statements
                    break;
                }
            case XAResource.TMFAIL:
                {
                    cancelTransactions(threadId, false);
                    break;
                }
            default:
                throw new XATransactionException(QueryPlugin.Event.TEIID30520, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30520));
        }
    } finally {
        tc.setThreadId(null);
        transactions.removeTransactionContext(threadId);
    }
}
Also used : TransactionContext(org.teiid.dqp.service.TransactionContext) XATransactionException(org.teiid.client.xa.XATransactionException)

Example 5 with XATransactionException

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

the class TransactionServerImpl method start.

/**
 * Global Transaction
 */
public void start(final String threadId, final XidImpl xid, int flags, int timeout, boolean singleTM) throws XATransactionException {
    TransactionContext tc = null;
    switch(flags) {
        case XAResource.TMNOFLAGS:
            {
                try {
                    checkXAState(threadId, xid, false, false);
                    tc = transactions.getOrCreateTransactionContext(threadId);
                    if (tc.getTransactionType() != TransactionContext.Scope.NONE) {
                        throw new XATransactionException(QueryPlugin.Event.TEIID30517, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30517));
                    }
                    tc.setTransactionTimeout(timeout);
                    tc.setXid(xid);
                    tc.setTransactionType(TransactionContext.Scope.GLOBAL);
                    if (singleTM) {
                        tc.setTransaction(transactionManager.getTransaction());
                        if (tc.getTransaction() == null) {
                            // in theory we could inflow the txn and then change all of the methods to check singleTM off of the context
                            throw new XATransactionException(QueryPlugin.Event.TEIID30590, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30590));
                        }
                    } else {
                        FutureWork<Transaction> work = new FutureWork<Transaction>(new Callable<Transaction>() {

                            @Override
                            public Transaction call() throws Exception {
                                return transactionManager.getTransaction();
                            }
                        }, 0);
                        workManager.doWork(work, WorkManager.INDEFINITE, tc, null);
                        tc.setTransaction(work.get());
                    }
                } catch (NotSupportedException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (WorkException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (InterruptedException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (ExecutionException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                } catch (SystemException e) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
                }
                break;
            }
        case XAResource.TMJOIN:
        case XAResource.TMRESUME:
            {
                tc = checkXAState(threadId, xid, true, false);
                TransactionContext threadContext = transactions.getOrCreateTransactionContext(threadId);
                if (threadContext.getTransactionType() != TransactionContext.Scope.NONE) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30517, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30517));
                }
                if (flags == XAResource.TMRESUME && !tc.getSuspendedBy().remove(threadId)) {
                    throw new XATransactionException(QueryPlugin.Event.TEIID30518, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30518, new Object[] { xid, threadId }));
                }
                break;
            }
        default:
            throw new XATransactionException(QueryPlugin.Event.TEIID30519, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30519));
    }
    tc.setThreadId(threadId);
    transactions.addTransactionContext(tc);
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionContext(org.teiid.dqp.service.TransactionContext) WorkException(javax.resource.spi.work.WorkException) XATransactionException(org.teiid.client.xa.XATransactionException) NotSupportedException(javax.resource.NotSupportedException) ExecutionException(java.util.concurrent.ExecutionException) Callable(java.util.concurrent.Callable)

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