Example usage for org.hibernate TransactionException TransactionException

List of usage examples for org.hibernate TransactionException TransactionException

Introduction

In this page you can find the example usage for org.hibernate TransactionException TransactionException.

Prototype

public TransactionException(String message, Throwable cause) 

Source Link

Document

Constructs a TransactionException using the specified information.

Usage

From source file:com.baomidou.hibernateplus.HibernateConfigurableJtaPlatform.java

License:Apache License

@Override
public boolean canRegisterSynchronization() {
    try {//from w  w  w.  ja v  a2 s. c  o m
        return (this.transactionManager.getStatus() == Status.STATUS_ACTIVE);
    } catch (SystemException ex) {
        throw new TransactionException("Could not determine JTA transaction status", ex);
    }
}

From source file:com.baomidou.hibernateplus.HibernateConfigurableJtaPlatform.java

License:Apache License

@Override
public void registerSynchronization(Synchronization synchronization) {
    if (this.transactionSynchronizationRegistry != null) {
        this.transactionSynchronizationRegistry.registerInterposedSynchronization(synchronization);
    } else {/*from  ww w.  j  av a 2 s .c  om*/
        try {
            this.transactionManager.getTransaction().registerSynchronization(synchronization);
        } catch (Exception ex) {
            throw new TransactionException("Could not access JTA Transaction to register synchronization", ex);
        }
    }
}

From source file:com.cubeia.firebase.service.persistence.jpa.SystemJTATransaction.java

License:Open Source License

private void afterCommitRollback() throws TransactionException {
    begun = false;//from   w  w  w .j  av  a2 s .co 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 = ut.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:com.cubeia.firebase.service.persistence.jpa.SystemJTATransaction.java

License:Open Source License

public boolean wasRolledBack() throws TransactionException {
    final int status;
    try {//from  w  w  w . jav  a  2s .  c  o  m
        status = ut.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 JTAHelper.isRollback(status);
    }
}

From source file:com.cubeia.firebase.service.persistence.jpa.SystemJTATransaction.java

License:Open Source License

public boolean wasCommitted() throws TransactionException {
    final int status;
    try {/*from  w ww .  j av  a 2 s. c  o  m*/
        status = ut.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:com.cubeia.firebase.service.persistence.jpa.SystemJTATransaction.java

License:Open Source License

public boolean isActive() throws TransactionException {
    if (!begun || commitFailed || commitSucceeded)
        return false;
    final int status;
    try {/*from  w  w  w.j  a  v  a 2s . c o m*/
        status = ut.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_ACTIVE;
    }
}

From source file:com.cubeia.firebase.service.persistence.jpa.SystemJTATransaction.java

License:Open Source License

public void registerSynchronization(Synchronization sync) throws HibernateException {
    if (getTransactionManager() == null)
        throw new IllegalStateException("JTA TransactionManager not available");
    else {//from   w ww  . ja  va2 s . c o  m
        try {
            getTransactionManager().getTransaction().registerSynchronization(sync);
        } catch (Exception e) {
            throw new TransactionException("could not register synchronization", e);
        }
    }
}

From source file:com.cubeia.firebase.service.persistence.jpa.SystemJTATransaction.java

License:Open Source License

public void setTimeout(int seconds) {
    try {//  www  . j av a  2 s.c o  m
        ut.setTransactionTimeout(seconds);
    } catch (SystemException se) {
        throw new TransactionException("could not set transaction timeout", se);
    }
}

From source file:com.cubeia.firebase.service.persistence.jpa.SystemTransactionFactory.java

License:Open Source License

public boolean isTransactionInProgress(JDBCContext jdbcContext, Context transactionContext,
        Transaction transaction) {//from   w ww.j a  v  a 2 s. c om
    try {
        // Essentially:
        // 1) If we have a local (Hibernate) transaction in progress
        //      and it already has the UserTransaction cached, use that
        //      UserTransaction to determine the status.
        // 2) If a transaction manager has been located, use
        //      that transaction manager to determine the status.
        // 3) Finally, as the last resort, try to lookup the
        //      UserTransaction via JNDI and use that to determine the
        //      status.
        if (transaction != null) {
            UserTransaction ut = ((SystemJTATransaction) transaction).getUserTransaction();
            if (ut != null) {
                return JTAHelper.isInProgress(ut.getStatus());
            }
        }

        if (jdbcContext.getFactory().getTransactionManager() != null) {
            return JTAHelper.isInProgress(jdbcContext.getFactory().getTransactionManager().getStatus());
        } else {
            UserTransaction ut = service.getUserTransaction();
            return ut != null && JTAHelper.isInProgress(ut.getStatus());
        }
    } catch (SystemException se) {
        throw new TransactionException("Unable to check transaction status", se);
    }
}

From source file:com.googlecode.hibernate.audit.synchronization.AuditSynchronization.java

License:Open Source License

private boolean isMarkedForRollback(Session session) {
    JtaPlatform jtaPlatform = ((SessionFactoryImplementor) auditedSession.getSessionFactory()).getSettings()
            .getJtaPlatform();//from   w  w  w.  j a  va2  s . c o  m
    TransactionManager manager = null;
    if (jtaPlatform != null) {
        manager = jtaPlatform.retrieveTransactionManager();
    }
    if (manager != null) {
        try {
            int status = manager.getStatus();
            if (status == Status.STATUS_MARKED_ROLLBACK || status == Status.STATUS_ROLLING_BACK
                    || status == Status.STATUS_ROLLEDBACK) {
                return true;
            }
        } catch (SystemException e) {
            throw new TransactionException("Unable to get the transaction status.", e);
        }
    } else {
        return session.getTransaction().wasRolledBack();
    }

    return false;
}