Package com.sleepycat.je

Examples of com.sleepycat.je.Transaction


   * @param itr
   */
  public void insertRecords(final Iterator<BDBRecord> itr) {
    OperationStatus status = null;
    try {
      Transaction txn = env.beginTransaction(null, null);
      try {
        Cursor cursor = db.openCursor(txn, null);
        while (itr.hasNext()) {
          BDBRecord record = (BDBRecord) itr.next();
          status = cursor.put(record.getKey(), record.getValue());
          if (status != OperationStatus.SUCCESS) {
            throw new RuntimeException("put() non-success status");
          }
        }
        cursor.close();
        txn.commit();
      } catch (DatabaseException e) {
        if(txn != null) {
          txn.abort();
        }
        e.printStackTrace();
      }
    } catch (DatabaseException e) {
      e.printStackTrace();
View Full Code Here


                abort();
            }
        };

        Transaction transaction = _environment.beginTransaction(null, null);
        new DatabaseTemplate(_environment, OLD_CONTENT_DB_NAME, transaction).run(cursorOperation);
        transaction.commit();
    }
View Full Code Here

    */
   protected void prepare(List<? extends Modification> mods, GlobalTransaction tx) throws CacheLoaderException {
      if (trace) log.tracef("preparing transaction %s", tx);
      try {
         transactionRunner.prepare(new ModificationsTransactionWorker(this, mods));
         Transaction txn = currentTransaction.getTransaction();
         if (trace) log.tracef("transaction %s == sleepycat transaction %s", tx, txn);
         txnMap.put(tx, txn);
         ((ThreadLocal)ReflectionUtil.getValue(currentTransaction, "localTrans")).remove();
      } catch (Exception e) {
         throw convertToCacheLoaderException("Problem preparing transaction", e);
View Full Code Here

    * @param tx     java transaction used to lookup a SleepyCat transaction
    * @param commit true to commit false to abort
    * @throws CacheLoaderException if there are problems committing or aborting the transaction
    */
   protected void completeTransaction(GlobalTransaction tx, boolean commit) throws CacheLoaderException {
      Transaction txn = txnMap.remove(tx);
      if (txn != null) {
         if (trace) log.tracef("%s sleepycat transaction %s", commit ? "committing" : "aborting", txn);
         try {
            if (commit)
               txn.commit();
            else
               txn.abort();
         } catch (Exception caught) {
            throw convertToCacheLoaderException("Problem completing transaction", caught);
         }
      } else {
         if (trace) log.tracef("no sleepycat transaction associated  transaction %s", tx);
View Full Code Here

    *
    * @see TransactionRunner#run(com.sleepycat.collections.TransactionWorker)
    */
   public void prepare(TransactionWorker worker) throws Exception {
      for (int currentTries = 0; ; currentTries++) {
         Transaction txn = null;
         try {
            txn = currentTxn.beginTransaction(getTransactionConfig());
            worker.doWork();
            return;
         } catch (Throwable caught) {
View Full Code Here

                abort();
            }
        };

        Transaction transaction = _environment.beginTransaction(null, null);
        new DatabaseTemplate(_environment, OLD_CONTENT_DB_NAME, transaction).run(cursorOperation);
        transaction.commit();
    }
View Full Code Here

    // 生成总的索引数据
    keyBinding.objectToEntry(keys, key);
    if (dbMain.get(null, key, data, null) != OperationStatus.SUCCESS) {
      synchronized (this) {
        if (dbMain.get(null, key, data, null) != OperationStatus.SUCCESS) {
          Transaction tran = env.beginTransaction(null, null);
          try {
            cache.create();
          } catch (Exception e) {
            throw new InvocationTargetException(e);
          }
          try {
            dataBinding.objectToEntry(cache, data);
            dbMain.put(tran, key, data);
            tran.commit();
          } catch (Exception e) {
            tran.abort();
            throw e;
          }
        }
      }
    }
View Full Code Here

   *           数据操作异常
   */
  public void clear(String name) throws Exception {
    SecondaryDatabase db = dbKeys.get(name);
    if (db != null) {
      Transaction tran = env.beginTransaction(null, null);
      DatabaseEntry key = new DatabaseEntry();
      DatabaseEntry pKey = new DatabaseEntry();
      DatabaseEntry data = new DatabaseEntry();
      try {
        SecondaryCursor cursor = db.openSecondaryCursor(tran, null);
        try {
          while (cursor.getNext(key, pKey, data, null) == OperationStatus.SUCCESS) {
            cursor.delete();
            dataBinding.entryToObject(data).remove();
          }
        } finally {
          cursor.close();
        }
        tran.commit();
      } catch (Exception e) {
        tran.abort();
        throw e;
      }
    }
  }
View Full Code Here

            break;
          }
          cursor.close();
        }
      }
      Transaction tran = env.beginTransaction(null, null);
      try {
        Cursor cursor = dbMain.openCursor(tran, null);
        try {
          for (DatabaseEntry entry : entries) {
            cursor.getSearchKey(entry, data, null);
            cursor.delete();
            dataBinding.entryToObject(data).remove();
          }
        } finally {
          cursor.close();
        }
        tran.commit();
      } catch (Exception e) {
        tran.abort();
        throw e;
      }
    }
  }
View Full Code Here

   *           数据操作异常
   */
  private void clear(IMetaData data) throws Exception {
    SecondaryDatabase db = dbKeys.get(data.getName());
    if (db != null) {
      Transaction tran = env.beginTransaction(null, null);
      DatabaseEntry key = new DatabaseEntry(data.getBytes());
      DatabaseEntry pKey = new DatabaseEntry();
      DatabaseEntry pData = new DatabaseEntry();
      try {
        SecondaryCursor cursor = db.openSecondaryCursor(tran, null);
        try {
          OperationStatus ret = cursor.getSearchKey(key, pKey, pData, null);
          while (ret == OperationStatus.SUCCESS) {
            cursor.delete();
            dataBinding.entryToObject(pData).remove();
            ret = cursor.getNextDup(pKey, pData, null);
          }
        } finally {
          cursor.close();
        }
        tran.commit();
      } catch (Exception e) {
        tran.abort();
        throw e;
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.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.