Example usage for javax.transaction HeuristicMixedException HeuristicMixedException

List of usage examples for javax.transaction HeuristicMixedException HeuristicMixedException

Introduction

In this page you can find the example usage for javax.transaction HeuristicMixedException HeuristicMixedException.

Prototype

public HeuristicMixedException() 

Source Link

Usage

From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java

private synchronized void fireRemoteParticipantConfirm()
        throws HeuristicMixedException, HeuristicRollbackException, SystemException {
    boolean commitExists = false;
    boolean rollbackExists = false;
    boolean errorExists = false;

    for (int i = 0; i < this.resourceList.size(); i++) {
        XAResourceArchive current = this.resourceList.get(i);
        if (current.isCommitted()) {
            commitExists = true;/*from w ww  .j  a  v  a2s  .  co m*/
            continue;
        }

        CompensableLogger transactionLogger = this.beanFactory.getCompensableLogger();
        XidFactory xidFactory = this.beanFactory.getCompensableXidFactory();
        TransactionXid branchXid = (TransactionXid) current.getXid();
        TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId());
        try {
            current.commit(globalXid, true);
            commitExists = true;

            current.setCommitted(true);
            current.setCompleted(true);
            transactionLogger.updateCoordinator(current);

            logger.info("{}| confirm remote branch: {}",
                    ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()),
                    current.getDescriptor().getIdentifier());
        } catch (XAException ex) {
            switch (ex.errorCode) {
            case XAException.XAER_NOTA:
                logger.warn("{}| error occurred while confirming remote branch: {}, transaction is not exists!",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()),
                        current.getDescriptor().getIdentifier());
                break;
            case XAException.XA_HEURCOM:
                commitExists = true;

                current.setCommitted(true);
                current.setHeuristic(false);
                current.setCompleted(true);
                transactionLogger.updateCoordinator(current);

                logger.info("{}| confirm remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()),
                        current.getDescriptor().getIdentifier());
                break;
            case XAException.XA_HEURRB:
                rollbackExists = true;

                current.setRolledback(true);
                current.setHeuristic(false);
                current.setCompleted(true);
                transactionLogger.updateCoordinator(current);

                logger.error("{}| error occurred while confirming remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, ex);
                break;
            case XAException.XA_HEURMIX:
                // should never happen
                commitExists = true;
                rollbackExists = true;

                current.setHeuristic(true);
                // current.setCommitted(true);
                // current.setRolledback(true);
                // current.setCompleted(true);
                transactionLogger.updateCoordinator(current);

                logger.error("{}| error occurred while confirming remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, ex);
                break;
            default:
                errorExists = false;
                logger.error("{}| error occurred while confirming remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, ex);
            }

        } catch (RuntimeException rex) {
            errorExists = false;
            logger.error("{}| error occurred while confirming branch: {}",
                    ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), this.archive, rex);
        }
    }

    if (commitExists && rollbackExists) {
        throw new HeuristicMixedException();
    } else if (rollbackExists) {
        throw new HeuristicRollbackException();
    } else if (errorExists) {
        throw new SystemException();
    }

}

From source file:org.bytesoft.bytetcc.CompensableTransactionImpl.java

private synchronized void fireRemoteParticipantRecoveryConfirm()
        throws HeuristicMixedException, HeuristicRollbackException, SystemException {
    boolean commitExists = false;
    boolean rollbackExists = false;
    boolean errorExists = false;

    for (int i = 0; i < this.resourceList.size(); i++) {
        XAResourceArchive current = this.resourceList.get(i);
        if (current.isCommitted()) {
            commitExists = true;//  www .j  av  a  2  s .  c  om
            continue;
        }

        CompensableLogger transactionLogger = this.beanFactory.getCompensableLogger();
        XidFactory xidFactory = this.beanFactory.getCompensableXidFactory();
        TransactionXid branchXid = (TransactionXid) current.getXid();
        TransactionXid globalXid = xidFactory.createGlobalXid(branchXid.getGlobalTransactionId());
        try {
            current.recoveryCommit(globalXid);
            commitExists = true;

            current.setCommitted(true);
            current.setCompleted(true);
            transactionLogger.updateCoordinator(current);

            logger.info("{}| recovery-confirm remote branch: {}",
                    ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()),
                    current.getDescriptor().getIdentifier());
        } catch (XAException ex) {
            switch (ex.errorCode) {
            case XAException.XAER_NOTA:
                logger.warn("{}| error occurred while confirming remote branch: {}, transaction is not exists!",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()),
                        current.getDescriptor().getIdentifier());
                break;
            case XAException.XA_HEURCOM:
                current.setCommitted(true);
                current.setHeuristic(false);
                current.setCompleted(true);
                transactionLogger.updateCoordinator(current);

                logger.info("{}| recovery-confirm remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()),
                        current.getDescriptor().getIdentifier());
                break;
            case XAException.XA_HEURRB:
                rollbackExists = true;

                current.setRolledback(true);
                current.setHeuristic(false);
                current.setCompleted(true);
                transactionLogger.updateCoordinator(current);

                logger.error("{}| error occurred while confirming remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex);
                break;
            case XAException.XA_HEURMIX:
                commitExists = true;
                rollbackExists = true;

                current.setHeuristic(true);
                // current.setCommitted(true);
                // current.setRolledback(true);
                // current.setCompleted(true);
                transactionLogger.updateCoordinator(current);

                logger.error("{}| error occurred while confirming remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex);
                break;
            default:
                errorExists = false;
                logger.error("{}| error occurred while confirming remote branch: {}",
                        ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, ex);
            }

        } catch (RuntimeException rex) {
            errorExists = false;
            logger.error("{}| error occurred while confirming remote branch: {}",
                    ByteUtils.byteArrayToString(branchXid.getGlobalTransactionId()), current, rex);
        }
    }

    if (commitExists && rollbackExists) {
        throw new HeuristicMixedException();
    } else if (rollbackExists) {
        throw new HeuristicRollbackException();
    } else if (errorExists) {
        throw new SystemException();
    }

}