use of org.springframework.transaction.support.DefaultTransactionDefinition in project ddd-cqrs-sample by BottegaIT.
the class AddSampleProductsOnStartup method addSampleProductsToRepo.
@PostConstruct
public void addSampleProductsToRepo() {
TransactionStatus tx = transactionManager.getTransaction(new DefaultTransactionDefinition());
for (int i = 1; i < 21; i++) {
em.persist(product(String.format("Electronic Gizmo %02d", i), 0.99));
em.persist(product(String.format("Cell Phone with 32GB flash memory %02d", i), 299.99));
em.persist(food(String.format("Software Engineering Audiobook %02d", i), 17.50));
em.persist(drug(String.format("PC Game including Zombies Part %02d", i), 39.89));
em.persist(product(String.format("Tablet with Keyboard %02d", i), 459.99));
}
em.persist(new Client());
transactionManager.commit(tx);
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project ignite by apache.
the class CacheSpringStoreSessionListener method definition.
/**
* Gets DB transaction isolation level based on ongoing cache transaction isolation.
*
* @return DB transaction isolation.
*/
private TransactionDefinition definition(Transaction tx, String cacheName) {
assert tx != null;
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setName("Ignite Tx [cache=" + (cacheName != null ? cacheName : "<default>") + ", id=" + tx.xid() + ']');
def.setIsolationLevel(isolationLevel(tx.isolation()));
long timeoutSec = (tx.timeout() + 500) / 1000;
if (timeoutSec > 0 && timeoutSec < Integer.MAX_VALUE)
def.setTimeout((int) timeoutSec);
return def;
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project grails-core by grails.
the class ChainedTransactionManagerTests method createAndRollbackTransaction.
private void createAndRollbackTransaction() {
MultiTransactionStatus transaction = tm.getTransaction(new DefaultTransactionDefinition());
tm.rollback(transaction);
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project jOOQ by jOOQ.
the class TransactionTest method testExplicitTransactions.
@Test
public void testExplicitTransactions() {
boolean rollback = false;
TransactionStatus tx = txMgr.getTransaction(new DefaultTransactionDefinition());
try {
// constraint violation exception
for (int i = 0; i < 2; i++) dsl.insertInto(BOOK).set(BOOK.ID, 5).set(BOOK.AUTHOR_ID, 1).set(BOOK.TITLE, "Book 5").execute();
Assert.fail();
}// Upon the constraint violation, we explicitly roll back the transaction.
catch (DataAccessException e) {
txMgr.rollback(tx);
rollback = true;
}
assertEquals(4, dsl.fetchCount(BOOK));
assertTrue(rollback);
}
use of org.springframework.transaction.support.DefaultTransactionDefinition in project jOOQ by jOOQ.
the class TransactionalMethodInterceptor method invoke.
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
TransactionStatus transaction = transactionManager.getTransaction(transactionDefinition);
try {
Object result = invocation.proceed();
try {
if (transaction.isNewTransaction())
transactionManager.commit(transaction);
} catch (UnexpectedRollbackException ignore) {
}
return result;
} catch (Exception e) {
if (transaction.isNewTransaction())
transactionManager.rollback(transaction);
throw e;
}
}
Aggregations