Example usage for javax.transaction Status STATUS_MARKED_ROLLBACK

List of usage examples for javax.transaction Status STATUS_MARKED_ROLLBACK

Introduction

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

Prototype

int STATUS_MARKED_ROLLBACK

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

Click Source Link

Document

A transaction is associated with the target object and it has been marked for rollback, perhaps as a result of a setRollbackOnly operation.

Usage

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

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Boolean b = threadBound.get();
    if (b == null) {
        // first call in thread
        try {/* ww  w.  j  a  v a  2  s .co m*/
            Transaction tx = TransactionHelper.lookupTransactionManager().getTransaction();
            if (tx != null && tx.getStatus() != Status.STATUS_MARKED_ROLLBACK) {
                tx.registerSynchronization(this);
                session.afterBegin();
                threadBound.set(Boolean.TRUE);
            }
        } catch (NamingException e) {
            // no transaction manager, ignore
        } catch (Exception e) {
            log.error("Error on transaction synchronizer registration", e);
        }
    }
    try {
        return method.invoke(session, args);
    } catch (Throwable t) {
        if (TransactionHelper.isTransactionActive() && needsRollback(method, t)) {
            TransactionHelper.setTransactionRollbackOnly();
        }
        if (t instanceof InvocationTargetException) {
            Throwable tt = ((InvocationTargetException) t).getTargetException();
            if (tt != null) {
                throw tt;
            }
        }
        throw t;
    }
}

From source file:org.eclipse.ecr.runtime.transaction.TransactionHelper.java

/**
 * Checks if the current User Transaction is marked rollback only.
 *///from ww  w. ja  v  a 2  s . co  m
public static boolean isTransactionMarkedRollback() {
    try {
        return lookupUserTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.eclipse.ecr.runtime.transaction.TransactionHelper.java

/**
 * Checks if the current User Transaction is active or marked rollback only.
 *//* w ww .  j  av a2  s.c o m*/
public static boolean isTransactionActiveOrMarkedRollback() {
    try {
        int status = lookupUserTransaction().getStatus();
        return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.eclipse.ecr.runtime.transaction.TransactionHelper.java

/**
 * Commits or rolls back the User Transaction depending on the transaction
 * status./*from ww  w . j  a va 2s  . co  m*/
 *
 * @throws SystemException
 * @throws HeuristicRollbackException
 * @throws HeuristicMixedException
 * @throws RollbackException
 * @throws IllegalStateException
 * @throws SecurityException
 */
public static void commitOrRollbackTransaction() {
    UserTransaction ut;
    try {
        ut = lookupUserTransaction();
    } catch (NamingException e) {
        log.warn("No user transaction", e);
        return;
    }
    try {
        int status = ut.getStatus();
        if (status == Status.STATUS_ACTIVE) {
            if (log.isDebugEnabled()) {
                log.debug("Commiting transaction");
            }
            ut.commit();
        } else if (status == Status.STATUS_MARKED_ROLLBACK) {
            if (log.isDebugEnabled()) {
                log.debug("Cannot commit transaction because it is marked rollback only");
            }
            ut.rollback();
        }
    } catch (Exception e) {
        String msg = "Unable to commit/rollback  " + ut;
        if (e instanceof RollbackException
                && "Unable to commit: transaction marked for rollback".equals(e.getMessage())) {
            // don't log as error, this happens if there's a
            // ConcurrentModificationException at transaction end inside VCS
            log.debug(msg, e);
        } else {
            log.error(msg, e);
        }
        throw new TransactionRuntimeException(msg, e);
    }
}

From source file:org.efaps.db.Context.java

/**
 * Is the status of transaction manager marked roll back?
 *
 * @return <i>true</i> if transaction manager is marked roll back, otherwise
 *         <i>false</i>//from  ww  w  .  j  av a  2s.c  om
 * @throws EFapsException if the status of the transaction manager could not
 *             be evaluated
 * @see #TRANSMANAG
 */
public static boolean isTMMarkedRollback() throws EFapsException {
    try {
        return Context.TRANSMANAG.getStatus() == Status.STATUS_MARKED_ROLLBACK;
    } catch (final SystemException e) {
        throw new EFapsException(Context.class, "isTMMarkedRollback.SystemException", e);
    }
}

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

/**
 * Begins a transaction in the current thread IF transactions are available;
 * only tries if the current transaction status is ACTIVE, if not active it
 * returns false. If and on only if it begins a transaction it will return
 * true. In other words, if a transaction is already in place it will return
 * false and do nothing.//w ww  .  ja  va2s.c  o  m
 */
public static boolean begin(int timeout) throws GenericTransactionException {
    UserTransaction ut = TransactionFactory.getUserTransaction();
    if (ut != null) {
        try {
            int currentStatus = ut.getStatus();
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "[TransactionUtil.begin] current status : " + getTransactionStateString(currentStatus));
            }
            if (currentStatus == Status.STATUS_ACTIVE) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "[TransactionUtil.begin] active transaction in place, so no transaction begun");
                }
                return false;
            } else if (currentStatus == Status.STATUS_MARKED_ROLLBACK) {
                Exception e = getTransactionBeginStack();
                if (e != null) {
                    logger.warn(
                            "[TransactionUtil.begin] active transaction marked for rollback in place, so no transaction begun; this stack trace shows when the exception began: ",
                            e);
                } else {
                    logger.warn(
                            "[TransactionUtil.begin] active transaction marked for rollback in place, so no transaction begun");
                }

                RollbackOnlyCause roc = getSetRollbackOnlyCause();
                // do we have a cause? if so, throw special exception
                if (roc != null && !roc.isEmpty()) {
                    throw new GenericTransactionException(
                            "The current transaction is marked for rollback, not beginning a new transaction and aborting current operation; the rollbackOnly was caused by: "
                                    + roc.getCauseMessage(),
                            roc.getCauseThrowable());
                } else {
                    return false;
                }
            }

            internalBegin(ut, timeout);

            // reset the transaction stamps, just in case...
            clearTransactionStamps();
            // initialize the start stamp
            getTransactionStartStamp();
            // set the tx begin stack placeholder
            setTransactionBeginStack();

            // initialize the debug resource
            if (debugResources) {
                DebugXaResource dxa = new DebugXaResource();
                try {
                    dxa.enlist();
                } catch (XAException e) {
                    logger.error(e.getMessage(), e);
                }
            }

            return true;
        } catch (NotSupportedException e) {
            // This is Java 1.4 only, but useful for certain debuggins: Throwable t
            // = e.getCause() == null ? e : e.getCause();
            throw new GenericTransactionException(
                    "Not Supported error, could not begin transaction (probably a nesting problem)", e);
        } catch (SystemException e) {
            // This is Java 1.4 only, but useful for certain debuggins: Throwable t
            // = e.getCause() == null ? e : e.getCause();
            throw new GenericTransactionException("System error, could not begin transaction", e);
        }
    } else {
        if (logger.isInfoEnabled())
            logger.info("[TransactionUtil.begin] no user transaction, so no transaction begun");
        return false;
    }
}

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

public static String getTransactionStateString(int state) {
    /*/*from   w  w w.ja  va2  s .c o 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  w  w  w  .  ja v  a  2 s  .  c  om
 */
public void beforeCompletion() {
    // XXX [SMH]: Find another test for txNotInProgress
    if (_transaction == null || _ctx == null || !_ctx.isOpen()) {
        throw new IllegalStateException(Messages.message("jdo.txNotInProgress"));
    }

    registerSynchronizables();

    if (_ctx.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
        try {
            _transaction.setRollbackOnly();
        } catch (SystemException except) {
            _log.warn(Messages.format("jdo.warnException", except));
        }
        return;
    }
    try {
        _ctx.prepare();
    } catch (TransactionAbortedException tae) {
        _log.error(Messages.format("jdo.txAbortedMarkRollback", tae.getMessage()), tae);
        try {
            _transaction.setRollbackOnly();
        } catch (SystemException se) {
            _log.fatal(Messages.format("jdo.txMarkRollbackFailure", se.getMessage()), se);
        }
        _ctx.rollback();
    }
}

From source file:org.j2free.jpa.Controller.java

/**
 * Ends the contatiner managed <tt>UserTransaction</tt>, committing
 * or rolling back as necessary./*w ww . j  a v  a  2 s .  co  m*/
 *
 * @throws SystemException
 * @throws RollbackException
 * @throws HeuristicMixedException
 * @throws HeuristicRollbackException
 */
public void end()
        throws SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
    try {
        switch (tx.getStatus()) {
        case Status.STATUS_MARKED_ROLLBACK:
            tx.rollback();
            break;
        case Status.STATUS_ACTIVE:
            tx.commit();
            break;
        case Status.STATUS_COMMITTED:
            // somebody called end() twice
            break;
        case Status.STATUS_COMMITTING:
            log.warn("uh oh, concurrency problem! end() called when transaction already committing");
            break;
        case Status.STATUS_ROLLEDBACK:
            // somebody called end() twice
            break;
        case Status.STATUS_ROLLING_BACK:
            log.warn("uh oh, concurrency problem! end() called when transaction already rolling back");
            break;
        default:
            throw new IllegalStateException("Unknown status in endTransaction: " + getTransactionStatus());
        }

        problem = null;
        errors = null;
    } catch (InvalidStateException ise) {
        problem = ise;
        this.errors = ise.getInvalidValues();
    }
}

From source file:org.j2free.jpa.Controller.java

/**
 * @return true if the current transaction has been
 *         marked for rollback, otherwise false
 *///from  www  .  ja  v a  2s . co m
public boolean isMarkedForRollback() {
    try {
        return tx.getStatus() == Status.STATUS_MARKED_ROLLBACK;
    } catch (Exception e) {
        throw LaunderThrowable.launderThrowable(e);
    }
}