Examples of TransactionContext


Examples of org.teiid.dqp.service.TransactionContext

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

Examples of org.teiid.dqp.service.TransactionContext

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

Examples of org.teiid.dqp.service.TransactionContext

        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

Examples of org.teiid.dqp.service.TransactionContext

        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

Examples of org.teiid.dqp.service.TransactionContext

    /**
     * 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

Examples of org.teiid.dqp.service.TransactionContext

   
    /**
     * Global Transaction
     */   
    public void commit(final String threadId, XidImpl xid, boolean onePhase, boolean singleTM) throws XATransactionException {
      TransactionContext tc = checkXAState(threadId, xid, true, false)
      try {
          if (singleTM || (onePhase && XAResource.XA_RDONLY == prepare(threadId, xid, singleTM))) {
            return; //nothing to do
          }
          //TODO: we have no way of knowing for sure if we can safely use the onephase optimization
          this.xaTerminator.commit(tc.getXid(), false);
      } catch (XAException e) {
            throw new XATransactionException(e);
        } finally {
        this.transactions.removeTransactionContext(tc);
      }
View Full Code Here

Examples of org.teiid.dqp.service.TransactionContext

   
    /**
     * Global Transaction
     */
    public void rollback(final String threadId, XidImpl xid, boolean singleTM) throws XATransactionException {
      TransactionContext tc = checkXAState(threadId, xid, true, false)
      try {
        // In the case of single TM, the container directly roll backs the sources.
          if (!singleTM) {
            this.xaTerminator.rollback(tc.getXid());
          }
      } catch (XAException e) {
            throw new XATransactionException(e);
        } finally {
        this.transactions.removeTransactionContext(tc);
View Full Code Here

Examples of org.teiid.dqp.service.TransactionContext

    /**
     * Global Transaction
     */   
    public void forget(final String threadId, XidImpl xid, boolean singleTM) throws XATransactionException {
      TransactionContext tc = checkXAState(threadId, xid, true, false);
        try {
          if (singleTM) {
            return;
          }
            this.xaTerminator.forget(xid);
View Full Code Here

Examples of org.teiid.dqp.service.TransactionContext

    /**
     * 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(XAException.XAER_PROTO, QueryPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
          }
          tc.setTransactionTimeout(timeout);
          tc.setXid(xid);
          tc.setTransactionType(TransactionContext.Scope.GLOBAL);
          if (singleTM) {
            tc.setTransaction(transactionManager.getTransaction());
            assert tc.getTransaction() != null;
          } 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(e, XAException.XAER_INVAL);
        } catch (WorkException e) {
          throw new XATransactionException(e, XAException.XAER_INVAL);
        } catch (InterruptedException e) {
          throw new XATransactionException(e, XAException.XAER_INVAL);
        } catch (ExecutionException e) {
          throw new XATransactionException(e, XAException.XAER_INVAL);
        } catch (SystemException e) {
          throw new XATransactionException(e, XAException.XAER_INVAL);
        }
                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(XAException.XAER_PROTO, QueryPlugin.Util.getString("TransactionServer.existing_transaction")); //$NON-NLS-1$
                }
               
                if (flags == XAResource.TMRESUME && !tc.getSuspendedBy().remove(threadId)) {
                    throw new XATransactionException(XAException.XAER_PROTO, QueryPlugin.Util.getString("TransactionServer.resume_failed", new Object[] {xid, threadId})); //$NON-NLS-1$
View Full Code Here

Examples of org.teiid.dqp.service.TransactionContext

    /**
     * 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(XAException.XAER_INVAL, QueryPlugin.Util.getString("TransactionServer.unknown_flags")); //$NON-NLS-1$
            }
        } finally {
            tc.setThreadId(null);
            transactions.removeTransactionContext(threadId);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.