Search in sources :

Example 26 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class PropertyValueIterable method getIteratorImpl.

@Override
@NotNull
public EntityIteratorBase getIteratorImpl(@NotNull final PersistentStoreTransaction txn) {
    final EntityIterableBase it = getPropertyValueIndex();
    if (it.isCachedInstance()) {
        final UpdatablePropertiesCachedInstanceIterable cached = (UpdatablePropertiesCachedInstanceIterable) it;
        if (value.getClass() != cached.getPropertyValueClass()) {
            return EntityIteratorBase.EMPTY;
        }
        return cached.getPropertyValueIterator(value);
    }
    final Cursor valueIdx = openCursor(txn);
    if (valueIdx == null) {
        return EntityIteratorBase.EMPTY;
    }
    return new PropertyValueIterator(valueIdx);
}
Also used : Cursor(jetbrains.exodus.env.Cursor) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class PropertyValueIterable method isEmptyImpl.

@Override
public boolean isEmptyImpl(@NotNull PersistentStoreTransaction txn) {
    final ByteIterable key = getStore().getPropertyTypes().dataToPropertyValue(value).dataToEntry();
    final Cursor valueIdx = openCursor(txn);
    return valueIdx == null || new SingleKeyCursorIsEmptyChecker(valueIdx, key).isEmpty();
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) Cursor(jetbrains.exodus.env.Cursor)

Example 28 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class CursorTestBase method check.

protected void check(ITree tm, GetNext r) {
    Cursor c = tm.openCursor();
    assertEquals(false, c.getKey().iterator().hasNext());
    assertEquals(false, c.getValue().iterator().hasNext());
    for (int i = 0; i < s; i++) {
        assertEquals(true, r.n(c));
        assertEquals(c.getValue(), value("v" + i));
        assertEquals(c.getKey(), key(i));
    }
    assertEquals(false, r.n(c));
}
Also used : Cursor(jetbrains.exodus.env.Cursor)

Example 29 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class TreeCursorConcurrentModificationTest method testConcurrentDeleteBefore.

@Test
public void testConcurrentDeleteBefore() {
    Cursor c = tm.openCursor();
    c.getSearchKey(key(2));
    deleteImpl(key(1));
    assertTrue(c.getNext());
    assertEquals(key(3), c.getKey());
}
Also used : Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test)

Example 30 with Cursor

use of jetbrains.exodus.env.Cursor in project xodus by JetBrains.

the class TreeCursorDuplicatesTest method testGetSearchKey.

@Test
public void testGetSearchKey() throws IOException {
    final TreeAwareRunnable getSearchKey = new TreeAwareRunnable(getTreeMutable()) {

        @Override
        public void run() {
            Cursor c = _t.openCursor();
            for (INode ln : valuesNoDup) {
                assertEquals(ln.getValue(), c.getSearchKey(ln.getKey()));
                assertEquals(ln.getValue(), c.getValue());
                assertEquals(ln.getKey(), c.getKey());
            }
            assertEquals(null, c.getSearchKey(key(0)));
            assertEquals(null, c.getSearchKey(key(4)));
            assertEquals(null, c.getSearchKey(key(13)));
            // prev state due to failed search
            assertEquals(values.get(values.size() - 1).getValue(), c.getValue());
            assertEquals(values.get(values.size() - 1).getKey(), c.getKey());
        }
    };
    getSearchKey.run();
    long a = saveTree();
    getSearchKey.run();
    reopen();
    getSearchKey.setTree(openTree(a, true));
    getSearchKey.run();
}
Also used : Cursor(jetbrains.exodus.env.Cursor) Test(org.junit.Test)

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