Example usage for javax.transaction Status STATUS_COMMITTED

List of usage examples for javax.transaction Status STATUS_COMMITTED

Introduction

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

Prototype

int STATUS_COMMITTED

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

Click Source Link

Document

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

Usage

From source file:org.apache.ode.bpel.engine.Contexts.java

public void registerCommitSynchronizer(final Runnable runnable) {
    try {//from  w  w w.j  a  v a2s .  com
        txManager.getTransaction().registerSynchronization(new Synchronization() {

            public void afterCompletion(int status) {
                if (status == Status.STATUS_COMMITTED)
                    runnable.run();
            }

            public void beforeCompletion() {

            }

        });
    } catch (Exception ex) {
        throw new BpelEngineException("Error registering synchronizer.", ex);
    }
}

From source file:org.apache.ode.daohib.JotmTransaction.java

private void afterCommitRollback() throws TransactionException {

    begun = false;/*ww w  . j  a v a 2  s .com*/
    // this method is a noop if there is a Synchronization!
    if (callback) {
        if (!newTransaction) {
            log.warn("You should set hibernate.transaction.manager_lookup_class if cache is enabled");
        }
        int status = NULL;
        try {
            status = userTransaction.getStatus();
        } catch (Exception e) {
            log.error("Could not determine transaction status after commit", e);
            throw new TransactionException("Could not determine transaction status after commit", e);
        } finally {
            jdbcContext.afterTransactionCompletion(status == Status.STATUS_COMMITTED, this);
        }
    }
}

From source file:org.apache.ode.daohib.JotmTransaction.java

/**
 * {@inheritDoc}//from w w w . j a va  2s  . co m
 */
public boolean wasCommitted() throws TransactionException {
    final int status;
    try {
        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 status == Status.STATUS_COMMITTED;
    }
}

From source file:org.apache.ode.il.MockScheduler.java

public void registerSynchronizer(final Synchronizer synch) throws ContextException {
    if (_txm != null) {
        try {// w w  w  . ja va 2  s  . c  om
            _txm.getTransaction().registerSynchronization(new Synchronization() {
                public void beforeCompletion() {
                    synch.beforeCompletion();
                }

                public void afterCompletion(int status) {
                    synch.afterCompletion(status == Status.STATUS_COMMITTED);
                }
            });
        } catch (Exception e) {
            __log.error("Exception in mock scheduler sync registration.", e);
            throw new RuntimeException(e);
        }
    } else {
        _synchros.get().add(synch);
    }
}

From source file:org.apache.ode.scheduler.simple.SimpleScheduler.java

public void registerSynchronizer(final Synchronizer synch) throws ContextException {
    TransactionManager txm = _txm;/*w  ww.j a v  a  2  s .  c om*/
    if (txm == null) {
        throw new ContextException("Cannot locate the transaction manager; the server might be shutting down.");
    }

    try {
        txm.getTransaction().registerSynchronization(new Synchronization() {

            public void beforeCompletion() {
                synch.beforeCompletion();
            }

            public void afterCompletion(int status) {
                synch.afterCompletion(status == Status.STATUS_COMMITTED);
            }

        });
    } catch (Exception e) {
        throw new ContextException("Unable to register synchronizer.", e);
    }
}

From source file:org.apache.ofbiz.entity.transaction.TransactionUtil.java

public static String getTransactionStateString(int state) {
    /*/*from   w ww .ja v a  2 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.apache.ojb.odmg.JTATxManager.java

private static String getStatusString(int status) {
    switch (status) {
    case Status.STATUS_ACTIVE:
        return "STATUS_ACTIVE";
    case Status.STATUS_COMMITTED:
        return "STATUS_COMMITTED";
    case Status.STATUS_COMMITTING:
        return "STATUS_COMMITTING";
    case Status.STATUS_MARKED_ROLLBACK:
        return "STATUS_MARKED_ROLLBACK";
    case Status.STATUS_NO_TRANSACTION:
        return "STATUS_NO_TRANSACTION";
    case Status.STATUS_PREPARED:
        return "STATUS_PREPARED";
    case Status.STATUS_PREPARING:
        return "STATUS_PREPARING";
    case Status.STATUS_ROLLEDBACK:
        return "STATUS_ROLLEDBACK";
    case Status.STATUS_ROLLING_BACK:
        return "STATUS_ROLLING_BACK";
    case Status.STATUS_UNKNOWN:
        return "STATUS_UNKNOWN";
    default:/* w  ww. j  a  va 2s  .  c  o  m*/
        return "NO STATUS FOUND";
    }
}

From source file:org.apache.ojb.odmg.TransactionImpl.java

/**
 * Commit and close the transaction. Calling <code>commit</code> commits to
 * the database all persistent object modifications within the transaction and
 * releases any locks held by the transaction. A persistent object
 * modification is an update of any field of an existing persistent object, or
 * an update or creation of a new named object in the database. If a
 * persistent object modification results in a reference from an existing
 * persistent object to a transient object, the transient object is moved to
 * the database, and all references to it updated accordingly. Note that the
 * act of moving a transient object to the database may create still more
 * persistent references to transient objects, so its referents must be
 * examined and moved as well. This process continues until the database
 * contains no references to transient objects, a condition that is guaranteed
 * as part of transaction commit. Committing a transaction does not remove
 * from memory transient objects created during the transaction.
 *
 * The updateObjectList contains a list of all objects for which this transaction
 * has write privledge to.  We need to update these objects.
 *//*from  ww  w.j  ava 2 s . c  o  m*/
public void commit() {
    checkOpen();
    try {
        prepareCommit();
        checkForCommit();

        txStatus = Status.STATUS_COMMITTING;
        if (log.isDebugEnabled())
            log.debug("Commit transaction " + this);
        // now do real commit on broker
        if (hasBroker())
            getBroker().commitTransaction();

        // Now, we notify everything the commit is done.
        performTransactionAwareAfterCommit();

        doClose();
        txStatus = Status.STATUS_COMMITTED;
    } catch (Exception ex) {
        log.error("Error while commit objects, do abort tx " + this + ", " + ex.getMessage(), ex);
        txStatus = Status.STATUS_MARKED_ROLLBACK;
        abort();
        if (!(ex instanceof ODMGRuntimeException)) {
            throw new TransactionAbortedExceptionOJB("Can't commit objects: " + ex.getMessage(), ex);
        } else {
            throw (ODMGRuntimeException) ex;
        }
    }
}

From source file:org.apache.openjpa.kernel.BrokerImpl.java

/**
 * Mark the current transaction as rollback-only.
 *//*from ww w .  j  a  va 2  s  .  c o m*/
private void setRollbackOnlyInternal(Throwable cause) {
    try {
        javax.transaction.Transaction trans = _runtime.getTransactionManager().getTransaction();
        if (trans == null)
            throw new InvalidStateException(_loc.get("null-trans"));
        // ensure tran is in a valid state to accept the setRollbackOnly
        int tranStatus = trans.getStatus();
        if ((tranStatus != Status.STATUS_NO_TRANSACTION) && (tranStatus != Status.STATUS_ROLLEDBACK)
                && (tranStatus != Status.STATUS_COMMITTED))
            _runtime.setRollbackOnly(cause);
        else if (_log.isTraceEnabled())
            _log.trace(_loc.get("invalid-tran-status", Integer.valueOf(tranStatus), "setRollbackOnly"));
    } catch (OpenJPAException ke) {
        throw ke;
    } catch (Exception e) {
        throw new GeneralException(e);
    }
}

From source file:org.apache.openjpa.kernel.BrokerImpl.java

public void afterCompletion(int status) {
    beginOperation(false);/*w  w w.  j a  v a 2  s.com*/
    try {
        assertActiveTransaction();

        _flags |= FLAG_TRANS_ENDING;
        endTransaction(status);
        if (_sync != null)
            _sync.afterCompletion(status);

        if ((_autoDetach & DETACH_COMMIT) != 0)
            detachAllInternal(null);
        else if (status == Status.STATUS_ROLLEDBACK && (_autoDetach & DETACH_ROLLBACK) != 0) {
            detachAllInternal(null);
        }

        // in an ee context, it's possible that the user tried to close
        // us but we didn't actually close because we were waiting on this
        // transaction; if that's true, then close now
        if ((_flags & FLAG_CLOSE_INVOKED) != 0 && _compat.getCloseOnManagedCommit())
            free();
    } catch (OpenJPAException ke) {
        if (_log.isTraceEnabled())
            _log.trace(_loc.get("end-trans-error"), ke);
        throw translateManagedCompletionException(ke);
    } catch (RuntimeException re) {
        if (_log.isTraceEnabled())
            _log.trace(_loc.get("end-trans-error"), re);
        throw translateManagedCompletionException(new StoreException(re));
    } finally {
        _flags &= ~FLAG_ACTIVE;
        _flags &= ~FLAG_FLUSHED;
        _flags &= ~FLAG_TRANS_ENDING;

        // event manager nulled if freed broker
        if (_transEventManager != null && _transEventManager.hasEndListeners()) {
            fireTransactionEvent(new TransactionEvent(this,
                    status == Status.STATUS_COMMITTED ? TransactionEvent.AFTER_COMMIT_COMPLETE
                            : TransactionEvent.AFTER_ROLLBACK_COMPLETE,
                    null, null, null, null));
        }

        endOperation();
    }
}