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();
}
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();
}
}
}
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;
}
Aggregations