Exemplo n.º 1
0
  public void testInTransaction() throws Exception {
    TransactionStuff txl = SqlObjectBuilder.attach(handle, TransactionStuff.class);
    txl.insert(7, "Keith");

    Something s =
        txl.inTransaction(
            new Transaction<Something, TransactionStuff>() {
              public Something inTransaction(TransactionStuff conn, TransactionStatus status)
                  throws Exception {
                return conn.byId(7);
              }
            });

    assertEquals("Keith", s.getName());
  }
Exemplo n.º 2
0
  public void testTransactionIsolationActuallyHappens() throws Exception {
    TransactionStuff txl = SqlObjectBuilder.attach(handle, TransactionStuff.class);
    TransactionStuff tx2 = SqlObjectBuilder.open(dbi, TransactionStuff.class);

    txl.insert(8, "Mike");

    txl.begin();

    txl.updateName(8, "Miker");
    assertEquals("Miker", txl.byId(8).getName());
    assertEquals("Mike", tx2.byId(8).getName());

    txl.commit();

    assertEquals("Miker", tx2.byId(8).getName());

    tx2.close();
  }
Exemplo n.º 3
0
  public void testBeginAndCommitTransaction() throws Exception {
    TransactionStuff txl = SqlObjectBuilder.attach(handle, TransactionStuff.class);

    txl.insert(8, "Mike");

    txl.begin();
    txl.updateName(8, "Miker");
    assertEquals("Miker", txl.byId(8).getName());
    txl.rollback();

    assertEquals("Mike", txl.byId(8).getName());
  }