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.etk.entity.engine.plugins.transaction.TransactionUtil.java

public static String getTransactionStateString(int state) {
    /*/*from w ww  .j a  va 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.exolab.castor.jdo.engine.GlobalDatabaseImpl.java

/**
 * @inheritDoc/*from   w  w w.  j  ava 2s .c o  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.firstopen.singularity.util.TransactionManager.java

public void rollback() {
    log.debug("rollback()");
    try {/*from ww w  .j a  v  a  2  s . c o  m*/
        UserTransaction userTransaction = TransactionUtil.getUserTransaction();
        int status = userTransaction.getStatus();
        if (status != Status.STATUS_COMMITTED && status != Status.STATUS_ROLLEDBACK) {
            userTransaction.rollback();
        }
    } catch (Exception e) {

        log.error("rollback failed!");
        throw new InfrastructureException(e);
    }
}

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

public void commit() throws HibernateException {
    if (!begun) {
        throw new TransactionException("Transaction not succesfully started");
    }//from ww w  .  j a v  a2 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

private void afterCommitRollback() throws TransactionException {

    begun = false;//from  ww w . ja v a2 s . c o  m

    if (callback) { // this method is a noop if there is a Synchronization!

        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 {
            /*if (status!=Status.STATUS_COMMITTED && status!=Status.STATUS_ROLLEDBACK) {
               log.warn("Transaction not complete - you should set hibernate.transaction.manager_lookup_class if cache is enabled");
               //throw exception??
            }*/
            jdbcContext.afterTransactionCompletion(status == Status.STATUS_COMMITTED, this);
        }

    }
}

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

public boolean wasCommitted() throws TransactionException {

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

    final int status;
    try {//from  w w w .  ja  v  a2 s  . co m
        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.j2free.jpa.Controller.java

/**
 * Ends the contatiner managed <tt>UserTransaction</tt>, committing
 * or rolling back as necessary./* ww  w.j a v a 2 s  .c om*/
 *
 * @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

/**
 * /*from w ww  . j a  va  2  s .  co  m*/
 * @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.jbpm.EventCallback.java

private static void registerNotification(final String event) {
    Synchronization notification = new Synchronization() {

        public void beforeCompletion() {
        }//from  ww w. ja va 2s  .co m

        public void afterCompletion(int status) {
            if (status == Status.STATUS_COMMITTED) {
                log.debug("sending '" + event + "' notification");
                Semaphore eventSemaphore = getEventSemaphore(event);
                eventSemaphore.release();
            }
        }

    };
    JbpmContext.getCurrentJbpmContext().getSession().getTransaction().registerSynchronization(notification);
}

From source file:org.jbpm.graph.def.EventCallback.java

private static void registerNotification(final String event) {
    Synchronization notification = new Synchronization() {

        public void beforeCompletion() {
        }/*www.j  a  v  a2s  . c  om*/

        public void afterCompletion(int status) {
            if (status == Status.STATUS_COMMITTED) {
                if (log.isDebugEnabled())
                    log.debug("sending '" + event + "' notification");
                Semaphore eventSemaphore = getEventSemaphore(event);
                eventSemaphore.release();
            }
        }
    };
    JbpmContext.getCurrentJbpmContext().getSession().getTransaction().registerSynchronization(notification);
}