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:org.apache.ode.daohib.JotmTransaction.java

License:Open Source License

private void afterCommitRollback() throws TransactionException {

    begun = false;// w  ww. j  a  va2 s. c o m
    // 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

License:Open Source License

/**
 * {@inheritDoc}//from  www. j  a  v a 2  s  .  co m
 */
public boolean wasRolledBack() 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 JTAHelper.isRollback(status);
    }
}

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

License:Open Source License

/**
 * {@inheritDoc}/*w ww.j a  va  2  s.  c o 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.daohib.JotmTransaction.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  w w  .ja  v a  2 s. c o  m*/
 */
public boolean isActive() throws TransactionException {
    if (!begun || commitFailed || commitSucceeded) {
        return false;
    }

    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_ACTIVE;
    }
}

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

License:Open Source License

/**
 * {@inheritDoc}/*www. j av a  2  s.c  o m*/
 */
public void registerSynchronization(Synchronization sync) throws HibernateException {
    if (getTransactionManager() == null) {
        throw new IllegalStateException("JTA TransactionManager not available");
    } else {
        try {
            getTransactionManager().getTransaction().registerSynchronization(sync);
        } catch (Exception e) {
            throw new TransactionException("could not register synchronization", e);
        }
    }
}

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

License:Open Source License

/**
 * {@inheritDoc}// ww w .  j  a v a 2  s  .c  om
 */
public void setTimeout(int seconds) {
    try {
        userTransaction.setTransactionTimeout(seconds);
    } catch (SystemException se) {
        throw new TransactionException("could not set transaction timeout", se);
    }
}

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

License:Open Source License

/**
 * {@inheritDoc}/*from   ww w.  j ava  2s. c  o m*/
 */
public boolean isTransactionInProgress(JDBCContext jdbcContext, Context transactionContext,
        Transaction transaction) {
    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 = ((JotmTransaction) 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 = getUserTransaction();
            return ut != null && JTAHelper.isInProgress(ut.getStatus());
        }
    } catch (SystemException se) {
        throw new TransactionException("Unable to check transaction status", se);
    }
}

From source file:org.springframework.orm.hibernate4.ConfigurableJtaPlatform.java

License:Apache License

public boolean canRegisterSynchronization() {
    try {//from   w  w  w .  j  a  va2 s.co  m
        return (this.transactionManager.getStatus() == Status.STATUS_ACTIVE);
    } catch (SystemException ex) {
        throw new TransactionException("Could not determine JTA transaction status", ex);
    }
}

From source file:org.springframework.orm.hibernate4.ConfigurableJtaPlatform.java

License:Apache License

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

From source file:org.xerela.zap.hibernate.internal.ZTransaction.java

License:Mozilla Public License

/** {@inheritDoc} */
public void registerSynchronization(Synchronization synchronization) {
    if (transactionContext.getFactory().getTransactionManager() == null) {
        throw new IllegalStateException("TransactionManager not available"); //$NON-NLS-1$
    } else {/* ww  w .  j ava 2 s  .  co  m*/
        try {
            transactionContext.getFactory().getTransactionManager().getTransaction()
                    .registerSynchronization(synchronization);
        } catch (Exception e) {
            throw new TransactionException("Could not register synchronization", e); //$NON-NLS-1$
        }
    }
}