Package jodd.db.jtx

Examples of jodd.db.jtx.DbJtxSessionProvider


    AnnotationTxAdviceManager annTxAdviceManager = new AnnotationTxAdviceManager(jtxManager, jtxScopePattern);
    annTxAdviceManager.registerAnnotations(jtxAnnotations);
    AnnotationTxAdviceSupport.manager = annTxAdviceManager;

    DbSessionProvider sessionProvider = new DbJtxSessionProvider(jtxManager);

    // global settings
    DbManager dbManager = DbManager.getInstance();
    dbManager.setConnectionProvider(connectionProvider);
    dbManager.setSessionProvider(sessionProvider);
View Full Code Here


  @Test
  public void testSessionProvider() {
    // prepare
    JtxTransactionManager jtxManager = new DbJtxTransactionManager(cp);
    DbJtxSessionProvider sessionProvider = new DbJtxSessionProvider(jtxManager);
    DbManager.getInstance().setSessionProvider(sessionProvider);

    for (int i = 0; i < 2; i++) {

      // start, 0 transactions, no session
      assertEquals(0, jtxManager.totalTransactions());

      // start transaction
      jtxManager.requestTransaction(new JtxTransactionMode());

      // get session from provider!
      DbSession dbSession = sessionProvider.getDbSession();
      assertNotNull(dbSession);

      // transaction started, but connection not yet fetched as it is not used yet
      assertEquals(1, jtxManager.totalTransactions());
      assertEquals(0, cp.getConnectionsCount().getBusyCount());

      // same session as it is the same transaction
      DbSession dbSession2 = sessionProvider.getDbSession();
      assertNotNull(dbSession2);
      assertSame(dbSession, dbSession2);

      // create query, session is get from provider, the very same one
      DbQuery dbQuery = new DbQuery("SELECT 173 FROM (VALUES(0))");
View Full Code Here

  }

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

    // session #1: required - commit
    JtxTransaction jtx = worker.maybeRequestTransaction(required(), CTX_1);
    assertTrue(jtx.isActive());
    assertNotNull(jtx);
    DbSession session = sessionProvider.getDbSession();

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

    // session #2: required - rollback
    jtx = worker.maybeRequestTransaction(required(), CTX_1);
    assertNotNull(jtx);
    session = sessionProvider.getDbSession();
    executeUpdate(session, "insert into GIRL values(2, 'Gloria', null)");
    assertTrue(worker.markOrRollbackTransaction(jtx, null));

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

  }

  @Test
  public void testRequiredToRequiredCommit() {
    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, required
    JtxTransaction jtx2 = worker.maybeRequestTransaction(required(), 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());
View Full Code Here

  }

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

  }

  @Test
  public void testSupportsToRequiredCommit() {
    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(required(), 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());
View Full Code Here

  }

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

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

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

    // session #2: required - rollback
    jtx = worker.maybeRequestTransaction(supports(), CTX_2);
    assertNotNull(jtx);
    session = sessionProvider.getDbSession();
    executeUpdate(session, "insert into GIRL values(2, 'Gloria', null)");
    assertTrue(worker.markOrRollbackTransaction(jtx, null));

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

  }

  @Test
  public void testRequiredToSupportsCommit() {
    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, supports
    JtxTransaction jtx2 = worker.maybeRequestTransaction(supports(), 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());
View Full Code Here


  @Test
  public void testSupportsToSupportsCommit() {
    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(supports(), 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());
View Full Code Here

  }

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

TOP

Related Classes of jodd.db.jtx.DbJtxSessionProvider

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.