Example usage for javax.transaction Status STATUS_UNKNOWN

List of usage examples for javax.transaction Status STATUS_UNKNOWN

Introduction

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

Prototype

int STATUS_UNKNOWN

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

Click Source Link

Document

A transaction is associated with the target object but its current status cannot be determined.

Usage

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 ww  . j  ava  2s .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.TransactionRecoveryImpl.java

private void fireCompensableStartRecovery() {
    final TransactionRepository transactionRepository = this.beanFactory.getCompensableRepository();
    CompensableLogger compensableLogger = this.beanFactory.getCompensableLogger();

    compensableLogger.recover(new TransactionRecoveryCallback() {
        public void recover(TransactionArchive archive) {
            this.recover((org.bytesoft.compensable.archive.TransactionArchive) archive);
        }//from  w  ww  .ja  v a2s  .co m

        public void recover(org.bytesoft.compensable.archive.TransactionArchive archive) {
            XidFactory transactionXidFactory = beanFactory.getTransactionXidFactory();

            CompensableTransactionImpl transaction = reconstructTransaction(archive);
            TransactionContext transactionContext = transaction.getTransactionContext();

            TransactionXid compensableXid = transactionContext.getXid();
            if (transactionContext.isCompensable()) {
                switch (transaction.getTransactionStatus()) {
                case Status.STATUS_ACTIVE:
                case Status.STATUS_MARKED_ROLLBACK:
                case Status.STATUS_PREPARING:
                case Status.STATUS_UNKNOWN:
                    recoverStatusIfNecessary(transaction);
                    break;
                default: // ignore
                }
            } else {
                TransactionXid transactionXid = transactionXidFactory
                        .createGlobalXid(compensableXid.getGlobalTransactionId());
                Transaction tx = recovered.get(transactionXid);
                if (tx != null) {
                    tx.setTransactionalExtra(transaction);
                    transaction.setTransactionalExtra(tx);
                }
            } // end-if (transactionContext.isCompensable())

            transactionRepository.putTransaction(compensableXid, transaction);
            transactionRepository.putErrorTransaction(compensableXid, transaction);
        }
    });
}

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   w ww  .  j a  v a2s  .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();//from  w  ww  . j  ava2s.  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.compass.core.transaction.AbstractJTATransaction.java

public boolean wasRolledBack() throws TransactionException {

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

    final int status;
    try {//from  ww w  .  j  ava 2  s  .  c om
        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.compass.core.transaction.AbstractJTATransaction.java

public boolean wasCommitted() throws TransactionException {

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

    final int status;
    try {/*from w  w  w .  j a v  a 2s. c  o  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_COMMITTED;
    }
}

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

public static String getTransactionStateString(int state) {
    /*/*from w  ww .j  ava 2 s.  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 + ")";
    }
}

From source file:org.exolab.castor.jdo.engine.GlobalDatabaseImpl.java

/**
 * @inheritDoc//from   ww  w  .  j  a  v  a2  s  .  c  om
 * @see javax.transaction.Synchronization#afterCompletion(int)
 */
public void afterCompletion(final int status) {
    try {
        // XXX [SMH]: Find another test for txNotInProgress
        if (_transaction == null || _ctx == null) {
            throw new IllegalStateException(Messages.message("jdo.txNotInProgress"));
        }
        if (_ctx.getStatus() == Status.STATUS_ROLLEDBACK) {
            return;
        }
        if (_ctx.getStatus() != Status.STATUS_PREPARED && status != Status.STATUS_ROLLEDBACK) {
            throw new IllegalStateException(
                    "Unexpected state: afterCompletion called at status " + _ctx.getStatus());
        }
        switch (status) {
        case Status.STATUS_COMMITTED:
            try {
                _ctx.commit();
            } catch (TransactionAbortedException except) {
                _log.fatal(Messages.format("jdo.fatalException", except));
                _ctx.rollback();
            }
            return;
        case Status.STATUS_ROLLEDBACK:
            _ctx.rollback();
            return;
        case Status.STATUS_UNKNOWN:
            _ctx.rollback();
            try {
                DatabaseContext context = DatabaseRegistry.getDatabaseContext(_dbName);
                TransactionManager transactionManager = context.getTransactionManager();
                if (AtomikosTransactionManagerFactory.MANAGER_CLASS_NAME
                        .equals(transactionManager.getClass().getName())) {
                    // Accept 'unknown' as legal state for Atomikos as this state
                    // is returned for read-only transactions. As nothing has changed
                    // during the transaction it doesn't matter if we do a commit or
                    // rollback. The handling of 'unknown' does not comply to J2EE spec.
                    return;
                }
            } catch (Exception ex) {
                _log.fatal(Messages.format("jdo.fatalException", ex));
            }
            throw new IllegalStateException("Unexpected state: afterCompletion called with status " + status);
        default:
            _ctx.rollback();
            throw new IllegalStateException("Unexpected state: afterCompletion called with status " + status);
        }
    } finally {
        unregisterSynchronizables();

        if (_txMap != null && _transaction != null) {
            _txMap.remove(_transaction);
            _txMap = null;
        }
    }
}

From source file:org.hibernate.shards.transaction.ShardedTransactionImpl.java

public void commit() throws HibernateException {
    if (!begun) {
        throw new TransactionException("Transaction not succesfully started");
    }/*  w  w  w .java 2 s.c  o m*/
    log.debug("Starting transaction commit");
    beforeTransactionCompletion();
    boolean commitException = false;
    HibernateException firstCommitException = null;
    for (Transaction t : transactions) {
        try {
            t.commit();
        } catch (HibernateException he) {
            log.warn("exception commiting underlying transaction", he);
            commitException = true;
            // we're only going to rethrow the first commit exception we receive
            if (firstCommitException == null) {
                firstCommitException = he;
            }
        }
    }
    if (commitException) {
        commitFailed = true;
        afterTransactionCompletion(Status.STATUS_UNKNOWN);
        throw new TransactionException("Commit failed", firstCommitException);
    }
    afterTransactionCompletion(Status.STATUS_COMMITTED);
    committed = true;
}

From source file:org.hibernate.transaction.JTATransaction.java

public boolean wasRolledBack() throws TransactionException {

    //if (!begun) return false;
    //if (commitFailed) return true;

    final int status;
    try {//w ww  .  j  a  va2  s  .  com
        status = userTransaction.getStatus();
    } catch (SystemException se) {
        log.error("Could not determine transaction status", 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 JTAHelper.isRollback(status);
    }
}