Search in sources :

Example 6 with DefaultTransactionStatus

use of org.springframework.transaction.support.DefaultTransactionStatus in project molgenis by molgenis.

the class PostgreSqlTransactionManager method doRollback.

@Override
protected void doRollback(DefaultTransactionStatus status) {
    MolgenisTransaction transaction = (MolgenisTransaction) status.getTransaction();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Rollback transaction [{}]", transaction.getId());
    }
    DefaultTransactionStatus jpaTransactionStatus = new DefaultTransactionStatus(transaction.getDataSourceTransaction(), status.isNewTransaction(), status.isNewSynchronization(), status.isReadOnly(), status.isDebug(), status.getSuspendedResources());
    if (!status.isReadOnly()) {
        transactionListeners.forEach(j -> j.rollbackTransaction(transaction.getId()));
    }
    super.doRollback(jpaTransactionStatus);
}
Also used : DefaultTransactionStatus(org.springframework.transaction.support.DefaultTransactionStatus)

Example 7 with DefaultTransactionStatus

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

the class TransactionSupportTests method noExistingTransaction.

@Test
public void noExistingTransaction() {
    PlatformTransactionManager tm = new TestTransactionManager(false, true);
    DefaultTransactionStatus status1 = (DefaultTransactionStatus) tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
    assertThat(status1.hasTransaction()).as("Must not have transaction").isFalse();
    DefaultTransactionStatus status2 = (DefaultTransactionStatus) tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
    assertThat(status2.hasTransaction()).as("Must have transaction").isTrue();
    assertThat(status2.isNewTransaction()).as("Must be new transaction").isTrue();
    assertThatExceptionOfType(IllegalTransactionStateException.class).isThrownBy(() -> tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_MANDATORY)));
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) DefaultTransactionStatus(org.springframework.transaction.support.DefaultTransactionStatus) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultTransactionStatus (org.springframework.transaction.support.DefaultTransactionStatus)7 Test (org.junit.jupiter.api.Test)3 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 EntityManager (javax.persistence.EntityManager)1 TransactionException (org.springframework.transaction.TransactionException)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1