List of usage examples for org.hibernate TransactionException TransactionException
public TransactionException(String message)
From source file:org.infinispan.test.hibernate.cache.commons.tm.JtaPlatformImpl.java
License:LGPL
@Override public void registerSynchronization(Synchronization synchronization) { try {/*from w w w . j a v a 2 s . c o m*/ XaTransactionManagerImpl.getInstance().getTransaction().registerSynchronization(synchronization); } catch (Exception e) { throw new TransactionException("Could not obtain transaction from TM"); } }
From source file:org.xerela.zap.hibernate.internal.ZTransaction.java
License:Mozilla Public License
/** {@inheritDoc} */ public void begin() { if (begun) {//from w w w . j a v a 2 s . com return; } if (commitFailed) { throw new TransactionException("Cannot re-start transaction after failed commit."); //$NON-NLS-1$ } try { newTransaction = userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION; if (newTransaction) { userTransaction.begin(); } } catch (NotSupportedException e) { throw new HibernateException(e); } catch (SystemException e) { throw new HibernateException(e); } boolean synchronization = jdbcContext.registerSynchronizationIfPossible(); if (!newTransaction && !synchronization) { LOGGER.warn(SET_HIBERNATE_TRANSACTION_MANAGER_LOOKUP_CLASS_IF_CACHE_IS_ENABLED); } if (!synchronization) { //if we could not register a synchronization, //do the before/after completion callbacks //ourself (but we need to let jdbcContext //know that this is what we are going to //do, so it doesn't keep trying to register //synchronizations) callback = jdbcContext.registerCallbackIfNecessary(); } begun = true; commitSucceeded = false; jdbcContext.afterTransactionBegin(this); }
From source file:org.xerela.zap.hibernate.internal.ZTransaction.java
License:Mozilla Public License
/** {@inheritDoc} */ public void commit() { if (!begun) { throw new TransactionException("Transaction not successfully started."); //$NON-NLS-1$ }//from w w w .j ava 2s. c o m boolean flush = !transactionContext.isFlushModeNever() && (callback || !transactionContext.isFlushBeforeCompletionEnabled()); if (flush) { transactionContext.managedFlush(); //if an exception occurs during flush, user must call rollback() } if (callback && newTransaction) { jdbcContext.beforeTransactionCompletion(this); } closeIfRequired(); if (newTransaction) { try { userTransaction.commit(); commitSucceeded = true; LOGGER.debug("Committed JTA UserTransaction"); //$NON-NLS-1$ } catch (Exception e) { // so the transaction is already rolled back, by JTA spec commitFailed = true; throw new TransactionException("ZTransaction commit failed: ", e); //$NON-NLS-1$ } finally { afterCommitRollback(); } } else { // this one only really needed for badly-behaved applications! // (if the TransactionManager has a Sychronization registered, its a noop) // (actually we do need it for downgrading locks) afterCommitRollback(); } }
From source file:org.xerela.zap.hibernate.internal.ZTransaction.java
License:Mozilla Public License
/** {@inheritDoc} */ public void rollback() { if (!begun && !commitFailed) { throw new TransactionException("Transaction not successfully started"); //$NON-NLS-1$ }//w ww . ja va2 s . com try { closeIfRequired(); } catch (Exception e) { LOGGER.error("Could not close session during rollback", e); //$NON-NLS-1$ //swallow it, and continue to roll back JTA transaction } try { if (newTransaction) { if (!commitFailed) { userTransaction.rollback(); } } else { userTransaction.setRollbackOnly(); } } catch (Exception e) { throw new HibernateException(e); } finally { afterCommitRollback(); } }
From source file:org.xerela.zap.hibernate.internal.ZTransaction.java
License:Mozilla Public License
/** {@inheritDoc} */ public boolean wasCommitted() { try {// ww w . jav a2 s. c o m int status = userTransaction.getStatus(); if (status == Status.STATUS_UNKNOWN) { throw new SystemException(); } return status == Status.STATUS_COMMITTED; } catch (SystemException se) { throw new TransactionException(COULD_NOT_DETERMINE_TRANSACTION_STATUS); } }
From source file:org.xerela.zap.hibernate.internal.ZTransaction.java
License:Mozilla Public License
/** {@inheritDoc} */ public boolean wasRolledBack() { try {// www .ja va2s.c om int status = userTransaction.getStatus(); if (status == Status.STATUS_UNKNOWN) { throw new SystemException(); } return status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_MARKED_ROLLBACK; } catch (SystemException se) { throw new TransactionException(COULD_NOT_DETERMINE_TRANSACTION_STATUS); } }
From source file:org.xerela.zap.hibernate.internal.ZTransactionFactory.java
License:Mozilla Public License
/** {@inheritDoc} */ public boolean isTransactionInProgress(JDBCContext jdbcContext, Context transactionContext, Transaction transaction) {/*ww w. j a v a 2 s . c o m*/ 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. if (transaction != null) { UserTransaction ut = ((ZTransaction) transaction).getUserTransaction(); if (ut != null) { return ut.getStatus() == Status.STATUS_ACTIVE || ut.getStatus() == Status.STATUS_MARKED_ROLLBACK; } } if (jdbcContext.getFactory().getTransactionManager() != null) { return JTAHelper.isInProgress(jdbcContext.getFactory().getTransactionManager().getStatus()); } throw new TransactionException(UNABLE_TO_CHECK_TRANSACTION_STATUS); } catch (SystemException se) { throw new TransactionException(UNABLE_TO_CHECK_TRANSACTION_STATUS, se); } }