Example usage for org.hibernate.resource.transaction.spi TransactionStatus ROLLED_BACK

List of usage examples for org.hibernate.resource.transaction.spi TransactionStatus ROLLED_BACK

Introduction

In this page you can find the example usage for org.hibernate.resource.transaction.spi TransactionStatus ROLLED_BACK.

Prototype

TransactionStatus ROLLED_BACK

To view the source code for org.hibernate.resource.transaction.spi TransactionStatus ROLLED_BACK.

Click Source Link

Document

The transaction has been rolled back.

Usage

From source file:org.glite.security.voms.admin.persistence.HibernateFactory.java

License:Apache License

public static void commitTransaction() {

    Transaction tx = (Transaction) threadTransaction.get();

    try {/*from ww w .  j  a va  2  s.  c  o m*/

        if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED)
                && !tx.getStatus().equals(TransactionStatus.ROLLING_BACK)
                && !tx.getStatus().equals(TransactionStatus.ROLLED_BACK)) {
            if (log.isDebugEnabled()) {
                log.debug("Committing transaction {} for thread {}", tx, Thread.currentThread());
            }
            tx.commit();

        }

        threadTransaction.set(null);
    } catch (HibernateException ex) {
        log.error("Error committing hibernate transaction:" + ex.getMessage());

        rollbackTransaction();

        if (log.isDebugEnabled()) {
            log.error("Error committing hibernate transaction!", ex);
        }
        throw new VOMSDatabaseException(ex.getMessage(), ex);
    }
}

From source file:org.glite.security.voms.admin.persistence.HibernateFactory.java

License:Apache License

public static void rollbackTransaction() {

    Transaction tx = (Transaction) threadTransaction.get();
    TransactionStatus status = tx.getStatus();
    log.warn("Rolling back transaction {}", tx);
    try {/*w  w w  . j  a  v a 2s  .co  m*/

        threadTransaction.set(null);
        if (tx != null && !tx.getStatus().equals(TransactionStatus.COMMITTED)
                && !tx.getStatus().equals(TransactionStatus.ROLLING_BACK)
                && !tx.getStatus().equals(TransactionStatus.ROLLED_BACK)) {

            if (log.isDebugEnabled()) {
                log.debug("Rolling back transaction {} for thread {}", tx, Thread.currentThread());
            }
            tx.rollback();
        }
    } catch (HibernateException ex) {
        log.error("Error rolling back hibernate transaction:" + ex.getMessage(), ex);

        throw new VOMSDatabaseException(ex.getMessage(), ex);

    } finally {
        closeSession();
    }

}