use of org.springframework.transaction.TransactionDefinition in project spring-framework by spring-projects.
the class DefaultJpaDialectTests method testDefaultBeginTransaction.
@Test
public void testDefaultBeginTransaction() throws Exception {
TransactionDefinition definition = new DefaultTransactionDefinition();
EntityManager entityManager = mock(EntityManager.class);
EntityTransaction entityTx = mock(EntityTransaction.class);
given(entityManager.getTransaction()).willReturn(entityTx);
dialect.beginTransaction(entityManager, definition);
}
use of org.springframework.transaction.TransactionDefinition in project ignite by apache.
the class CacheSpringStoreSessionListener method onSessionStart.
/** {@inheritDoc} */
@Override
public void onSessionStart(CacheStoreSession ses) {
if (ses.isWithinTransaction() && ses.attachment() == null) {
try {
TransactionDefinition def = definition(ses.transaction(), ses.cacheName());
ses.attach(txMgr.getTransaction(def));
} catch (TransactionException e) {
throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
}
}
}
use of org.springframework.transaction.TransactionDefinition in project spring-boot by spring-projects.
the class SpringTransactionProvider method begin.
@Override
public void begin(TransactionContext context) {
TransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED);
TransactionStatus status = this.transactionManager.getTransaction(definition);
context.transaction(new SpringTransaction(status));
}
use of org.springframework.transaction.TransactionDefinition in project spring-framework by spring-projects.
the class BeanFactoryTransactionTests method doTestGetsAreNotTransactional.
private void doTestGetsAreNotTransactional(final ITestBean testBean) {
// Install facade
PlatformTransactionManager ptm = mock(PlatformTransactionManager.class);
PlatformTransactionManagerFacade.delegate = ptm;
assertTrue("Age should not be " + testBean.getAge(), testBean.getAge() == 666);
// Expect no methods
verifyZeroInteractions(ptm);
// Install facade expecting a call
final TransactionStatus ts = mock(TransactionStatus.class);
ptm = new PlatformTransactionManager() {
private boolean invoked;
@Override
public TransactionStatus getTransaction(TransactionDefinition def) throws TransactionException {
if (invoked) {
throw new IllegalStateException("getTransaction should not get invoked more than once");
}
invoked = true;
if (!(def.getName().contains(DerivedTestBean.class.getName()) && def.getName().contains("setAge"))) {
throw new IllegalStateException("transaction name should contain class and method name: " + def.getName());
}
return ts;
}
@Override
public void commit(TransactionStatus status) throws TransactionException {
assertTrue(status == ts);
}
@Override
public void rollback(TransactionStatus status) throws TransactionException {
throw new IllegalStateException("rollback should not get invoked");
}
};
PlatformTransactionManagerFacade.delegate = ptm;
// TODO same as old age to avoid ordering effect for now
int age = 666;
testBean.setAge(age);
assertTrue(testBean.getAge() == age);
}
use of org.springframework.transaction.TransactionDefinition in project spring-framework by spring-projects.
the class TransactionAttributeSourceTests method matchAlwaysTransactionAttributeSourceWithNulls.
@Test
public void matchAlwaysTransactionAttributeSourceWithNulls() throws Exception {
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
TransactionDefinition definition = tas.getTransactionAttribute(null, null);
assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, definition.getPropagationBehavior());
assertEquals(TransactionDefinition.ISOLATION_DEFAULT, definition.getIsolationLevel());
assertEquals(TransactionDefinition.TIMEOUT_DEFAULT, definition.getTimeout());
assertFalse(definition.isReadOnly());
}
Aggregations