use of org.springframework.transaction.support.DefaultTransactionDefinition in project spring-framework by spring-projects.
the class WebSphereUowTransactionManagerTests method propagationNestedFailsInCaseOfExistingTransaction.
@Test
public void propagationNestedFailsInCaseOfExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);
try {
ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
return "result";
}
});
fail("Should have thrown NestedTransactionNotSupportedException");
} catch (NestedTransactionNotSupportedException ex) {
// expected
}
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project spring-framework by spring-projects.
the class WebSphereUowTransactionManagerTests method doTestNewTransactionSynchronization.
private void doTestNewTransactionSynchronization(int propagationBehavior, final int synchMode) {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
ptm.setTransactionSynchronization(synchMode);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(propagationBehavior);
definition.setReadOnly(true);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
if (synchMode == WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
} else {
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
}
return "result";
}
}));
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals(0, manager.getUOWTimeout());
assertEquals(UOWManager.UOW_TYPE_LOCAL_TRANSACTION, manager.getUOWType());
assertFalse(manager.getJoined());
assertFalse(manager.getRollbackOnly());
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project spring-framework by spring-projects.
the class WebSphereUowTransactionManagerTests method uowManagerFoundInJndi.
@Test
public void uowManagerFoundInJndi() {
MockUOWManager manager = new MockUOWManager();
ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate(WebSphereUowTransactionManager.DEFAULT_UOW_MANAGER_NAME, manager);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager();
ptm.setJndiTemplate(jndiTemplate);
ptm.afterPropertiesSet();
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
return "result";
}
}));
assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
assertFalse(manager.getJoined());
assertFalse(manager.getRollbackOnly());
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project spring-framework by spring-projects.
the class WebSphereUowTransactionManagerTests method newTransactionWithCommitAndTimeout.
@Test
public void newTransactionWithCommitAndTimeout() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setTimeout(10);
definition.setReadOnly(true);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
return "result";
}
}));
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
assertEquals(10, manager.getUOWTimeout());
assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
assertFalse(manager.getJoined());
assertFalse(manager.getRollbackOnly());
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project uPortal by Jasig.
the class RDBMUserLayoutStore method setPlatformTransactionManager.
@Autowired
public void setPlatformTransactionManager(@Qualifier(BasePortalJpaDao.PERSISTENCE_UNIT_NAME) PlatformTransactionManager platformTransactionManager) {
this.transactionOperations = new TransactionTemplate(platformTransactionManager);
final DefaultTransactionDefinition nextStructTransactionDefinition = new DefaultTransactionDefinition();
nextStructTransactionDefinition.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
this.nextStructTransactionOperations = new TransactionTemplate(platformTransactionManager, nextStructTransactionDefinition);
}
Aggregations