Example usage for javax.transaction.xa XAException XA_HEURMIX

List of usage examples for javax.transaction.xa XAException XA_HEURMIX

Introduction

In this page you can find the example usage for javax.transaction.xa XAException XA_HEURMIX.

Prototype

int XA_HEURMIX

To view the source code for javax.transaction.xa XAException XA_HEURMIX.

Click Source Link

Document

The transaction branch has been heuristically committed and rolled back.

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;//w w w .j  a  v  a2  s  .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;//from   w  ww  .  ja va  2  s. c  o 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.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();
    }

}