Package jodd.jtx.worker

Examples of jodd.jtx.worker.LeanJtxWorker


    return new JtxTransactionMode().propagationNotSupported().readOnly(false);
  }

  @Test
  public void testNotSupported() {
    LeanJtxWorker worker = new LeanJtxWorker(dbtxm);
    DbJtxSessionProvider sessionProvider = new DbJtxSessionProvider(worker.getTransactionManager());

    // session #1: not supported - commit
    JtxTransaction jtx = worker.maybeRequestTransaction(notSupported(), CTX_1);
    assertNotNull(jtx);
    DbSession session = sessionProvider.getDbSession();

    executeUpdate(session, "insert into GIRL values(1, 'Sophia', null)");
    assertFalse(jtx.isActive());
    assertTrue(jtx.isNoTransaction());
    assertTrue(worker.maybeCommitTransaction(jtx));
    assertFalse(jtx.isActive());
    assertTrue(jtx.isCommitted());

    // session #2: not supported - rollback
    jtx = worker.maybeRequestTransaction(notSupported(), CTX_2);
    assertNotNull(jtx);
    session = sessionProvider.getDbSession();
    assertFalse(jtx.isActive());
    assertTrue(jtx.isNoTransaction());
    executeUpdate(session, "insert into GIRL values(2, 'Gloria', null)");
    assertTrue(worker.markOrRollbackTransaction(jtx, null));

    // test
    session = new DbSession(cp);
    assertEquals(1, executeCount(session, "select count(*) from GIRL where id = 1"));
    assertEquals(1, executeCount(session, "select count(*) from GIRL where id = 2"));
View Full Code Here


    return new JtxTransactionMode().propagationNever().readOnly(false);
  }

  @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) {
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testSupportsToNeverCommit() {
    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, supports
    JtxTransaction jtx2 = worker.maybeRequestTransaction(never(), CTX_2);
    assertNull(jtx2);
    DbSession session2 = sessionProvider.getDbSession();
    assertSame(session1, session2);
    executeUpdate(session2, "insert into GIRL values(2, 'Gloria', null)");
    assertFalse(worker.maybeCommitTransaction(jtx2));
    assertFalse(jtx.isActive());

    // session #1: commit
    assertTrue(worker.maybeCommitTransaction(jtx));
    assertFalse(jtx.isActive());
    assertTrue(jtx.isCommitted());

    // test
    session1 = new DbSession(cp);
View Full Code Here

  }
*/

  @Test
  public void testSupportsToRequiresNewCommit() {
    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, required
    JtxTransaction jtx2 = worker.maybeRequestTransaction(requiredNew(), CTX_2);
    assertNotNull(jtx2);
    DbSession session2 = sessionProvider.getDbSession();
    assertNotSame(session1, session2);
    executeUpdate(session2, "insert into GIRL values(2, 'Gloria', null)");
    assertTrue(worker.maybeCommitTransaction(jtx2));
    assertFalse(jtx2.isActive());

    // session #1: rollback
    assertTrue(worker.markOrRollbackTransaction(jtx, null));
    assertFalse(jtx.isActive());
    assertFalse(jtx.isCommitted());

    // test
    session1 = new DbSession(cp);
View Full Code Here

    return new JtxTransactionMode().propagationMandatory().readOnly(false);
  }

  @Test
  public void testRequiredToMandatoryCommit() {
    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, mandatory
    JtxTransaction jtx2 = worker.maybeRequestTransaction(mandatory(), CTX_2);
    assertNull(jtx2);
    DbSession session2 = sessionProvider.getDbSession();
    assertSame(session1, session2);
    executeUpdate(session2, "insert into GIRL values(2, 'Gloria', null)");
    assertFalse(worker.maybeCommitTransaction(jtx2));
    assertTrue(jtx.isActive());

    // session #1: commit
    assertTrue(worker.maybeCommitTransaction(jtx));
    assertFalse(jtx.isActive());
    assertTrue(jtx.isCommitted());

    // test
    session1 = new DbSession(cp);
View Full Code Here

    session1.closeSession();
  }

  @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) {
    }
  }
View Full Code Here

    jtxManager.registerResourceManager(new WorkResourceManager());
    return jtxManager;
  }

  private LeanJtxWorker createWorker() {
    return new LeanJtxWorker(createManager());
  }
View Full Code Here

  }

  @Test
  public void testPropagationRequiredWithWorker() {

    LeanJtxWorker worker = createWorker();

    JtxTransaction jtx1 = worker.maybeRequestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false), null);
    WorkSession work1 = jtx1.requestResource(WorkSession.class);
    assertEquals(1, worker.getTransactionManager().totalTransactions());
    work1.writeValue("one");
    assertEquals("[1] one", work1.readValue());

    JtxTransaction jtx2 = worker.maybeRequestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false), null);
    assertEquals(1, worker.getTransactionManager().totalTransactions());
    assertNull(jtx2);

    WorkSession work2 = jtx1.requestResource(WorkSession.class);
    assertSame(work2, work1);
    work2.writeValue("two");
    assertEquals("[1] two", work2.readValue());
    assertFalse(worker.maybeCommitTransaction(jtx2));

    work1.writeValue("three");
    assertEquals("[1] three", work1.readValue());
    assertTrue(worker.maybeCommitTransaction(jtx1));
  }
View Full Code Here

TOP

Related Classes of jodd.jtx.worker.LeanJtxWorker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.