當前位置: 首頁>>代碼示例>>Java>>正文


Java BitronixTransaction.setStatus方法代碼示例

本文整理匯總了Java中bitronix.tm.BitronixTransaction.setStatus方法的典型用法代碼示例。如果您正苦於以下問題:Java BitronixTransaction.setStatus方法的具體用法?Java BitronixTransaction.setStatus怎麽用?Java BitronixTransaction.setStatus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bitronix.tm.BitronixTransaction的用法示例。


在下文中一共展示了BitronixTransaction.setStatus方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invoke

import bitronix.tm.BitronixTransaction; //導入方法依賴的package包/類
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Object result = null;
    String methodName = method.getName();

    logger.trace(methodName);
    if( "commit".equals(methodName) && args == null) { 
        BitronixTransaction bt = ((BitronixTransactionManager) ut).getCurrentTransaction();
        // Ensure that all actions have occurred so that we get what is _really_ commited to the db
        // (This code is straight from bitronix)
        Iterator<?> iter = bt.getSynchronizationScheduler().reverseIterator();
        while (iter.hasNext()) {
            Synchronization synchronization = (Synchronization) iter.next();
            try {
                synchronization.beforeCompletion();
            } catch (RuntimeException ex) {
                bt.setStatus(Status.STATUS_MARKED_ROLLBACK);
                throw ex;
            }
        }
        
        String testMethodName = MarshallingTestUtil.getTestMethodName();
        if( testMethodName != null ) { 
            EntityManager em = emf.createEntityManager();
            Set<MarshalledData> newMarshalledData = objectSpecificMarshallingActions.updateManagedObjects(testMethodName);
            for( MarshalledData marshalledData : newMarshalledData ) { 
                em.persist(marshalledData);
            }
            em.close();
        }
        ut.commit();
        return result;
    }
    else { 
        result = invoke(method, ut, args);
    }
    
    return result;
}
 
開發者ID:mrietveld,項目名稱:gimcrack,代碼行數:39,代碼來源:UserTransactionProxy.java

示例2: prepare

import bitronix.tm.BitronixTransaction; //導入方法依賴的package包/類
/**
 * Execute phase 1 prepare.
 * @param transaction the transaction to prepare.
 * @return a list that will be filled with all resources that received the prepare command
 *  and replied with {@link javax.transaction.xa.XAResource#XA_OK}.
 * @throws RollbackException when an error occured that can be fixed with a rollback.
 * @throws bitronix.tm.internal.BitronixSystemException when an internal error occured.
 */
public List<XAResourceHolderState> prepare(BitronixTransaction transaction) throws RollbackException, BitronixSystemException {
    XAResourceManager resourceManager = transaction.getResourceManager();
    transaction.setStatus(Status.STATUS_PREPARING);
    preparedResources.clear();

    if (resourceManager.size() == 0) {
        if (TransactionManagerServices.getConfiguration().isWarnAboutZeroResourceTransaction())
            log.warn("executing transaction with 0 enlisted resource");
        else
            if (log.isDebugEnabled()) { log.debug("0 resource enlisted, no prepare needed"); }

        transaction.setStatus(Status.STATUS_PREPARED);
        return preparedResources;
    }

    // 1PC optimization
    if (resourceManager.size() == 1) {
        XAResourceHolderState resourceHolder = resourceManager.getAllResources().get(0);

        preparedResources.add(resourceHolder);
        if (log.isDebugEnabled()) { log.debug("1 resource enlisted, no prepare needed (1PC)"); }
        transaction.setStatus(Status.STATUS_PREPARED);
        return preparedResources;
    }

    try {
        executePhase(resourceManager, false);
    } catch (PhaseException ex) {
        logFailedResources(ex);
        throwException("transaction failed during prepare of " + transaction, ex);
    }

    transaction.setStatus(Status.STATUS_PREPARED);
    if (log.isDebugEnabled()) { log.debug("successfully prepared " + preparedResources.size() + " resource(s)"); }
    return Collections.unmodifiableList(preparedResources);
}
 
開發者ID:bitronix,項目名稱:btm,代碼行數:45,代碼來源:Preparer.java

示例3: rollback

import bitronix.tm.BitronixTransaction; //導入方法依賴的package包/類
/**
 * Rollback the current XA transaction. Transaction will not timeout while changing status but rather by some
 * extra logic that will manually throw the exception after doing as much cleanup as possible.
 *
 * @param transaction the transaction to rollback.
 * @param interestedResources resources that should be rolled back.
 * @throws HeuristicCommitException when all resources committed instead.
 * @throws HeuristicMixedException when some resources committed and some rolled back.
 * @throws bitronix.tm.internal.BitronixSystemException when an internal error occured.
 */
public void rollback(BitronixTransaction transaction, List<XAResourceHolderState> interestedResources) throws HeuristicMixedException, HeuristicCommitException, BitronixSystemException {
    XAResourceManager resourceManager = transaction.getResourceManager();
    transaction.setStatus(Status.STATUS_ROLLING_BACK);
    this.interestedResources.clear();
    this.interestedResources.addAll(interestedResources);

    try {
        executePhase(resourceManager, true);
    } catch (PhaseException ex) {
        logFailedResources(ex);
        transaction.setStatus(Status.STATUS_UNKNOWN);
        throwException("transaction failed during rollback of " + transaction, ex, interestedResources.size());
    }

    if (log.isDebugEnabled()) { log.debug("rollback executed on resources " + Decoder.collectResourcesNames(rolledbackResources)); }

    // Some resources might have failed the 2nd phase of 2PC.
    // Only resources which successfully rolled back should be registered in the journal, the other
    // ones should be picked up by the recoverer.
    // Not interested resources have to be included as well since they returned XA_RDONLY and they
    // don't participate in phase 2: the TX succeded for them.
    Set<String> rolledbackAndNotInterestedUniqueNames = new HashSet<String>();
    rolledbackAndNotInterestedUniqueNames.addAll(collectResourcesUniqueNames(rolledbackResources));
    List<XAResourceHolderState> notInterestedResources = collectNotInterestedResources(resourceManager.getAllResources(), interestedResources);
    rolledbackAndNotInterestedUniqueNames.addAll(collectResourcesUniqueNames(notInterestedResources));

    if (log.isDebugEnabled()) {
        List<XAResourceHolderState> rolledbackAndNotInterestedResources = new ArrayList<XAResourceHolderState>();
        rolledbackAndNotInterestedResources.addAll(rolledbackResources);
        rolledbackAndNotInterestedResources.addAll(notInterestedResources);

        log.debug("rollback succeeded on resources " + Decoder.collectResourcesNames(rolledbackAndNotInterestedResources));
    }

    transaction.setStatus(Status.STATUS_ROLLEDBACK, rolledbackAndNotInterestedUniqueNames);
}
 
開發者ID:bitronix,項目名稱:btm,代碼行數:47,代碼來源:Rollbacker.java

示例4: commit

import bitronix.tm.BitronixTransaction; //導入方法依賴的package包/類
/**
 * Execute phase 2 commit.
 * @param transaction the transaction wanting to commit phase 2
 * @param interestedResources a map of phase 1 prepared resources wanting to participate in phase 2 using Xids as keys
 * @throws HeuristicRollbackException when all resources committed instead.
 * @throws HeuristicMixedException when some resources committed and some rolled back.
 * @throws bitronix.tm.internal.BitronixSystemException when an internal error occured.
 * @throws bitronix.tm.internal.BitronixRollbackException during 1PC when resource fails to commit
 */
public void commit(BitronixTransaction transaction, List<XAResourceHolderState> interestedResources) throws HeuristicMixedException, HeuristicRollbackException, BitronixSystemException, BitronixRollbackException {
    XAResourceManager resourceManager = transaction.getResourceManager();
    if (resourceManager.size() == 0) {
        transaction.setStatus(Status.STATUS_COMMITTING); //TODO: there is a disk force here that could be avoided
        transaction.setStatus(Status.STATUS_COMMITTED);
        if (log.isDebugEnabled()) { log.debug("phase 2 commit succeeded with no interested resource"); }
        return;
    }

    transaction.setStatus(Status.STATUS_COMMITTING);

    this.interestedResources.clear();
    this.interestedResources.addAll(interestedResources);
    this.onePhase = resourceManager.size() == 1;

    try {
        executePhase(resourceManager, true);
    } catch (PhaseException ex) {
        logFailedResources(ex);
        if (onePhase) {
            transaction.setStatus(Status.STATUS_ROLLEDBACK);
            throw new BitronixRollbackException("transaction failed during 1PC commit of " + transaction, ex);
        } else {
            transaction.setStatus(Status.STATUS_UNKNOWN);
            throwException("transaction failed during commit of " + transaction, ex, interestedResources.size());
        }
    }

    if (log.isDebugEnabled()) { log.debug("phase 2 commit executed on resources " + Decoder.collectResourcesNames(committedResources)); }

    // Some resources might have failed the 2nd phase of 2PC.
    // Only resources which successfully committed should be registered in the journal, the other
    // ones should be picked up by the recoverer.
    // Not interested resources have to be included as well since they returned XA_RDONLY and they
    // don't participate in phase 2: the TX succeded for them.
    Set<String> committedAndNotInterestedUniqueNames = new HashSet<String>();
    committedAndNotInterestedUniqueNames.addAll(collectResourcesUniqueNames(committedResources));
    List<XAResourceHolderState> notInterestedResources = collectNotInterestedResources(resourceManager.getAllResources(), interestedResources);
    committedAndNotInterestedUniqueNames.addAll(collectResourcesUniqueNames(notInterestedResources));

    if (log.isDebugEnabled()) {
        List<XAResourceHolderState> committedAndNotInterestedResources = new ArrayList<XAResourceHolderState>();
        committedAndNotInterestedResources.addAll(committedResources);
        committedAndNotInterestedResources.addAll(notInterestedResources);

        log.debug("phase 2 commit succeeded on resources " + Decoder.collectResourcesNames(committedAndNotInterestedResources));
    }

    transaction.setStatus(Status.STATUS_COMMITTED, committedAndNotInterestedUniqueNames);
}
 
開發者ID:bitronix,項目名稱:btm,代碼行數:60,代碼來源:Committer.java


注:本文中的bitronix.tm.BitronixTransaction.setStatus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。