use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.
the class PropertyRangeIterable method countImpl.
@Override
protected long countImpl(@NotNull final PersistentStoreTransaction txn) {
final Cursor cursor = openCursor(txn);
if (cursor == null) {
return 0;
}
try {
final PropertyValue propertyValue = getStore().getPropertyTypes().dataToPropertyValue(min);
final ComparableBinding binding = propertyValue.getBinding();
long result = 0;
boolean success = cursor.getSearchKeyRange(propertyValue.dataToEntry()) != null;
while (success && max.compareTo(binding.entryToObject(cursor.getKey())) >= 0) {
result += cursor.count();
success = cursor.getNextNoDup();
}
return result;
} finally {
cursor.close();
}
}
use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.
the class PropertyValueIterable method countImpl.
@Override
protected long countImpl(@NotNull final PersistentStoreTransaction txn) {
final ByteIterable key = getStore().getPropertyTypes().dataToPropertyValue(value).dataToEntry();
final Cursor valueIdx = openCursor(txn);
return valueIdx == null ? 0 : new SingleKeyCursorCounter(valueIdx, key).getCount();
}
use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.
the class EntityIteratorBase method dispose.
@Override
public boolean dispose() {
queryCancellingPolicy = null;
if (!disposed) {
disposed = true;
final PersistentStoreTransaction txn = iterable.getStore().getCurrentTransaction();
// txn is null if dispose is called from PersistentStoreTransaction.close()
if (txn != null) {
txn.deregisterEntityIterator(this);
}
final Cursor cursor = this.cursor;
if (cursor != null) {
cursor.close();
this.cursor = null;
}
return true;
}
return false;
}
use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.
the class BTreeSpecificCursorNoDuplicatesTest method testGetSearchKeyRange3.
@Test
public void testGetSearchKeyRange3() throws IOException {
tm = createEmptyTreeForCursor(1).getMutableCopy();
getTreeMutable().put(kv(1, "v1"));
getTreeMutable().put(kv(2, "v2"));
getTreeMutable().put(kv(3, "v3"));
getTreeMutable().put(kv(5, "v5"));
getTreeMutable().put(kv(6, "v6"));
getTreeMutable().put(kv(7, "v7"));
assertMatches(getTreeMutable(), IP(BP(3), BP(3)));
final TreeAwareRunnable getSearchKeyRange = new TreeAwareRunnable(getTreeMutable()) {
@Override
public void run() {
Cursor c = _t.openCursor();
assertEquals(value("v5"), c.getSearchKeyRange(key(4)));
assertEquals(key(5), c.getKey());
}
};
getSearchKeyRange.run();
long a = saveTree();
getSearchKeyRange.run();
reopen();
getSearchKeyRange.setTree(openTree(a, true));
getSearchKeyRange.run();
}
use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.
the class PropertyRangeIterable method getIteratorImpl.
@Override
@NotNull
public EntityIteratorBase getIteratorImpl(@NotNull final PersistentStoreTransaction txn) {
final EntityIterableBase it = getPropertyValueIndex();
if (it.isCachedInstance()) {
final Class<? extends Comparable> minClass = min.getClass();
final Class<? extends Comparable> maxClass = max.getClass();
final UpdatablePropertiesCachedInstanceIterable cached = (UpdatablePropertiesCachedInstanceIterable) it;
if (minClass != maxClass || minClass != cached.getPropertyValueClass()) {
return EntityIteratorBase.EMPTY;
}
return cached.getPropertyRangeIterator(min, max);
}
final Cursor valueIdx = openCursor(txn);
if (valueIdx == null) {
return EntityIteratorBase.EMPTY;
}
return new PropertyRangeIterator(valueIdx);
}
Aggregations