use of jodd.jtx.JtxException in project jodd by oblac.
the class DbPropagationTest method testSupportsToMandatory.
@Test
public void testSupportsToMandatory() {
LeanJtxWorker worker = new LeanJtxWorker(dbtxm);
DbJtxSessionProvider sessionProvider = new DbJtxSessionProvider(worker.getTransactionManager());
// session #1: supports
JtxTransaction jtx = worker.maybeRequestTransaction(supports(), CTX_1);
assertNotNull(jtx);
assertFalse(jtx.isActive());
DbSession session1 = sessionProvider.getDbSession();
executeUpdate(session1, "insert into GIRL values(1, 'Sophia', null)");
assertFalse(jtx.isActive());
assertFalse(jtx.isCommitted());
assertTrue(jtx.isNoTransaction());
// session #2: inner, mandatory
try {
worker.maybeRequestTransaction(mandatory(), CTX_2);
fail();
} catch (JtxException ignore) {
}
}
use of jodd.jtx.JtxException in project jodd by oblac.
the class DbJtxResourceManager method rollbackTransaction.
/**
* {@inheritDoc}
*/
public void rollbackTransaction(DbSession resource) {
try {
if (resource.isTransactionActive()) {
log.debug("rollback tx");
resource.rollbackTransaction();
}
} catch (Exception ex) {
throw new JtxException(ex);
} finally {
resource.closeSession();
}
}
use of jodd.jtx.JtxException in project jodd by oblac.
the class DbTransactionTest method testTime.
// ---------------------------------------------------------------- test time
@Test
public void testTime() {
JtxTransactionManager manager = new JtxTransactionManager();
manager.registerResourceManager(new DbJtxResourceManager(cp));
JtxTransaction tx1 = manager.requestTransaction(new JtxTransactionMode().propagationRequired().transactionTimeout(1));
DbSession session1 = tx1.requestResource(DbSession.class);
assertNotNull(session1);
executeCount(session1, "select count(*) from GIRL");
ThreadUtil.sleep(2000);
try {
DbSession session2 = tx1.requestResource(DbSession.class);
assertNotNull(session2);
assertSame(session1, session2);
executeCount(session1, "select count(*) from GIRL");
fail();
} catch (JtxException ignore) {
}
tx1.rollback();
}
use of jodd.jtx.JtxException in project jodd by oblac.
the class DbPropagationTest method testRequiredToNever.
@Test
public void testRequiredToNever() {
LeanJtxWorker worker = new LeanJtxWorker(dbtxm);
DbJtxSessionProvider sessionProvider = new DbJtxSessionProvider(worker.getTransactionManager());
// session #1: required
JtxTransaction jtx = worker.maybeRequestTransaction(required(), CTX_1);
assertNotNull(jtx);
DbSession session1 = sessionProvider.getDbSession();
executeUpdate(session1, "insert into GIRL values(1, 'Sophia', null)");
assertTrue(jtx.isActive());
assertFalse(jtx.isCommitted());
assertFalse(jtx.isNoTransaction());
// session #2: inner, never
try {
worker.maybeRequestTransaction(never(), CTX_2);
fail();
} catch (JtxException ignore) {
}
}
Aggregations