Search in sources :

Example 21 with TransactionSystemException

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

the class WebLogicJtaTransactionManager method loadWebLogicTransactionHelper.

private void loadWebLogicTransactionHelper() throws TransactionSystemException {
    if (this.transactionHelper == null) {
        try {
            Class<?> transactionHelperClass = getClass().getClassLoader().loadClass(TRANSACTION_HELPER_CLASS_NAME);
            Method getTransactionHelperMethod = transactionHelperClass.getMethod("getTransactionHelper");
            this.transactionHelper = getTransactionHelperMethod.invoke(null);
            logger.debug("WebLogic TransactionHelper found");
        } catch (InvocationTargetException ex) {
            throw new TransactionSystemException("WebLogic's TransactionHelper.getTransactionHelper() method failed", ex.getTargetException());
        } catch (Exception ex) {
            throw new TransactionSystemException("Could not initialize WebLogicJtaTransactionManager because WebLogic API classes are not available", ex);
        }
    }
}
Also used : Method(java.lang.reflect.Method) TransactionSystemException(org.springframework.transaction.TransactionSystemException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotSupportedException(javax.transaction.NotSupportedException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with TransactionSystemException

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

the class DataSourceTransactionManager method doCommit.

@Override
protected void doCommit(DefaultTransactionStatus status) {
    DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction();
    Connection con = txObject.getConnectionHolder().getConnection();
    if (status.isDebug()) {
        logger.debug("Committing JDBC transaction on Connection [" + con + "]");
    }
    try {
        con.commit();
    } catch (SQLException ex) {
        throw new TransactionSystemException("Could not commit JDBC transaction", ex);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) TransactionSystemException(org.springframework.transaction.TransactionSystemException)

Example 23 with TransactionSystemException

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

the class JmsTransactionManager method doCommit.

@Override
protected void doCommit(DefaultTransactionStatus status) {
    JmsTransactionObject txObject = (JmsTransactionObject) status.getTransaction();
    Session session = txObject.getResourceHolder().getSession();
    try {
        if (status.isDebug()) {
            logger.debug("Committing JMS transaction on Session [" + session + "]");
        }
        session.commit();
    } catch (TransactionRolledBackException ex) {
        throw new UnexpectedRollbackException("JMS transaction rolled back", ex);
    } catch (JMSException ex) {
        throw new TransactionSystemException("Could not commit JMS transaction", ex);
    }
}
Also used : UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) TransactionRolledBackException(javax.jms.TransactionRolledBackException) JMSException(javax.jms.JMSException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) Session(javax.jms.Session)

Example 24 with TransactionSystemException

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

the class WebSphereUowTransactionManagerTests method newTransactionWithCommitException.

@Test
public void newTransactionWithCommitException() {
    final RollbackException rex = new RollbackException();
    MockUOWManager manager = new MockUOWManager() {

        @Override
        public void runUnderUOW(int type, boolean join, UOWAction action) throws UOWException {
            throw new UOWException(rex);
        }
    };
    WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
    assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
    assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
    try {
        ptm.execute(definition, new TransactionCallback<String>() {

            @Override
            public String doInTransaction(TransactionStatus status) {
                assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
                assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
                assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
                return "result";
            }
        });
        fail("Should have thrown TransactionSystemException");
    } catch (TransactionSystemException ex) {
        // expected
        assertTrue(ex.getCause() instanceof UOWException);
        assertSame(rex, ex.getRootCause());
        assertSame(rex, ex.getMostSpecificCause());
    }
    assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
    assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
    assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
    assertEquals(0, manager.getUOWTimeout());
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) UOWException(com.ibm.wsspi.uow.UOWException) TransactionStatus(org.springframework.transaction.TransactionStatus) UOWAction(com.ibm.wsspi.uow.UOWAction) TransactionSystemException(org.springframework.transaction.TransactionSystemException) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 25 with TransactionSystemException

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

the class DataSourceTransactionManagerTests method testTransactionWithExceptionOnRollback.

@Test
public void testTransactionWithExceptionOnRollback() throws Exception {
    given(con.getAutoCommit()).willReturn(true);
    willThrow(new SQLException("Cannot rollback")).given(con).rollback();
    TransactionTemplate tt = new TransactionTemplate(tm);
    try {
        tt.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
                status.setRollbackOnly();
            }
        });
        fail("Should have thrown TransactionSystemException");
    } catch (TransactionSystemException ex) {
    // expected
    }
    assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
    InOrder ordered = inOrder(con);
    ordered.verify(con).setAutoCommit(false);
    ordered.verify(con).rollback();
    ordered.verify(con).setAutoCommit(true);
    verify(con).close();
}
Also used : InOrder(org.mockito.InOrder) 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)

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