当前位置: 首页>>代码示例>>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;未经允许,请勿转载。