Package com.sleepycat.je

Examples of com.sleepycat.je.Cursor$KeyChangeStatus


        throw new IOException("File does not exist: " + name);
    }

    @Override
    public String[] listAll() throws IOException {
        Cursor cursor = null;
        List<String> list = new ArrayList<String>();

        try {
            try {
                DatabaseEntry key = new DatabaseEntry(new byte[0]);
                DatabaseEntry data = new DatabaseEntry(null);

                data.setPartial(true);
                // TODO see if cursor needs configuration
                cursor = files.openCursor(txn, null);
                // TODO see if LockMode should be set
                if (cursor.getNext(key, data, null) != OperationStatus.NOTFOUND) {
                    ByteArrayInputStream buffer = new ByteArrayInputStream(key
                            .getData());
                    DataInputStream in = new DataInputStream(buffer);
                    String name = in.readUTF();

                    in.close();
                    list.add(name);

                    while (cursor.getNext(key, data, null) != OperationStatus.NOTFOUND) {
                        buffer = new ByteArrayInputStream(key.getData());
                        in = new DataInputStream(buffer);
                        name = in.readUTF();
                        in.close();

                        list.add(name);
                    }
                }
            } finally {
                if (cursor != null)
                    cursor.close();
            }
        } catch (DatabaseException e) {
            throw new IOException(e.getMessage());
        }
View Full Code Here


        System.out.println(" total milliseconds to delete");

        System.out.print(end.getTime() - veryStart.getTime());
        System.out.println(" total milliseconds");

        Cursor cursor = null;
        try {
            cursor = index.openCursor(null, null);

            DatabaseEntry foundKey = new DatabaseEntry();
            DatabaseEntry foundData = new DatabaseEntry();

            if (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
                fail("index database is not empty");
            }
        } catch (DatabaseException e) {
            throw e;
        } finally {
            if (cursor != null)
                cursor.close();
        }

        cursor = null;
        try {
            cursor = blocks.openCursor(null, null);

            DatabaseEntry foundKey = new DatabaseEntry();
            DatabaseEntry foundData = new DatabaseEntry();

            if (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
                fail("blocks database is not empty");
            }
        } catch (DatabaseException e) {
            throw e;
        } finally {
            if (cursor != null)
                cursor.close();
        }
    }
View Full Code Here

    int getSourceVersion(Database versionDb)
    {
        int version = -1;

        Cursor cursor = null;
        try
        {
            cursor = versionDb.openCursor(null, null);

            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();

            while(cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
            {
                int ver = IntegerBinding.entryToInt(key);
                if(ver > version)
                {
                    version = ver;
                }
            }
        }
        finally
        {
            if(cursor != null)
            {
                cursor.close();
            }
        }


        return version;
View Full Code Here

     */
    private SortedMap<Integer, byte[]> getMessageData(final long messageId, final Database oldDatabase)
    {
        TreeMap<Integer, byte[]> data = new TreeMap<Integer, byte[]>();

        Cursor cursor = oldDatabase.openCursor(null, CursorConfig.READ_COMMITTED);
        try
        {
            DatabaseEntry contentKeyEntry = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            CompoundKeyBinding binding = new CompoundKeyBinding();
            binding.objectToEntry(new CompoundKey(messageId, 0), contentKeyEntry);

            OperationStatus status = cursor.getSearchKeyRange(contentKeyEntry, value, LockMode.DEFAULT);
            OldDataBinding dataBinding = new OldDataBinding();

            while (status == OperationStatus.SUCCESS)
            {
                CompoundKey compoundKey = binding.entryToObject(contentKeyEntry);
                long id = compoundKey.getMessageId();

                if (id != messageId)
                {
                    // we have exhausted all chunks for this message id, break
                    break;
                }

                int offsetInMessage = compoundKey.getOffset();
                OldDataValue dataValue = dataBinding.entryToObject(value);
                data.put(offsetInMessage, dataValue.getData());

                status = cursor.getNext(contentKeyEntry, value, LockMode.DEFAULT);
            }
        }
        finally
        {
            cursor.close();
        }

        return data;
    }
View Full Code Here

        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        int storeVersion = -1;
        Database versionDb = null;
        Cursor cursor = null;
        try
        {
            versionDb = _environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
            cursor = versionDb.openCursor(null, null);
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS)
            {
                int version = IntegerBinding.entryToInt(key);
                if (storeVersion < version)
                {
                    storeVersion = version;
                }
            }
        }
        finally
        {
            if (cursor != null)
            {
                cursor.close();
            }
            if (versionDb != null)
            {
                versionDb.close();
            }
View Full Code Here

    }

    @Override
    public ClosableIterator<ByteArray> keys(int partition) {
        try {
            Cursor cursor = getBdbDatabase().openCursor(null, null);
            // evict data brought in by the cursor walk right away
            if(this.minimizeScanImpact)
                cursor.setCacheMode(CacheMode.EVICT_BIN);
            return new BdbPartitionKeysIterator(cursor, partition, this);
        } catch(DatabaseException e) {
            this.bdbEnvironmentStats.reportException(e);
            logger.error(e);
            throw new PersistenceFailureException(e);
View Full Code Here

    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);
    cursor.close();
    if (status != OperationStatus.SUCCESS)
      return null;
    else
      return StringBinding.entryToString(dataEntry);
 
View Full Code Here

    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);
    if(status == OperationStatus.SUCCESS && !includeLeft){
      //omit the first element
      status = cursor.getNextNoDup(keyEntry, dataEntry, LockMode.DEFAULT);
    }
    while (status == OperationStatus.SUCCESS) {
      // check if this is right of righBoundary
      final Object currentKey = entryToObject(keyEntry);
      if (!isLessEqual(currentKey, rightBoundary, includeRight))
        break;

      // find all the data values (tuples) for the given key
      final String values = StringBinding.entryToString(dataEntry);
      final List<String> tuples = Arrays.asList(values
          .split(SystemParameters.BDB_TUPLE_DELIMITER));
      result.addAll(tuples);

      status = cursor.getNext(keyEntry, dataEntry, LockMode.DEFAULT);
    }
    cursor.close();
    return result;
  }
View Full Code Here

    put((KeyType) key6, value6);
    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();

    // test getEquals
    final List<String> equalsA = getEqual((KeyType) key1);
    for (final String tuple : equalsA)
      System.out.println("Equals1: For key = " + key1 + " , value = " + tuple);
View Full Code Here

    put((KeyType) key6, value6);
    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();

    // test getEquals
    final List<String> equalsA = getEqual((KeyType) key1);
    for (final String tuple : equalsA)
      System.out.println("Equals1: For key = " + key1 + " , value = " + tuple);
View Full Code Here

TOP

Related Classes of com.sleepycat.je.Cursor$KeyChangeStatus

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.