Example usage for javax.transaction Status STATUS_PREPARED

List of usage examples for javax.transaction Status STATUS_PREPARED

Introduction

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

Prototype

int STATUS_PREPARED

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

Click Source Link

Document

A transaction is associated with the target object and it has been prepared.

Usage

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

/**
 * @inheritDoc/*w w  w  .j  a v a 2s  .co m*/
 * @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.j2free.jpa.Controller.java

/**
 * /*from w w  w . j a  v  a2  s  .  c  om*/
 * @return
 * @throws SystemException
 */
public String getTransactionStatus() throws SystemException {
    if (tx == null) {
        return "Null transaction";
    }

    switch (tx.getStatus()) {
    case Status.STATUS_ACTIVE:
        return "Active";
    case Status.STATUS_COMMITTED:
        return "Committed";
    case Status.STATUS_COMMITTING:
        return "Committing";
    case Status.STATUS_MARKED_ROLLBACK:
        return "Marked for rollback";
    case Status.STATUS_NO_TRANSACTION:
        return "No Transaction";
    case Status.STATUS_PREPARED:
        return "Prepared";
    case Status.STATUS_ROLLEDBACK:
        return "Rolledback";
    case Status.STATUS_ROLLING_BACK:
        return "Rolling back";
    case Status.STATUS_UNKNOWN:
        return "Declared Unknown";
    default:
        return "Undeclared Unknown Status";
    }
}

From source file:org.mule.util.xa.AbstractResourceManager.java

public int prepareTransaction(AbstractTransactionContext context) throws ResourceManagerException {
    assureReady();//from   w ww .j  a v  a  2 s .  c  o m
    synchronized (context) {
        if (logger.isDebugEnabled()) {
            logger.debug("Preparing transaction " + context);
        }
        context.status = Status.STATUS_PREPARING;
        int status = doPrepare(context);
        context.status = Status.STATUS_PREPARED;
        if (logger.isDebugEnabled()) {
            logger.debug("Prepared transaction " + context);
        }
        return status;
    }
}

From source file:org.mule.util.xa.DefaultXASession.java

public void commit(Xid xid, boolean onePhase) throws XAException {
    if (xid == null) {
        throw new XAException(XAException.XAER_PROTO);
    }//from   w w w .ja  v  a  2s.c  o m
    AbstractTransactionContext context = resourceManager.getActiveTransactionalResource(xid);
    if (context == null) {
        throw new XAException(XAException.XAER_NOTA);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Committing transaction branch " + xid);
    }
    if (context.status == Status.STATUS_MARKED_ROLLBACK) {
        throw new XAException(XAException.XA_RBROLLBACK);
    }

    try {
        if (context.status != Status.STATUS_PREPARED) {
            if (onePhase) {
                resourceManager.prepareTransaction(context);
            } else {
                throw new XAException(XAException.XAER_PROTO);
            }
        }
        resourceManager.commitTransaction(context);
    } catch (ResourceManagerException e) {
        throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e);
    }
    resourceManager.removeActiveTransactionalResource(xid);
    resourceManager.removeSuspendedTransactionalResource(xid);
}