Search in sources :

Example 1 with SecondaryCursor

use of com.sleepycat.je.SecondaryCursor in project parliament by SemWebCentral.

the class PersistentTemporalIndex method readMinAndMaxes.

private void readMinAndMaxes() throws DatabaseException {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    try (SecondaryCursor cursor = startsDatabase.openCursor(null, CursorConfig.READ_UNCOMMITTED)) {
        OperationStatus status = cursor.getFirst(key, value, LockMode.READ_UNCOMMITTED);
        if (status == OperationStatus.SUCCESS) {
            // If we get one thing back, there is at least one element in the db
            minStart = getLongForBytes(value.getData(), 0);
            cursor.getLast(key, value, LockMode.READ_UNCOMMITTED);
            maxStart = getLongForBytes(value.getData(), 0);
        } else {
            minStart = 0L;
            maxStart = Long.MAX_VALUE;
        }
    }
    try (SecondaryCursor cursor = endsDatabase.openCursor(null, CursorConfig.READ_UNCOMMITTED)) {
        OperationStatus status = cursor.getFirst(key, value, LockMode.READ_UNCOMMITTED);
        if (status == OperationStatus.SUCCESS) {
            // If we get one thing back, there is at least one element in the db
            minEnd = getLongForBytes(value.getData(), 8);
            cursor.getLast(key, value, LockMode.READ_UNCOMMITTED);
            maxEnd = getLongForBytes(value.getData(), 8);
        } else {
            minEnd = 0L;
            maxEnd = Long.MAX_VALUE;
        }
    }
    size = nodeIndexedDatabase.count();
}
Also used : SecondaryCursor(com.sleepycat.je.SecondaryCursor) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 2 with SecondaryCursor

use of com.sleepycat.je.SecondaryCursor in project parliament by SemWebCentral.

the class NumericIndex method readMinAndMax.

/**
 * Read the minimum and maximum values.
 *
 * @throws DatabaseException
 */
private void readMinAndMax() throws DatabaseException {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    try (SecondaryCursor cursor = numbersDb.openCursor(null, CursorConfig.READ_UNCOMMITTED)) {
        // Cursor cursor = startsDatabase.openCursor(null,
        // CursorConfig.READ_UNCOMMITTED);
        // OperationStatus retVal = cursor.getSearchKey(key, value,
        // LockMode.READ_UNCOMMITTED);
        OperationStatus status = cursor.getFirst(key, value, LockMode.READ_UNCOMMITTED);
        // If we get one thing back, there is at least one element in the db
        if (status == OperationStatus.SUCCESS) {
            min = getRecordFactory().getNumberForBytes(value.getData());
            cursor.getLast(key, value, LockMode.READ_UNCOMMITTED);
            max = getRecordFactory().getNumberForBytes(value.getData());
        } else {
            min = getRecordFactory().getMaximum();
            max = getRecordFactory().getMinimum();
        }
    }
}
Also used : SecondaryCursor(com.sleepycat.je.SecondaryCursor) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 3 with SecondaryCursor

use of com.sleepycat.je.SecondaryCursor in project parliament by SemWebCentral.

the class PersistentTemporalIndex method countRecords.

private long countRecords(long time, boolean starts) {
    @SuppressWarnings("resource") SecondaryDatabase sdb = (starts) ? getStartsDatabase() : getEndsDatabase();
    DatabaseEntry key = new DatabaseEntry(PersistentTemporalIndex.getBytesForLong(time));
    DatabaseEntry data = new DatabaseEntry();
    try (SecondaryCursor cursor = sdb.openCursor(null, CursorConfig.READ_UNCOMMITTED)) {
        OperationStatus status = cursor.getSearchKeyRange(key, data, LockMode.READ_UNCOMMITTED);
        if (OperationStatus.SUCCESS.equals(status)) {
            int count = 1;
            long start = System.currentTimeMillis();
            while (OperationStatus.SUCCESS.equals(cursor.getNext(key, data, LockMode.READ_UNCOMMITTED))) {
                count++;
            }
            long length = System.currentTimeMillis() - start;
            LOG.debug("Search took: " + length);
            return count;
        }
    }
    return Long.MAX_VALUE;
}
Also used : SecondaryDatabase(com.sleepycat.je.SecondaryDatabase) SecondaryCursor(com.sleepycat.je.SecondaryCursor) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 OperationStatus (com.sleepycat.je.OperationStatus)3 SecondaryCursor (com.sleepycat.je.SecondaryCursor)3 SecondaryDatabase (com.sleepycat.je.SecondaryDatabase)1