Search in sources :

Example 1 with WorkSession

use of jodd.jtx.data.WorkSession in project jodd by oblac.

the class JtxManagerTest method testReadOnly.

// ---------------------------------------------------------------- ro
@Test
public void testReadOnly() {
    JtxTransactionManager manager = createManager();
    JtxTransaction jtx = manager.requestTransaction(new JtxTransactionMode().propagationRequired().readOnly(true));
    WorkSession work = jtx.requestResource(WorkSession.class);
    WorkSession work2 = jtx.requestResource(WorkSession.class);
    assertSame(work2, work);
    try {
        work.writeValue("new value");
        fail();
    } catch (UncheckedException ignored) {
    }
    jtx.commit();
    manager.close();
}
Also used : UncheckedException(jodd.exception.UncheckedException) WorkSession(jodd.jtx.data.WorkSession) Test(org.junit.Test)

Example 2 with WorkSession

use of jodd.jtx.data.WorkSession in project jodd by oblac.

the class JtxManagerTest method testRollback.

// ---------------------------------------------------------------- rollback
@Test
public void testRollback() {
    JtxTransactionManager manager = createManager();
    JtxTransaction jtx = manager.requestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false));
    WorkSession work = jtx.requestResource(WorkSession.class);
    work.writeValue("new value");
    jtx.rollback();
    assertFalse(work.readValue().equals("new value"));
    manager.close();
}
Also used : WorkSession(jodd.jtx.data.WorkSession) Test(org.junit.Test)

Example 3 with WorkSession

use of jodd.jtx.data.WorkSession in project jodd by oblac.

the class JtxManagerTest method testPropagationSupports.

// ---------------------------------------------------------------- supports
@Test
public void testPropagationSupports() {
    JtxTransactionManager manager = createManager();
    JtxTransaction jtx1 = manager.requestTransaction(new JtxTransactionMode().propagationSupports().readOnly(false));
    WorkSession work1 = jtx1.requestResource(WorkSession.class);
    assertEquals(1, manager.totalTransactions());
    work1.writeValue("one");
    assertEquals("one", work1.readValue());
    jtx1.commit();
    assertTrue(jtx1.isCommitted());
}
Also used : WorkSession(jodd.jtx.data.WorkSession) Test(org.junit.Test)

Example 4 with WorkSession

use of jodd.jtx.data.WorkSession in project jodd by oblac.

the class JtxManagerTest method testPropagationRequiresNew.

// ---------------------------------------------------------------- required
@Test
public void testPropagationRequiresNew() {
    JtxTransactionManager manager = createManager();
    JtxTransaction jtx1 = manager.requestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false));
    WorkSession work1 = jtx1.requestResource(WorkSession.class);
    assertEquals(1, manager.totalTransactions());
    work1.writeValue("one");
    assertEquals("[1] one", work1.readValue());
    JtxTransaction jtx2 = manager.requestTransaction(new JtxTransactionMode().propagationRequiresNew().readOnly(false));
    assertEquals(2, manager.totalTransactions());
    assertNotSame(jtx2, jtx1);
    WorkSession work2 = jtx2.requestResource(WorkSession.class);
    assertNotSame(work2, work1);
    work2.writeValue("two");
    assertEquals("[2] two", work2.readValue());
    jtx2.commit();
    work1.writeValue("three");
    assertEquals("[1] three", work1.readValue());
    jtx1.commit();
    assertTrue(jtx1.isCommitted());
    assertEquals("[1] three", WorkSession.getPersistedValue());
}
Also used : WorkSession(jodd.jtx.data.WorkSession) Test(org.junit.Test)

Example 5 with WorkSession

use of jodd.jtx.data.WorkSession in project jodd by oblac.

the class JtxManagerTest method testPropagationRequired.

// ---------------------------------------------------------------- required
@Test
public void testPropagationRequired() {
    JtxTransactionManager manager = createManager();
    JtxTransaction jtx1 = manager.requestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false));
    WorkSession work1 = jtx1.requestResource(WorkSession.class);
    assertEquals(1, manager.totalTransactions());
    work1.writeValue("one");
    assertEquals("[1] one", work1.readValue());
    JtxTransaction jtx2 = manager.requestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false));
    assertEquals(1, manager.totalTransactions());
    assertSame(jtx2, jtx1);
    WorkSession work2 = jtx2.requestResource(WorkSession.class);
    assertSame(work2, work1);
    work2.writeValue("two");
    assertEquals("[1] two", work2.readValue());
    //jtx2.commit();
    work1.writeValue("three");
    assertEquals("[1] three", work1.readValue());
    jtx1.commit();
    assertTrue(jtx1.isCommitted());
}
Also used : WorkSession(jodd.jtx.data.WorkSession) Test(org.junit.Test)

Aggregations

WorkSession (jodd.jtx.data.WorkSession)6 Test (org.junit.Test)6 UncheckedException (jodd.exception.UncheckedException)1 LeanJtxWorker (jodd.jtx.worker.LeanJtxWorker)1