Search in sources :

Example 31 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project cucumber-jvm by cucumber.

the class SpringTransactionHooksTest method setUp.

@Before
public void setUp() {
    target = new SpringTransactionHooks() {

        @Override
        public PlatformTransactionManager obtainPlatformTransactionManager() {
            return mockedPlatformTransactionManager;
        }
    };
    target.setBeanFactory(mockedBeanFactory);
}
Also used : SpringTransactionHooks(cucumber.api.spring.SpringTransactionHooks) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Before(org.junit.Before)

Example 32 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project grails-core by grails.

the class ChainedTransactionManager method commit.

/*
	 * (non-Javadoc)
	 * @see org.springframework.transaction.PlatformTransactionManager#commit(org.springframework.transaction.TransactionStatus)
	 */
public void commit(TransactionStatus status) throws TransactionException {
    MultiTransactionStatus multiTransactionStatus = (MultiTransactionStatus) status;
    boolean commit = true;
    Exception commitException = null;
    PlatformTransactionManager commitExceptionTransactionManager = null;
    for (PlatformTransactionManager transactionManager : reverse(transactionManagers)) {
        if (commit) {
            try {
                multiTransactionStatus.commit(transactionManager);
            } catch (Exception ex) {
                commit = false;
                commitException = ex;
                commitExceptionTransactionManager = transactionManager;
            }
        } else {
            try {
                multiTransactionStatus.rollback(transactionManager);
            } catch (Exception ex) {
                LOGGER.warn("Rollback exception (after commit) (" + transactionManager + ") " + ex.getMessage(), ex);
            }
        }
    }
    if (multiTransactionStatus.isNewSynchonization()) {
        synchronizationManager.clearSynchronization();
    }
    if (commitException != null) {
        boolean firstTransactionManagerFailed = commitExceptionTransactionManager == getLastTransactionManager();
        int transactionState = firstTransactionManagerFailed ? HeuristicCompletionException.STATE_ROLLED_BACK : HeuristicCompletionException.STATE_MIXED;
        throw new HeuristicCompletionException(transactionState, commitException);
    }
}
Also used : HeuristicCompletionException(org.springframework.transaction.HeuristicCompletionException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) TransactionException(org.springframework.transaction.TransactionException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) HeuristicCompletionException(org.springframework.transaction.HeuristicCompletionException) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 33 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project grails-core by grails.

the class ChainedTransactionManagerTests method shouldCompleteSuccessfully.

@Test
public void shouldCompleteSuccessfully() throws Exception {
    PlatformTransactionManager transactionManager = createNonFailingTransactionManager("single");
    setupTransactionManagers(transactionManager);
    createAndCommitTransaction();
    assertThat(transactionManager, isCommitted());
}
Also used : TestPlatformTransactionManager(org.grails.transaction.ChainedTransactionManagerTests.TestPlatformTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.Test)

Example 34 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project grails-core by grails.

the class ChainedTransactionManagerTests method shouldCommitAllRegisteredTransactionManagers.

@Test
public void shouldCommitAllRegisteredTransactionManagers() {
    PlatformTransactionManager first = createNonFailingTransactionManager("first");
    PlatformTransactionManager second = createNonFailingTransactionManager("second");
    setupTransactionManagers(first, second);
    createAndCommitTransaction();
    assertThat(first, isCommitted());
    assertThat(second, isCommitted());
}
Also used : TestPlatformTransactionManager(org.grails.transaction.ChainedTransactionManagerTests.TestPlatformTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.Test)

Example 35 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project grails-core by grails.

the class ChainedTransactionManagerTests method shouldCommitInReverseOrder.

@Test
public void shouldCommitInReverseOrder() {
    PlatformTransactionManager first = createNonFailingTransactionManager("first");
    PlatformTransactionManager second = createNonFailingTransactionManager("second");
    setupTransactionManagers(first, second);
    createAndCommitTransaction();
    assertThat("second tm commited before first ", commitTime(first) >= commitTime(second), is(true));
}
Also used : TestPlatformTransactionManager(org.grails.transaction.ChainedTransactionManagerTests.TestPlatformTransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.Test)

Aggregations

PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)54 Test (org.junit.Test)34 TransactionStatus (org.springframework.transaction.TransactionStatus)13 ITestBean (org.springframework.tests.sample.beans.ITestBean)10 TestBean (org.springframework.tests.sample.beans.TestBean)10 BeanFactory (org.springframework.beans.factory.BeanFactory)7 Method (java.lang.reflect.Method)6 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)6 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)6 TestPlatformTransactionManager (org.grails.transaction.ChainedTransactionManagerTests.TestPlatformTransactionManager)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 CannotCreateTransactionException (org.springframework.transaction.CannotCreateTransactionException)4 TransactionException (org.springframework.transaction.TransactionException)4 UnexpectedRollbackException (org.springframework.transaction.UnexpectedRollbackException)4 HashMap (java.util.HashMap)3 DataSource (javax.sql.DataSource)3 Before (org.junit.Before)3 MockPlatformTransactionManager (org.opennms.core.test.MockPlatformTransactionManager)3 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)3