Package com.sleepycat.je

Examples of com.sleepycat.je.DatabaseEntry


         *
         * @return true if successfully fetched one more key, false if end of
         *         keys
         */
        private boolean fetchNextKey() {
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry valueEntry = new DatabaseEntry();
            OperationStatus status;
            valueEntry.setPartial(true);
            try {
                if(!positioned) {
                    positioned = true;
                    keyEntry.setData(StoreBinaryFormat.makePartitionKey(partition));
                    status = cursor.getSearchKeyRange(keyEntry,
View Full Code Here


    }

    @Override
    public void transfer() throws Exception {
        cursor = srcDB.openCursor(null, null);
        DatabaseEntry keyEntry = new DatabaseEntry();
        DatabaseEntry valueEntry = new DatabaseEntry();

        byte[] prevKey = null;
        List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();

        long startTime = System.currentTimeMillis();
        int scanCount = 0;
        int keyCount = 0;
        while(cursor.getNext(keyEntry, valueEntry, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            scanCount++;
            if(scanCount % 1000000 == 0)
                logger.info("Converted " + scanCount + " entries in "
                            + (System.currentTimeMillis() - startTime) / 1000 + " secs");

            // read the value as a versioned Object
            VectorClock clock = new VectorClock(valueEntry.getData());
            byte[] bytes = ByteUtils.copy(valueEntry.getData(),
                                          clock.sizeInBytes(),
                                          valueEntry.getData().length);
            Versioned<byte[]> value = new Versioned<byte[]>(bytes, clock);
            byte[] key = keyEntry.getData();

            if(prevKey != null && (ByteUtils.compare(prevKey, key) != 0)) {
                // there is a new key; write out the buffered values and
                // previous key
                OperationStatus putStatus = dstDB.put(null,
                                                      new DatabaseEntry(prevKey),
                                                      new DatabaseEntry(StoreBinaryFormat.toByteArray(vals)));
                if(OperationStatus.SUCCESS != putStatus) {
                    String errorStr = "Put failed with " + putStatus + " for key"
                                      + BdbConvertData.writeAsciiString(prevKey);
                    logger.error(errorStr);
                    throw new Exception(errorStr);
                }
                vals = new ArrayList<Versioned<byte[]>>();
                keyCount++;
            }

            vals.add(value);
            prevKey = key;
        }
        if(vals.size() > 0) {
            OperationStatus putStatus = dstDB.put(null,
                                                  new DatabaseEntry(prevKey),
                                                  new DatabaseEntry(StoreBinaryFormat.toByteArray(vals)));
            if(OperationStatus.SUCCESS != putStatus) {
                String errorStr = "Put failed with " + putStatus + " for key"
                                  + BdbConvertData.writeAsciiString(prevKey);
                logger.error(errorStr);
                throw new Exception(errorStr);
View Full Code Here

    databasePut(key, value);
  }
 
  protected OperationStatus databasePut(Object key, String value){
    /* DatabaseEntry represents the key and data of each record */
    final DatabaseEntry keyEntry = new DatabaseEntry();
    final DatabaseEntry dataEntry = new DatabaseEntry();
   
    /* Use a binding to convert the int into a DatabaseEntry. */   
    objectToEntry(key, keyEntry);
    StringBinding.stringToEntry(value, dataEntry);

View Full Code Here

        .split(SystemParameters.BDB_TUPLE_DELIMITER));
  }
 
  protected String getValue(Object key) {
    // initialize key
    final DatabaseEntry keyEntry = new DatabaseEntry();
    final DatabaseEntry dataEntry = new DatabaseEntry();
    objectToEntry(key, keyEntry);

    // initialize cursor
    final Cursor cursor = _db.openCursor(null, null);
    final OperationStatus status = cursor.getSearchKey(keyEntry, dataEntry, LockMode.DEFAULT);
View Full Code Here

  protected List<String> getRange(Object leftBoundary, boolean includeLeft, Object rightBoundary, boolean includeRight) {
    final List<String> result = new ArrayList<String>();

    // initialize left and rightBoundary
    final DatabaseEntry keyEntry = new DatabaseEntry();
    final DatabaseEntry dataEntry = new DatabaseEntry();
    objectToEntry(leftBoundary, keyEntry);

    // initialize cursor
    final Cursor cursor = _db.openCursor(null, null);
    OperationStatus status = cursor.getSearchKeyRange(keyEntry, dataEntry, LockMode.DEFAULT);
View Full Code Here

    put((KeyType) key51, value51);
    put((KeyType) key52, value52);

    // print everything
    final Cursor cursor = _db.openCursor(null, null);
    final DatabaseEntry keyEntry = new DatabaseEntry();
    final DatabaseEntry dataEntry = new DatabaseEntry();
    while (cursor.getNext(keyEntry, dataEntry, LockMode.DEFAULT) == OperationStatus.SUCCESS)
      System.out.println("key=" + entryToObject(keyEntry) + " data="
          + StringBinding.entryToString(dataEntry));
    cursor.close();
View Full Code Here

    put((KeyType) key51, value51);
    put((KeyType) key52, value52);

    // print everything
    final Cursor cursor = _db.openCursor(null, null);
    final DatabaseEntry keyEntry = new DatabaseEntry();
    final DatabaseEntry dataEntry = new DatabaseEntry();
    while (cursor.getNext(keyEntry, dataEntry, LockMode.DEFAULT) == OperationStatus.SUCCESS)
      System.out.println("key=" + entryToObject(keyEntry) + " data="
          + StringBinding.entryToString(dataEntry));
    cursor.close();
View Full Code Here

  }
    }

    /** {@inheritDoc} */
    public boolean findNext(byte[] key) {
  DatabaseEntry searchEntry = new DatabaseEntry(key);
  try {
      OperationStatus status =
    cursor.getSearchKeyRange(searchEntry, valueEntry, null);
      if (status == SUCCESS) {
    keyEntry = searchEntry;
View Full Code Here

    }

    /** {@inheritDoc} */
    public boolean putNoOverwrite(byte[] key, byte[] value) {
  try {
      DatabaseEntry putKeyEntry = new DatabaseEntry(key);
      DatabaseEntry putValueEntry = new DatabaseEntry(value);
      OperationStatus status = cursor.putNoOverwrite(
    putKeyEntry, putValueEntry);
      if (status == SUCCESS) {
    isCurrent = true;
    keyEntry = putKeyEntry;
View Full Code Here

    /* -- Implement DbDatabase -- */

    /** {@inheritDoc} */
    public byte[] get(DbTransaction txn, byte[] key, boolean forUpdate) {
  try {
      DatabaseEntry valueEntry = new DatabaseEntry();
      OperationStatus status = db.get(
    JeTransaction.getJeTxn(txn), new DatabaseEntry(key),
    valueEntry, forUpdate ? LockMode.RMW : null);
      if (status == SUCCESS) {
    return convertData(valueEntry.getData());
      } else if (status == NOTFOUND) {
    return null;
      } else {
    throw new DbDatabaseException("Operation failed: " + status);
      }
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.