Example usage for javax.transaction Status STATUS_ROLLEDBACK

List of usage examples for javax.transaction Status STATUS_ROLLEDBACK

Introduction

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

Prototype

int STATUS_ROLLEDBACK

To view the source code for javax.transaction Status STATUS_ROLLEDBACK.

Click Source Link

Document

A transaction is associated with the target object and the outcome has been determined to be rollback.

Usage

From source file:org.bytesoft.bytejta.TransactionRecoveryImpl.java

private void recoverCoordinator(Transaction transaction)
        throws CommitRequiredException, RollbackRequiredException, SystemException {

    switch (transaction.getTransactionStatus()) {
    case Status.STATUS_ACTIVE:
    case Status.STATUS_MARKED_ROLLBACK:
    case Status.STATUS_PREPARING:
    case Status.STATUS_ROLLING_BACK:
    case Status.STATUS_UNKNOWN:
        transaction.recoveryRollback();//from w  ww. j av a 2  s. c o m
        transaction.forgetQuietly();
        break;
    case Status.STATUS_PREPARED:
    case Status.STATUS_COMMITTING:
        transaction.recoveryCommit();
        transaction.forgetQuietly();
        break;
    case Status.STATUS_COMMITTED:
    case Status.STATUS_ROLLEDBACK:
        transaction.forgetQuietly();
        break;
    default:
        logger.debug("Current transaction has already been completed.");
    }
}

From source file:org.bytesoft.bytejta.TransactionRecoveryImpl.java

private void recoverParticipant(Transaction transaction)
        throws CommitRequiredException, RollbackRequiredException, SystemException {

    TransactionImpl transactionImpl = (TransactionImpl) transaction;
    switch (transaction.getTransactionStatus()) {
    case Status.STATUS_PREPARED:
    case Status.STATUS_COMMITTING:
        break;/*from   w w w.j  a  v a 2  s  . c  o  m*/
    case Status.STATUS_COMMITTED:
    case Status.STATUS_ROLLEDBACK:
        break;
    case Status.STATUS_ACTIVE:
    case Status.STATUS_MARKED_ROLLBACK:
    case Status.STATUS_PREPARING:
    case Status.STATUS_UNKNOWN:
    case Status.STATUS_ROLLING_BACK:
    default:
        transactionImpl.recoveryRollback();
        transactionImpl.forgetQuietly();
    }
}

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

public synchronized void rollback() throws IllegalStateException, SystemException {
    CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger();

    this.transactionStatus = Status.STATUS_ROLLING_BACK;
    this.transactionContext.setCompensating(true);

    compensableLogger.updateTransaction(this.getTransactionArchive());

    boolean coordinator = this.transactionContext.isCoordinator();
    boolean coordinatorTried = false;
    for (int i = 0; coordinator && i < this.archiveList.size(); i++) {
        CompensableArchive compensableArchive = this.archiveList.get(i);
        coordinatorTried = compensableArchive.isTried() ? true : coordinatorTried;
    }/*from  w ww . j  av a  2  s  . com*/

    SystemException systemEx = null;
    if (coordinator == false || coordinatorTried) {
        try {
            this.fireNativeParticipantCancel();
        } catch (SystemException ex) {
            systemEx = ex;

            logger.info("{}| cancel native branchs failed!",
                    ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
        } catch (RuntimeException ex) {
            systemEx = new SystemException(ex.getMessage());

            logger.info("{}| cancel native branchs failed!",
                    ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
        }
    }

    try {
        this.fireRemoteParticipantCancel();
    } catch (SystemException ex) {
        logger.info("{}| cancel remote branchs failed!",
                ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
        throw ex;
    } catch (RuntimeException ex) {
        logger.info("{}| cancel remote branchs failed!",
                ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
        throw new SystemException(ex.getMessage());
    }

    if (systemEx != null) {
        throw systemEx;
    } else {
        this.transactionStatus = Status.STATUS_ROLLEDBACK;
        compensableLogger.updateTransaction(this.getTransactionArchive());
        logger.info("{}| compensable transaction rolled back!",
                ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()));
    }

}

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

public synchronized void recoveryRollback() throws RollbackRequiredException, SystemException {
    CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger();

    this.transactionStatus = Status.STATUS_ROLLING_BACK;
    this.transactionContext.setCompensating(true);
    compensableLogger.updateTransaction(this.getTransactionArchive());

    SystemException systemEx = null;
    try {/*from  w w w .  j  a  v  a2  s.c  o  m*/
        this.fireNativeParticipantRecoveryCancel();
    } catch (SystemException ex) {
        systemEx = ex;

        logger.info("{}| recovery-cancel native branchs failed!",
                ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
    } catch (RuntimeException ex) {
        systemEx = new SystemException(ex.getMessage());

        logger.info("{}| recovery-cancel native branchs failed!",
                ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
    }

    try {
        this.fireRemoteParticipantRecoveryCancel();
    } catch (SystemException ex) {
        logger.info("{}| recovery-cancel remote branchs failed!",
                ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
        throw ex;
    } catch (RuntimeException ex) {
        logger.info("{}| recovery-cancel remote branchs failed!",
                ByteUtils.byteArrayToString(this.transactionContext.getXid().getGlobalTransactionId()), ex);
        throw new SystemException(ex.getMessage());
    }

    if (systemEx != null) {
        throw systemEx;
    } else {
        this.transactionStatus = Status.STATUS_ROLLEDBACK;
        compensableLogger.updateTransaction(this.getTransactionArchive());
        logger.info("{}| compensable transaction recovery rolled back!",
                ByteUtils.byteArrayToString(transactionContext.getXid().getGlobalTransactionId()));
    }

}

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

private void recoverStatusIfNecessary(Transaction transaction) {
    CompensableTransactionImpl compensable = (CompensableTransactionImpl) transaction;
    List<CompensableArchive> archiveList = compensable.getCompensableArchiveList();

    XAResourceDeserializer resourceDeserializer = this.beanFactory.getResourceDeserializer();
    CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger();

    Map<TransactionBranchKey, Boolean> triedMap = new HashMap<TransactionBranchKey, Boolean>();
    for (int i = 0; i < archiveList.size(); i++) {
        CompensableArchive archive = archiveList.get(i);

        if (archive.isTried()) {
            switch (transaction.getTransactionStatus()) {
            case Status.STATUS_ACTIVE:
            case Status.STATUS_MARKED_ROLLBACK:
            case Status.STATUS_PREPARING:
            case Status.STATUS_ROLLING_BACK:
            case Status.STATUS_UNKNOWN:
                transaction.setTransactionStatus(Status.STATUS_PREPARED);
                transaction.getTransactionContext().setCompensating(true);
                compensableLogger.updateTransaction(compensable.getTransactionArchive());
                break;
            case Status.STATUS_PREPARED:
            case Status.STATUS_COMMITTING:
            case Status.STATUS_COMMITTED:
            case Status.STATUS_ROLLEDBACK:
            default:
                // ignore
            }/*from   ww w  .j a  v a2  s  .c om*/
        } else {
            Xid transactionXid = archive.getTransactionXid();
            String resourceKey = archive.getTransactionResourceKey();

            TransactionBranchKey recordKey = new TransactionBranchKey();
            recordKey.xid = transactionXid;
            recordKey.resource = resourceKey;

            if (StringUtils.isBlank(resourceKey)) {
                logger.warn(
                        "There is no valid resource participated in the trying branch transaction, the status of the branch transaction is unknown!");
            } else if (triedMap.containsKey(recordKey)) {
                Boolean tried = triedMap.get(recordKey);
                if (Boolean.TRUE.equals(tried)) {
                    transaction.setTransactionStatus(Status.STATUS_COMMITTING); // TODO
                } else {
                    transaction.setTransactionStatus(Status.STATUS_MARKED_ROLLBACK);
                }
                transaction.getTransactionContext().setCompensating(true);
                compensableLogger.updateTransaction(compensable.getTransactionArchive());
            } else {
                XAResource xares = resourceDeserializer.deserialize(resourceKey);
                if (RecoveredResource.class.isInstance(xares)) {
                    RecoveredResource resource = (RecoveredResource) xares;
                    try {
                        resource.recoverable(archive.getTransactionXid());
                        archive.setTried(true);
                        triedMap.put(recordKey, Boolean.TRUE);

                        transaction.setTransactionStatus(Status.STATUS_COMMITTING); // TODO
                        transaction.getTransactionContext().setCompensating(true);
                        compensableLogger.updateTransaction(compensable.getTransactionArchive());
                    } catch (XAException xaex) {
                        switch (xaex.errorCode) {
                        case XAException.XAER_NOTA:
                            triedMap.put(recordKey, Boolean.FALSE);

                            transaction.setTransactionStatus(Status.STATUS_MARKED_ROLLBACK);
                            transaction.getTransactionContext().setCompensating(true);
                            compensableLogger.updateTransaction(compensable.getTransactionArchive());
                            break;
                        case XAException.XAER_RMERR:
                            logger.warn(
                                    "The database table 'bytejta' cannot found, the status of the trying branch transaction is unknown!");
                            break;
                        case XAException.XAER_RMFAIL:
                            logger.error("Error occurred while recovering the branch transaction service: {}",
                                    ByteUtils.byteArrayToString(transactionXid.getGlobalTransactionId()), xaex);
                            break;
                        default:
                            logger.error(
                                    "Illegal state, the status of the trying branch transaction is unknown!");
                        }
                    }
                } else {
                    logger.error("Illegal resources, the status of the trying branch transaction is unknown!");
                }
            }
        } // end-else-if (archive.isTried())
    } // end-for
}

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

public synchronized void recoverCoordinator(Transaction transaction)
        throws CommitRequiredException, RollbackRequiredException, SystemException {

    switch (transaction.getTransactionStatus()) {
    case Status.STATUS_ACTIVE:
    case Status.STATUS_MARKED_ROLLBACK:
    case Status.STATUS_PREPARING:
    case Status.STATUS_ROLLING_BACK:
    case Status.STATUS_UNKNOWN:
        transaction.recoveryRollback();// w  ww.ja v a  2  s.c o m
        transaction.recoveryForget();
        break;
    case Status.STATUS_PREPARED:
    case Status.STATUS_COMMITTING:
        transaction.recoveryCommit();
        transaction.recoveryForget();
        break;
    case Status.STATUS_COMMITTED:
    case Status.STATUS_ROLLEDBACK:
    default:
        // ignore
    }

}

From source file:org.castor.persist.AbstractTransactionContext.java

/**
 * {@inheritDoc}//w  w w .j  a  v  a 2 s .c  o  m
 * @see org.castor.persist.TransactionContext#rollback()
 */
public final synchronized void rollback() {
    if (_status != Status.STATUS_ACTIVE && _status != Status.STATUS_PREPARED
            && _status != Status.STATUS_MARKED_ROLLBACK) {
        throw new IllegalStateException(Messages.message("persist.noTransaction"));
    }

    // Go through all the connections opened in this transaction,
    // rollback and close them one by one.
    rollbackConnections();

    // un-delete object first
    _tracker.unmarkAllDeleted();

    // Clean the transaction locks with regards to the database engine.
    Collection readWriteObjects = _tracker.getReadWriteObjects();
    OID oid = null;
    try {
        Iterator it = readWriteObjects.iterator();
        // First revert all objects
        while (it.hasNext()) {
            Object object = it.next();
            LockEngine engine = _tracker.getMolderForObject(object).getLockEngine();
            oid = _tracker.getOIDForObject(object);
            if (!_tracker.isCreating(object)) {
                engine.revertObject(this, oid, object);
            }
        }

        // then forget object or release lock on them
        it = readWriteObjects.iterator();
        while (it.hasNext()) {
            Object object = it.next();
            ClassMolder molder = _tracker.getMolderForObject(object);
            LockEngine engine = molder.getLockEngine();
            oid = _tracker.getOIDForObject(object);

            if (!_tracker.isCreating(object)) {
                if (_tracker.isCreated(object)) {
                    // Object has been created in this transaction,
                    // it no longer exists, forget about it in the engine.
                    engine.forgetObject(this, oid);
                } else {
                    // Object has been queried (possibly) deleted in this
                    // transaction and release the lock.
                    engine.releaseLock(this, oid);
                }
            }

            if (_callback != null) {
                _callback.releasing(object, false);
            } else if (molder.getCallback() != null) {
                molder.getCallback().releasing(object, false);
            }
        }
    } catch (Exception except) {
        // Don't thow exceptions during a rollback. Just report them.
        LOG.error("Caught exception at rollback of object with OID " + oid, except);
    }

    // Forget about all the objects in this transaction,
    // and mark it as completed.
    _tracker.clear();
    txrolledback();
    _status = Status.STATUS_ROLLEDBACK;
}

From source file:org.compass.core.transaction.AbstractJTATransaction.java

public boolean wasRolledBack() throws TransactionException {

    if (!isBegun())
        return false;
    if (commitFailed)
        return true;

    final int status;
    try {//from   w ww.ja va2s  .co  m
        status = ut.getStatus();
    } catch (SystemException se) {
        throw new TransactionException("Could not determine transaction status", se);
    }
    if (status == Status.STATUS_UNKNOWN) {
        throw new TransactionException("Could not determine transaction status");
    } else {
        return status == Status.STATUS_MARKED_ROLLBACK || status == Status.STATUS_ROLLING_BACK
                || status == Status.STATUS_ROLLEDBACK;
    }
}

From source file:org.eclipse.ecr.core.api.TransactionalCoreSessionWrapper.java

@Override
public void afterCompletion(int status) {
    threadBound.remove();//from   w  w  w.j av  a 2 s .  c  om
    boolean committed;
    if (status == Status.STATUS_COMMITTED) {
        committed = true;
    } else if (status == Status.STATUS_ROLLEDBACK) {
        committed = false;
    } else {
        log.error("Unexpected status after completion: " + status);
        return;
    }
    session.afterCompletion(committed);
}

From source file:org.etk.entity.engine.plugins.transaction.TransactionUtil.java

public static String getTransactionStateString(int state) {
    /*//from   w w  w  . j a v a 2s  .  co  m
     * javax.transaction.Status STATUS_ACTIVE 0 STATUS_MARKED_ROLLBACK 1
     * STATUS_PREPARED 2 STATUS_COMMITTED 3 STATUS_ROLLEDBACK 4 STATUS_UNKNOWN 5
     * STATUS_NO_TRANSACTION 6 STATUS_PREPARING 7 STATUS_COMMITTING 8
     * STATUS_ROLLING_BACK 9
     */
    switch (state) {
    case Status.STATUS_ACTIVE:
        return "Transaction Active (" + state + ")";
    case Status.STATUS_COMMITTED:
        return "Transaction Committed (" + state + ")";
    case Status.STATUS_COMMITTING:
        return "Transaction Committing (" + state + ")";
    case Status.STATUS_MARKED_ROLLBACK:
        return "Transaction Marked Rollback (" + state + ")";
    case Status.STATUS_NO_TRANSACTION:
        return "No Transaction (" + state + ")";
    case Status.STATUS_PREPARED:
        return "Transaction Prepared (" + state + ")";
    case Status.STATUS_PREPARING:
        return "Transaction Preparing (" + state + ")";
    case Status.STATUS_ROLLEDBACK:
        return "Transaction Rolledback (" + state + ")";
    case Status.STATUS_ROLLING_BACK:
        return "Transaction Rolling Back (" + state + ")";
    case Status.STATUS_UNKNOWN:
        return "Transaction Status Unknown (" + state + ")";
    default:
        return "Not a valid state code (" + state + ")";
    }
}