Search in sources :

Example 21 with Cursor

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();
    }
}
Also used : ComparableBinding(jetbrains.exodus.bindings.ComparableBinding) PropertyValue(jetbrains.exodus.entitystore.tables.PropertyValue) Cursor(jetbrains.exodus.env.Cursor)

Example 22 with Cursor

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();
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) Cursor(jetbrains.exodus.env.Cursor)

Example 23 with Cursor

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;
}
Also used : Cursor(jetbrains.exodus.env.Cursor)

Example 24 with Cursor

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();
}
Also used : Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test)

Example 25 with Cursor

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);
}
Also used : Cursor(jetbrains.exodus.env.Cursor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Cursor (jetbrains.exodus.env.Cursor)57 Test (org.junit.Test)46 ByteIterable (jetbrains.exodus.ByteIterable)7 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)6 NotNull (org.jetbrains.annotations.NotNull)4 Store (jetbrains.exodus.env.Store)3 Transaction (jetbrains.exodus.env.Transaction)3 File (java.io.File)2 TestFor (jetbrains.exodus.TestFor)2 TransactionalExecutable (jetbrains.exodus.env.TransactionalExecutable)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ComparableBinding (jetbrains.exodus.bindings.ComparableBinding)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1 BlobsTable (jetbrains.exodus.entitystore.tables.BlobsTable)1 PropertyValue (jetbrains.exodus.entitystore.tables.PropertyValue)1 TreeCursorNoDuplicatesTest (jetbrains.exodus.tree.TreeCursorNoDuplicatesTest)1