Search in sources :

Example 1 with JtxTransactionMode

use of jodd.jtx.JtxTransactionMode in project jodd by oblac.

the class DbTransactionTest method service1.

// service #1 REQUIRED
JtxTransaction service1() {
    assertTotals(0, 0);
    DbJtxTransaction tx = dbtxm.requestTransaction(new JtxTransactionMode().propagationRequired());
    assertTotals(1, 1);
    s1 = tx.requestResource();
    return tx;
}
Also used : DbJtxTransaction(jodd.db.jtx.DbJtxTransaction) JtxTransactionMode(jodd.jtx.JtxTransactionMode)

Example 2 with JtxTransactionMode

use of jodd.jtx.JtxTransactionMode in project jodd by oblac.

the class DbTransactionTest method service3_1.

// service #3_1 NOT SUPPORTED
void service3_1(JtxTransaction tx3) {
    assertTotals(1, 1);
    DbJtxTransaction tx = dbtxm.requestTransaction(new JtxTransactionMode().propagationNotSupported());
    assertNotSame(tx3, tx);
    assertTotals(2, 1);
    assertNotSame(s1, tx.requestResource());
    assertNotSame(s1, tx.requestResource());
    tx.commit();
    assertTotals(1, 1);
}
Also used : DbJtxTransaction(jodd.db.jtx.DbJtxTransaction) JtxTransactionMode(jodd.jtx.JtxTransactionMode)

Example 3 with JtxTransactionMode

use of jodd.jtx.JtxTransactionMode in project jodd by oblac.

the class DbTransactionTest method testNoTx.

// ---------------------------------------------------------------- notx
@Test
public void testNoTx() {
    final JtxTransactionManager manager = new JtxTransactionManager();
    manager.registerResourceManager(new DbJtxResourceManager(cp));
    JtxTransaction tx = manager.requestTransaction(new JtxTransactionMode().propagationSupports());
    assertTrue(tx.isNoTransaction());
    try {
        tx.commit();
    } catch (Exception ignore) {
        fail();
    }
    assertTrue(tx.isCommitted());
    try {
        tx.rollback();
        fail("exception is already committed!");
    } catch (Exception ignore) {
    }
    tx = manager.requestTransaction(new JtxTransactionMode().propagationSupports());
    try {
        tx.rollback();
    } catch (Exception ex) {
        fail(ex.toString());
    }
    tx = manager.requestTransaction(new JtxTransactionMode().propagationSupports());
    try {
        tx.setRollbackOnly();
    } catch (Exception ex) {
        fail(ex.toString());
    }
}
Also used : DbJtxResourceManager(jodd.db.jtx.DbJtxResourceManager) JtxTransactionMode(jodd.jtx.JtxTransactionMode) DbJtxTransaction(jodd.db.jtx.DbJtxTransaction) JtxTransaction(jodd.jtx.JtxTransaction) JtxTransactionManager(jodd.jtx.JtxTransactionManager) SQLException(java.sql.SQLException) JtxException(jodd.jtx.JtxException) Test(org.junit.Test)

Example 4 with JtxTransactionMode

use of jodd.jtx.JtxTransactionMode in project jodd by oblac.

the class DbTransactionTest method service3.

// service #3 REQUIRED
void service3(JtxTransaction tx1) {
    assertTotals(1, 1);
    DbJtxTransaction tx = dbtxm.requestTransaction(new JtxTransactionMode().propagationRequired());
    assertEquals(tx1, tx);
    assertTotals(1, 1);
    assertEquals(s1, tx.requestResource());
    service3_1(tx);
    assertEquals(s1, tx.requestResource());
    assertTotals(1, 1);
}
Also used : DbJtxTransaction(jodd.db.jtx.DbJtxTransaction) JtxTransactionMode(jodd.jtx.JtxTransactionMode)

Example 5 with JtxTransactionMode

use of jodd.jtx.JtxTransactionMode in project jodd by oblac.

the class DbTransactionTest method service2.

// service #2 REQUIRES NEW
void service2(JtxTransaction tx1) {
    assertTotals(1, 1);
    DbJtxTransaction tx = dbtxm.requestTransaction(new JtxTransactionMode().propagationRequiresNew());
    assertTotals(2, 2);
    assertNotSame(tx1, tx);
    assertNotSame(s1, tx.requestResource());
    tx.commit();
    assertTotals(1, 1);
}
Also used : DbJtxTransaction(jodd.db.jtx.DbJtxTransaction) JtxTransactionMode(jodd.jtx.JtxTransactionMode)

Aggregations

JtxTransactionMode (jodd.jtx.JtxTransactionMode)13 DbJtxTransaction (jodd.db.jtx.DbJtxTransaction)10 JtxTransaction (jodd.jtx.JtxTransaction)5 JtxTransactionManager (jodd.jtx.JtxTransactionManager)5 Test (org.junit.Test)5 DbJtxResourceManager (jodd.db.jtx.DbJtxResourceManager)4 JtxException (jodd.jtx.JtxException)2 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 DbJtxSessionProvider (jodd.db.jtx.DbJtxSessionProvider)1 DbJtxTransactionManager (jodd.db.jtx.DbJtxTransactionManager)1 TransactionAnnotationData (jodd.jtx.meta.TransactionAnnotationData)1 ProxettaException (jodd.proxetta.ProxettaException)1 ProxyTarget.targetClass (jodd.proxetta.ProxyTarget.targetClass)1