Package org.helidb.txn

Examples of org.helidb.txn.Transaction


  }

  @Test
  public void testClearTransactionAtRollback()
  {
    Transaction txn = Transaction.startTransaction(false);
    assertSame(txn, Transaction.getCurrentTransaction());
    txn.rollback();
    assertNull(Transaction.getCurrentTransactionOrNull());
  }
View Full Code Here


  }

  @Override
  protected void tearDownDatabase(Database<?, ?> db)
  {
    Transaction txn = Transaction.getCurrentTransactionOrNull();
    // The transaction may already be rolled back if we're working with
    // several databases.
    if (txn != null)
    {
      txn.rollback();
    }

    db.close();
    Directory dbDir = m_dbDirs.remove(Integer.valueOf(System.identityHashCode(db)));
    if (dbDir != null)
View Full Code Here

   * Load some data into the database.
   */
  protected void populateDb(Database<String, String> db)
  {
    boolean successful = false;
    Transaction txn = Transaction.startTransaction(false);
    try
    {
      db.fasterInsert("key1", "value1");
      db.fasterInsert("key10", "value10");
      assertEquals("value1", db.get("key1"));
      assertEquals("value10", db.get("key10"));
      txn.commit();
      successful = true;
    }
    finally
    {
      if (!successful)
      {
        txn.rollback();
      }
    }
    assertNull(Transaction.getCurrentTransactionOrNull());
  }
View Full Code Here

    Database<String, String> db = createDatabaseWoTxn();
    try
    {
      populateDb(db);

      Transaction txn = Transaction.startTransaction(true);
      try
      {
        assertEquals("value1", db.get("key1"));
        assertEquals("value10", db.get("key10"));
      }
      finally
      {
        txn.rollback();
      }
    }
    finally
    {
      tearDownDatabase(db);
View Full Code Here

  public void testRollback()
  {
    Database<String, String> db = createDatabaseWoTxn();
    try
    {
      Transaction txn = Transaction.startTransaction(false);
      try
      {
        db.fasterInsert("key1", "value1");
        db.fasterInsert("key10", "value10");
        assertEquals("value1", db.get("key1"));
        assertEquals("value10", db.get("key10"));
      }
      finally
      {
        txn.rollback();
      }

      txn = Transaction.startTransaction(true);
      try
      {
        assertNull(db.get("key1"));
        assertNull(db.get("key10"));
      }
      finally
      {
        txn.rollback();
      }
    }
    finally
    {
      tearDownDatabase(db);
View Full Code Here

      catch (NoTransactionException e)
      {
        // ok
      }

      Transaction txn = Transaction.startTransaction(true);
      try
      {
        assertEquals("value1", db.get("key1"));
      }
      finally
      {
        txn.rollback();
      }
    }
    finally
    {
      tearDownDatabase(db);
View Full Code Here

    try
    {
      populateDb(db);

      assertNull(Transaction.getCurrentTransactionOrNull());
      Transaction txn = Transaction.startTransaction(true);
      try
      {
        try
        {
          db.fasterInsert("key11", "value11");
          fail();
        }
        catch (ReadOnlyTransactionException e)
        {
          // ok
        }

        assertNull(db.get("key11"));
      }
      finally
      {
        txn.commit();
      }

      txn = Transaction.startTransaction(true);
      try
      {
        assertNull(db.get("key11"));
      }
      finally
      {
        txn.rollback();
      }
    }
    finally
    {
      tearDownDatabase(db);
View Full Code Here

    Database<String, String> db = createDatabaseWoTxn();
    try
    {
      populateDb(db);
      boolean committed = false;
      Transaction txn = Transaction.startTransaction(false);
      try
      {
        db.fasterInsert("key11", "value11");
        tearDownDatabase(db);
        destroyed = true;
        committed = true;
        try
        {
          txn.commit();
        }
        catch (IllegalStateException e)
        {
          // ok
        }
      }
      finally
      {
        if (!committed)
        {
          txn.rollback();
        }
      }
    }
    finally
    {
View Full Code Here

    Database<String, String> db = createDatabaseWoTxn();
    try
    {
      populateDb(db);
      boolean committed = false;
      Transaction txn = Transaction.startTransaction(false);
      try
      {
        db.fasterInsert("key11", "value11");
        tearDownDatabase(db);
        destroyed = true;
        committed = true;
        try
        {
          txn.rollback();
        }
        catch (IllegalStateException e)
        {
          // ok
        }
      }
      finally
      {
        if (!committed)
        {
          txn.rollback();
        }
      }
    }
    finally
    {
View Full Code Here

  public void testInsertCommit()
  {
    Database<String, String> db = createDatabaseWoTxn();
    try
    {
      Transaction txn = Transaction.startTransaction(false);
      try
      {
        db.insert("key 1", "value 1");
        db.insert("key 2", "value 2");
        txn.commit();

        txn = Transaction.startTransaction(true);
        assertEquals(2, db.size());
        assertEquals("value 2", db.get("key 2"));
        assertEquals("value 1", db.get("key 1"));
      }
      finally
      {
        txn.rollback();
      }
    }
    finally
    {
      tearDownDatabase(db);
View Full Code Here

TOP

Related Classes of org.helidb.txn.Transaction

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.