use of io.ebean.Transaction in project act-ebean by actframework.
the class EbeanService method doEndTxIfActive.
@Override
protected void doEndTxIfActive(Object delegate) {
Transaction tx = ebean.currentTransaction();
if (null == tx) {
return;
}
if (TxContext.readOnly()) {
ebeanReadOnly.endTransaction();
} else {
SpiEbeanServer server = (SpiEbeanServer) ebean;
server.scopedTransactionExit(null, 1);
}
}
use of io.ebean.Transaction in project ebean by ebean-orm.
the class JdbcTransactionTest method postNestedCallback.
@Test
public void postNestedCallback() {
// test both pre-commit and post-commit to ensure callbacks don't disappear and new ones can be added
AtomicInteger preCommitCallCount = new AtomicInteger();
AtomicInteger postCommitCallCount = new AtomicInteger();
try (Transaction transaction = DB.beginTransaction()) {
DB.currentTransaction().register(new TransactionCallbackAdapter() {
@Override
public void postCommit() {
postCommitCallCount.incrementAndGet();
DB.currentTransaction().register(new TransactionCallbackAdapter() {
@Override
public void postCommit() {
postCommitCallCount.incrementAndGet();
}
});
}
@Override
public void preCommit() {
preCommitCallCount.incrementAndGet();
}
});
EBasic basic = new EBasic("b1");
DB.save(basic);
// transaction will fail if recursive post-commit is failing
transaction.commit();
// precommit executed once
assertThat(preCommitCallCount.get()).isEqualTo(1);
// postcommit executed twice
assertThat(postCommitCallCount.get()).isEqualTo(2);
}
}
use of io.ebean.Transaction in project ebean by ebean-orm.
the class TestQueryFindEach method persistenceContext_scope.
@Test
public void persistenceContext_scope() {
ResetBasicData.reset();
Query<Contact> query = DB.find(Contact.class);
try (final Transaction transaction = DB.beginTransaction()) {
// effectively loads customers into persistence context
final List<Customer> customerList = DB.find(Customer.class).select("name").findList();
SpiTransaction spiTxn = (SpiTransaction) transaction;
PersistenceContext pc = spiTxn.getPersistenceContext();
assertThat(pc.size(Customer.class)).isEqualTo(customerList.size());
LoggedSql.start();
query.findEach(contact -> {
// use customer from persistence context (otherwise would invoke lazy loading)
assertNotNull(contact.getCustomer().getName());
});
final List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(1);
}
}
use of io.ebean.Transaction in project ebean by ebean-orm.
the class DummyDao method doSomething.
@Transactional(type = TxType.REQUIRES_NEW)
public void doSomething() {
logger.info(" --- in DummyDao.doSomething() with TxType.REQUIRES_NEW");
Transaction txn = DB.currentTransaction();
if (txn == null) {
logger.error(" NO TRANSACTION ??");
} else {
logger.info(" --- txn - " + txn);
}
}
use of io.ebean.Transaction in project ebean by ebean-orm.
the class DummyDao method doWithBatchOptionsSet.
@Transactional(batch = PersistBatch.ALL, batchOnCascade = PersistBatch.ALL, batchSize = 99)
private void doWithBatchOptionsSet() {
Transaction txn = DB.currentTransaction();
assertTrue(txn.isBatchMode());
assertTrue(txn.isBatchOnCascade());
assertEquals(99, txn.getBatchSize());
}
Aggregations