Package org.helidb.txn

Examples of org.helidb.txn.Transaction


  {
    TransactionalDatabase<Integer, Long> db1 = createDatabaseWoTxn();
    try
    {
      populateDb(db1);
      Transaction txn = Transaction.startTransaction(false);
      try
      {
        db1.delete(1);
        db1.update(123, 10000L);
        db1.insert(2, 2L);

        TransactionalDatabase<Integer, Long> db2 = createNewDatabaseUsingSameFilesButTruncateRollbackLog(db1, howMuchToTruncate);
        try
        {
          // This should contain the old values.
          assertEquals(234L, db2.get(123).longValue());
          assertEquals(2L, db2.get(1).longValue());

          // ...and this
          assertEquals(2L, db2.get(2).longValue());
        }
        finally
        {
          tearDownDatabase(db2);
        }
      }
      finally
      {
        if (!txn.isFinished())
        {
          txn.rollback();
        }
      }
    }
    finally
    {
View Full Code Here


    final int noOfRecords = tc.getNoOfBaseRecords();
    System.out.println("Inserting " + noOfRecords + " records in " + dbs.size() + " databases");
    long start = System.currentTimeMillis();
    for (Database<Integer, Long> db : dbs)
    {
      Transaction txn = null;
      try
      {
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn = Transaction.startTransaction(false);
        }
        for (int i = 0; i < noOfRecords; i++)
        {
          db.insert(s_crs_keys[i], s_crs_values[i]);
        }
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn.commit();
          txn = null;
        }
      }
      finally
      {
        if (txn != null)
        {
          txn.rollback();
        }
      }
    }
    long time = System.currentTimeMillis() - start;
    double res = (float) time / (noOfRecords * dbs.size());
 
View Full Code Here

    final int noOfRecords = tc.getNoOfBaseRecords();
    System.out.println("Selecting " + noOfRecords + " records in " + dbs.size() + " databases");
    long start = System.currentTimeMillis();
    for (Database<Integer, Long> db : dbs)
    {
      Transaction txn = null;
      try
      {
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn = Transaction.startTransaction(true);
        }
        for (int i = 0; i < noOfRecords; i++)
        {
          db.get(s_crs_keys[i]);
        }
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn.commit();
          txn = null;
        }
      }
      finally
      {
        if (txn != null)
        {
          txn.rollback();
        }
      }
    }
    long time = System.currentTimeMillis() - start;
    double res = (float) time / (noOfRecords * dbs.size());
 
View Full Code Here

      try
      {
        LoggingTransactionalDatabase<String, String, Long> db2 = new LoggingTransactionalDatabase<String, String, Long>(new HeapBackend<String, String>(new ReadWritableFileAdapter(f2), false, StringSerializer.INSTANCE, StringSerializer.INSTANCE, lah), new ReadWritableFileAdapter(f2l), StringSerializer.INSTANCE, StringSerializer.INSTANCE, lah);
        try
        {
          Transaction txn = Transaction.startTransaction(false);
          db2.insert("years", "2007");
          txn.commit();

          runExampleMethodTest("pg/ex/ex_transaction.javaa", codePrefix, "return null;\r\n", null, new Object[] { db1, db2 }, null);

          txn = Transaction.startTransaction(true);
          try
          {
            assertEquals(1, db1.size());
            assertTrue(db1.containsKey("lastUpdate"));
            assertEquals(1, db2.size());
            assertEquals("2007, 2008", db2.get("years"));
          }
          finally
          {
            txn.rollback();
          }
        }
        finally
        {
          db2.close();
View Full Code Here

  {
    TransactionalDatabase<String, String> db1 = createDatabaseWoTxn();
    try
    {
      populateDb(db1);
      Transaction txn = Transaction.startTransaction(false);
      try
      {
        db1.delete("key1");
        db1.update("key10", "value10p");
        db1.insert("key2", "value2");

        TransactionalDatabase<String, String> db2 = createNewDatabaseUsingSameFilesButTruncateRollbackLog(db1, howMuchToTruncate);
        try
        {
          // This should contain the old values.
          assertEquals("value1", db2.get("key1"));
          assertEquals("value10", db2.get("key10"));

          // ...and this
          assertEquals("value2", db2.get("key2"));
        }
        finally
        {
          tearDownDatabase(db2);
        }
      }
      finally
      {
        if (!txn.isFinished())
        {
          txn.rollback();
        }
      }
    }
    finally
    {
View Full Code Here

    }
  }

  public void joinTransaction(boolean readOnly)
  {
    Transaction txn = Transaction.getCurrentTransaction();
    if (txn.isReadOnly())
    {
      if (!readOnly)
      {
        throw new ReadOnlyTransactionException();
      }
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  @Override
  protected DatabaseBackend<K, V, P> getBackendForWriting() throws NoTransactionException, ReadOnlyTransactionException, WrappedIOException
  {
    Transaction txn = Transaction.getCurrentTransaction();
    TransactionCollaborator tc = txn.getCollaborator(this);

    if (tc == null)
    {
      if (txn.isReadOnly())
      {
        throw new ReadOnlyTransactionException();
      }

      tc = joinReadWriteTransaction(txn);
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  @Override
  protected DatabaseBackend<K, V, P> getBackendForReading() throws NoTransactionException, WrappedIOException
  {
    Transaction txn = Transaction.getCurrentTransaction();
    TransactionCollaborator<K, V, P> tc = (TransactionCollaborator<K, V, P>) txn.getCollaborator(this);

    if (tc == null)
    {
      if (getLogAdapterHolder().isDebugEnabled())
      {
        getLogAdapterHolder().logDebug("Joining transaction " + txn);
      }
      tc = (txn.isReadOnly() ? joinReadOnlyTransaction(txn) : joinReadWriteTransaction(txn));
    }
    return tc.getBackend();
  }
View Full Code Here

    final int noOfRecords = tc.getNoOfBaseRecords();
    System.out.print("Iterating over " + noOfRecords + " keys in " + dbs.size() + " databases");
    long start = System.currentTimeMillis();
    for (Database<?, ?> db : dbs)
    {
      Transaction txn = null;
      try
      {
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn = Transaction.startTransaction(true);
        }
        Iterator<?> itr = db.keyIterator();
        while (itr.hasNext())
        {
          itr.next();
        }
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn.commit();
          txn = null;
        }
      }
      finally
      {
        if (txn != null)
        {
          txn.rollback();
        }
      }
    }
    long time = System.currentTimeMillis() - start;
    double res = (float) time / (noOfRecords * dbs.size());
 
View Full Code Here

    final int noOfRecords = tc.getNoOfBaseRecords();
    System.out.print("Iterating over " + noOfRecords + " records in " + dbs.size() + " databases");
    long start = System.currentTimeMillis();
    for (Database<?, ?> db : dbs)
    {
      Transaction txn = null;
      try
      {
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn = Transaction.startTransaction(true);
        }
        Iterator<? extends Record<?, ?>> itr = db.iterator();
        while (itr.hasNext())
        {
          itr.next();
        }
        if (db instanceof TransactionalDatabase<?, ?>)
        {
          txn.commit();
          txn = null;
        }
      }
      finally
      {
        if (txn != null)
        {
          txn.rollback();
        }
      }
    }
    long time = System.currentTimeMillis() - start;
    double res = (float) time / (noOfRecords * dbs.size());
 
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.