Search in sources :

Example 26 with TransactionSystemException

use of org.springframework.transaction.TransactionSystemException in project spring-framework by spring-projects.

the class DataSourceTransactionManagerTests method testTransactionWithExceptionOnCommitAndRollbackOnCommitFailure.

@Test
public void testTransactionWithExceptionOnCommitAndRollbackOnCommitFailure() throws Exception {
    willThrow(new SQLException("Cannot commit")).given(con).commit();
    tm.setRollbackOnCommitFailure(true);
    TransactionTemplate tt = new TransactionTemplate(tm);
    try {
        tt.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
            // something transactional
            }
        });
        fail("Should have thrown TransactionSystemException");
    } catch (TransactionSystemException ex) {
    // expected
    }
    assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
    verify(con).rollback();
    verify(con).close();
}
Also used : UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) SQLException(java.sql.SQLException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 27 with TransactionSystemException

use of org.springframework.transaction.TransactionSystemException in project ignite by apache.

the class SpringTransactionManager method doCommit.

/**
 * {@inheritDoc}
 */
@Override
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
    IgniteTransactionObject txObj = (IgniteTransactionObject) status.getTransaction();
    Transaction tx = txObj.getTransactionHolder().getTransaction();
    if (status.isDebug() && log.isDebugEnabled())
        log.debug("Committing Ignite transaction: " + tx);
    try {
        tx.commit();
    } catch (IgniteException e) {
        throw new TransactionSystemException("Could not commit Ignite transaction", e);
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) IgniteException(org.apache.ignite.IgniteException) TransactionSystemException(org.springframework.transaction.TransactionSystemException)

Aggregations

TransactionSystemException (org.springframework.transaction.TransactionSystemException)27 SystemException (javax.transaction.SystemException)7 Test (org.junit.Test)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 InvalidTransactionException (javax.transaction.InvalidTransactionException)6 NotSupportedException (javax.transaction.NotSupportedException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 SQLException (java.sql.SQLException)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)3 RollbackException (javax.persistence.RollbackException)3 Connection (javax.resource.cci.Connection)3 LocalTransactionException (javax.resource.spi.LocalTransactionException)3 RollbackException (javax.transaction.RollbackException)3 UserTransaction (javax.transaction.UserTransaction)3 UncategorizedSQLException (org.springframework.jdbc.UncategorizedSQLException)3 UOWException (com.ibm.wsspi.uow.UOWException)2 Connection (java.sql.Connection)2 JMSException (javax.jms.JMSException)2 Session (javax.jms.Session)2