Package com.sleepycat.je

Examples of com.sleepycat.je.DatabaseEntry


    }

    /** {@inheritDoc} */
    public void markForUpdate(DbTransaction txn, byte[] key) {
  try {
      DatabaseEntry valueEntry = new DatabaseEntry();
      /* Ignore value by truncating to zero bytes */
      valueEntry.setPartial(0, 0, true);
      OperationStatus status = db.get(
    JeTransaction.getJeTxn(txn), new DatabaseEntry(key),
    valueEntry, LockMode.RMW);
      if (status != SUCCESS && status != NOTFOUND) {
    throw new DbDatabaseException("Operation failed: " + status);
      }
  } catch (DatabaseException e) {
View Full Code Here


    /** {@inheritDoc} */
    public void put(DbTransaction txn, byte[] key, byte[] value) {
  try {
      OperationStatus status = db.put(
    JeTransaction.getJeTxn(txn), new DatabaseEntry(key),
    new DatabaseEntry(value));
      if (status != SUCCESS) {
    throw new DbDatabaseException("Operation failed: " + status);
      }
  } catch (DatabaseException e) {
      throw JeEnvironment.convertException(e, true);
View Full Code Here

    public boolean putNoOverwrite(
  DbTransaction txn, byte[] key, byte[] value)
    {
  try {
      OperationStatus status = db.putNoOverwrite(
    JeTransaction.getJeTxn(txn), new DatabaseEntry(key),
    new DatabaseEntry(value));
      if (status == SUCCESS) {
    return true;
      } else if (status == KEYEXIST) {
    return false;
      } else {
View Full Code Here

    /** {@inheritDoc} */
    public boolean delete(DbTransaction txn, byte[] key) {
  try {
      OperationStatus status = db.delete(
    JeTransaction.getJeTxn(txn), new DatabaseEntry(key));
      if (status == SUCCESS) {
    return true;
      } else if (status == NOTFOUND) {
    return false;
      } else {
View Full Code Here

            if (secretKey != null) {
                Cipher cipher = Cipher.getInstance("AES");
                cipher.init(Cipher.ENCRYPT_MODE, secretKey);
                eventData = cipher.doFinal(eventData);
            }
            final DatabaseEntry key = new DatabaseEntry(keyData);
            final DatabaseEntry data = new DatabaseEntry(eventData);
            Transaction txn = environment.beginTransaction(null, null);
            try {
                database.put(txn, key, data);
                txn.commit();
                queue.add(keyData);
View Full Code Here

                long now = System.currentTimeMillis();
                if (database.count() >= batchSize || (database.count() > 0 && nextBatch < now)) {
                    nextBatch = now + manager.delay;
                    try {
                        boolean errors = false;
                        DatabaseEntry key = new DatabaseEntry();
                        final DatabaseEntry data = new DatabaseEntry();

                        queue.clear();
                        OperationStatus status;
                        if (batchSize > 1) {
                            Cursor cursor = database.openCursor(null, CursorConfig.DEFAULT);
                            try {
                                status = cursor.getFirst(key, data, null);

                                BatchEvent batch = new BatchEvent();
                                for (int i = 0; status == OperationStatus.SUCCESS && i < batchSize; ++i) {
                                    SimpleEvent event = createEvent(data);
                                    if (event != null) {
                                        batch.addEvent(event);
                                    }
                                    status = cursor.getNext(key, data, null);
                                }
                                try {
                                    manager.send(batch);
                                } catch (Exception ioe) {
                                    LOGGER.error("Error sending events", ioe);
                                    break;
                                }
                                cursor.close();
                                cursor = null;
                                Transaction txn = environment.beginTransaction(null, null);
                                try {
                                    for (Event event : batch.getEvents()) {
                                        try {
                                            Map<String, String> headers = event.getHeaders();
                                            key = new DatabaseEntry(headers.get(FlumeEvent.GUID).getBytes(UTF8));
                                            database.delete(txn, key);
                                        } catch (Exception ex) {
                                            LOGGER.error("Error deleting key from database", ex);
                                        }
                                    }
View Full Code Here

   * @return the docid of the url if it is seen before. Otherwise -1 is
   *         returned.
   */
  public synchronized int getDocId(String url) {
    OperationStatus result;
    DatabaseEntry value = new DatabaseEntry();
    try {
      DatabaseEntry key = new DatabaseEntry(url.getBytes());
      result = db.get(null, key, value, null);

      if (result == OperationStatus.SUCCESS
          && value.getData().length > 0) {
        return CommonUtil.byteArray2Int(value.getData());
View Full Code Here

      if (docid > 0) {
        return docid;
      }

      lastDocID++;
      db.put(null, new DatabaseEntry(url.getBytes()), new DatabaseEntry(CommonUtil.int2ByteArray(lastDocID)));
      return lastDocID;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return -1;
View Full Code Here

        return;
      }
      throw new Exception("Doc id: " + prevDocid + " is already assigned to URL: " + url);
    }
   
    db.put(null, new DatabaseEntry(url.getBytes()), new DatabaseEntry(CommonUtil.int2ByteArray(docId)));
    lastDocID = docId;
  }
View Full Code Here

               cursor = db.openCursor(currentTransaction.getTransaction(), null);
               for (int i = 0; i < recordCount; i++) {
                  byte[] keyBytes = (byte[]) ois.readObject();
                  byte[] dataBytes = (byte[]) ois.readObject();

                  DatabaseEntry key = new DatabaseEntry(keyBytes);
                  DatabaseEntry data = new DatabaseEntry(dataBytes);
                  cursor.put(key, data);
               }
            } finally {
               if (cursor != null) cursor.close();
            }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.DatabaseEntry

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.