Search in sources :

Example 1 with SecondaryDatabase

use of com.sleepycat.je.SecondaryDatabase 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)1 OperationStatus (com.sleepycat.je.OperationStatus)1 SecondaryCursor (com.sleepycat.je.SecondaryCursor)1 SecondaryDatabase (com.sleepycat.je.SecondaryDatabase)1