use of org.springframework.transaction.support.DefaultTransactionStatus in project BroadleafCommerce by BroadleafCommerce.
the class TransactionLifecycleMonitor method finalizeTransaction.
protected void finalizeTransaction(TransactionLifecycleEvent event) {
String finalizationType = event.getLifecycle().name();
DefaultTransactionStatus status = (DefaultTransactionStatus) event.getParams()[0];
EntityManager em = getEntityManagerFromTransactionObject(status.getTransaction());
if (em != null) {
Integer hashcode = em.hashCode();
TransactionInfo info = infos.get(hashcode);
if (info != null) {
try {
Throwable finalizationException = event.getException();
if (finalizationException != null) {
info.setFaultStateDetected(true);
// An exception took place during finalization. Log our info to support for review.
StringWriter sw = new StringWriter();
finalizationException.printStackTrace(new PrintWriter(sw));
logger.support(String.format("TRANSACTIONMONITOR(3) - Exception during " + finalizationType + " finalization. Logging " + "TransactionInfo and finalization exception: \n%s finalizationStack=\'%s\'", info.toString(), sw.toString()));
}
} finally {
infos.remove(hashcode);
}
}
}
}
use of org.springframework.transaction.support.DefaultTransactionStatus in project molgenis by molgenis.
the class PostgreSqlTransactionManager method doCommit.
@Override
protected void doCommit(DefaultTransactionStatus status) {
MolgenisTransaction transaction = (MolgenisTransaction) status.getTransaction();
if (LOG.isDebugEnabled()) {
LOG.debug("Commit 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.commitTransaction(transaction.getId()));
}
try {
super.doCommit(jpaTransactionStatus);
} catch (TransactionException e) {
throw translateTransactionException(e);
}
if (!status.isReadOnly()) {
transactionListeners.forEach(j -> j.afterCommitTransaction(transaction.getId()));
}
}
use of org.springframework.transaction.support.DefaultTransactionStatus in project molgenis by molgenis.
the class PostgreSqlTransactionManager method doSetRollbackOnly.
@Override
protected void doSetRollbackOnly(DefaultTransactionStatus status) {
MolgenisTransaction transaction = (MolgenisTransaction) status.getTransaction();
DefaultTransactionStatus jpaTransactionStatus = new DefaultTransactionStatus(transaction.getDataSourceTransaction(), status.isNewTransaction(), status.isNewSynchronization(), status.isReadOnly(), status.isDebug(), status.getSuspendedResources());
super.doSetRollbackOnly(jpaTransactionStatus);
}
use of org.springframework.transaction.support.DefaultTransactionStatus in project spring-framework by spring-projects.
the class TransactionSupportTests method transactionTemplateWithRollbackException.
@SuppressWarnings("serial")
@Test
public void transactionTemplateWithRollbackException() {
final TransactionSystemException tex = new TransactionSystemException("system exception");
TestTransactionManager tm = new TestTransactionManager(false, true) {
@Override
protected void doRollback(DefaultTransactionStatus status) {
super.doRollback(status);
throw tex;
}
};
TransactionTemplate template = new TransactionTemplate(tm);
final RuntimeException ex = new RuntimeException("Some application exception");
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> template.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
throw ex;
}
})).isSameAs(tex);
assertThat(tm.begin).as("triggered begin").isTrue();
assertThat(tm.commit).as("no commit").isFalse();
assertThat(tm.rollback).as("triggered rollback").isTrue();
assertThat(tm.rollbackOnly).as("no rollbackOnly").isFalse();
}
use of org.springframework.transaction.support.DefaultTransactionStatus in project spring-framework by spring-projects.
the class TransactionSupportTests method existingTransaction.
@Test
public void existingTransaction() {
PlatformTransactionManager tm = new TestTransactionManager(true, true);
DefaultTransactionStatus status1 = (DefaultTransactionStatus) tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
assertThat(status1.getTransaction() != null).as("Must have transaction").isTrue();
boolean condition2 = !status1.isNewTransaction();
assertThat(condition2).as("Must not be new transaction").isTrue();
DefaultTransactionStatus status2 = (DefaultTransactionStatus) tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
assertThat(status2.getTransaction() != null).as("Must have transaction").isTrue();
boolean condition1 = !status2.isNewTransaction();
assertThat(condition1).as("Must not be new transaction").isTrue();
DefaultTransactionStatus status3 = (DefaultTransactionStatus) tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_MANDATORY));
assertThat(status3.getTransaction() != null).as("Must have transaction").isTrue();
boolean condition = !status3.isNewTransaction();
assertThat(condition).as("Must not be new transaction").isTrue();
}
Aggregations