Package org.teiid.dqp.service

Examples of org.teiid.dqp.service.TransactionContext


       
        Mockito.verify(txn).setRollbackOnly();
   
   
    @Test public void testRequestCancel() throws Exception{
      TransactionContext tc = server.getOrCreateTransactionContext(THREAD1);
      server.begin(tc);
     
      server.cancelTransactions(THREAD1, true);
      Mockito.verify(txn).setRollbackOnly();
    }     
View Full Code Here


        }
    }

    private void createProcessor() throws TeiidComponentException {
       
        TransactionContext tc = transactionService.getOrCreateTransactionContext(workContext.getSessionId());
       
        Assertion.assertTrue(tc.getTransactionType() != TransactionContext.Scope.REQUEST, "Transaction already associated with request."); //$NON-NLS-1$

        // If local or global transaction is not started.
        if (tc.getTransactionType() == Scope.NONE) {
           
            boolean startAutoWrapTxn = false;
           
            if(RequestMessage.TXN_WRAP_ON.equals(requestMsg.getTxnAutoWrapMode())){
                startAutoWrapTxn = true;
View Full Code Here

            transactions.removeTransactionContext(threadId);
        }
    }

    private TransactionContext checkXAState(final String threadId, final XidImpl xid, boolean transactionExpected, boolean threadBound) throws XATransactionException {
        TransactionContext tc = transactions.getTransactionContext(xid);
       
        if (transactionExpected && tc == null) {
            throw new XATransactionException(XAException.XAER_NOTA, QueryPlugin.Util.getString("TransactionServer.no_global_transaction", xid)); //$NON-NLS-1$
        } else if (!transactionExpected) {
            if (tc != null) {
                throw new XATransactionException(XAException.XAER_DUPID, QueryPlugin.Util.getString("TransactionServer.existing_global_transaction", new Object[] {xid})); //$NON-NLS-1$
            }
            if (!threadBound) {
                tc = transactions.getOrCreateTransactionContext(threadId);
                if (tc.getTransactionType() != TransactionContext.Scope.NONE) {
                    throw new XATransactionException(XAException.XAER_PROTO, QueryPlugin.Util.getString("TransactionServer.existing_transaction", new Object[] {xid, threadId})); //$NON-NLS-1$
                }
            }
            return null;
        }
       
        if (threadBound) {
            if (!threadId.equals(tc.getThreadId())) {
                throw new XATransactionException(XAException.XAER_PROTO, QueryPlugin.Util.getString("TransactionServer.wrong_transaction", xid)); //$NON-NLS-1$
            }
        } else if (tc.getThreadId() != null) {
            throw new XATransactionException(XAException.XAER_PROTO, QueryPlugin.Util.getString("TransactionServer.concurrent_transaction", xid)); //$NON-NLS-1$
        }
       
        return tc;
    }
View Full Code Here

    }

    private TransactionContext checkLocalTransactionState(String threadId, boolean transactionExpected)
      throws XATransactionException {

        final TransactionContext tc = transactions.getOrCreateTransactionContext(threadId);

        try {
          if (tc.getTransactionType() != TransactionContext.Scope.NONE) {
              if (tc.getTransactionType() != TransactionContext.Scope.LOCAL) {
                  throw new InvalidTransactionException(QueryPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
              }
              if (!transactionExpected) {
                throw new InvalidTransactionException(QueryPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
              }
              transactionManager.resume(tc.getTransaction());
          } else if (transactionExpected) {
            throw new InvalidTransactionException(QueryPlugin.Util.getString("TransactionServer.no_transaction", threadId)); //$NON-NLS-1$
          }
        } catch (InvalidTransactionException e) {
          throw new XATransactionException(e);
View Full Code Here

    /**
     * Local Transaction
     */
    public TransactionContext begin(String threadId) throws XATransactionException {
        TransactionContext tc = checkLocalTransactionState(threadId, false);
        beginDirect(tc);
        tc.setTransactionType(TransactionContext.Scope.LOCAL);
        return tc;
    }
View Full Code Here

    /**
     * Local Transaction
     */   
    public void commit(String threadId) throws XATransactionException {
        TransactionContext tc = checkLocalTransactionState(threadId, true);
        commitDirect(tc);
    }
View Full Code Here

    /**
     * Local Transaction
     */   
    public void rollback(String threadId) throws XATransactionException {
        TransactionContext tc = checkLocalTransactionState(threadId, true);
        rollbackDirect(tc);
    }
View Full Code Here

        rollbackDirect(context);
        return context;     
    }

    public void cancelTransactions(String threadId, boolean requestOnly) throws XATransactionException {
      TransactionContext tc = requestOnly?transactions.getTransactionContext(threadId):transactions.removeTransactionContext(threadId);
       
        if (tc == null || tc.getTransactionType() == TransactionContext.Scope.NONE
            || (requestOnly && tc.getTransactionType() != TransactionContext.Scope.REQUEST)) {
            return;
        }
       
        try {
            tc.getTransaction().setRollbackOnly();
    } catch (SystemException e) {
      throw new XATransactionException(e);
    }
    }
View Full Code Here

        private Map<String, TransactionContext> threadToTransactionContext = new HashMap<String, TransactionContext>();
        // (MMXid -> global transactions keyed)
        private Map<Xid, TransactionContext> xidToTransactionContext = new HashMap<Xid, TransactionContext>();
       
        public synchronized TransactionContext getOrCreateTransactionContext(String threadId) {
            TransactionContext tc = threadToTransactionContext.get(threadId);

            if (tc == null) {
                tc = new TransactionContext();
                tc.setThreadId(threadId);
                threadToTransactionContext.put(threadId, tc);
            }

            return tc;
        }
View Full Code Here

    /**
     * Global Transaction
     */
  public int prepare(final String threadId, XidImpl xid, boolean singleTM) throws XATransactionException {
        TransactionContext tc = checkXAState(threadId, xid, true, false);
        if (!tc.getSuspendedBy().isEmpty()) {
            throw new XATransactionException(XAException.XAER_PROTO, QueryPlugin.Util.getString("TransactionServer.suspended_exist", xid)); //$NON-NLS-1$
        }   
       
        // In the container this pass though
        if (singleTM) {               
        return XAResource.XA_RDONLY;
        }
       
        try {
          return this.xaTerminator.prepare(tc.getXid());
        } catch (XAException e) {
            throw new XATransactionException(e);
        }
    }
View Full Code Here

TOP

Related Classes of org.teiid.dqp.service.TransactionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.