Search in sources :

Example 21 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.

the class UniqueIndexSeekIT method lockNodeUsingUniqueIndexSeek.

private static void lockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, String nameProperty) throws KernelException {
    try (Transaction transaction = database.beginTx()) {
        KernelTransaction kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
        TokenRead tokenRead = kernelTransaction.tokenRead();
        Read dataRead = kernelTransaction.dataRead();
        int propertyId = tokenRead.propertyKey(nameProperty);
        IndexDescriptor indexReference = kernelTransaction.schemaRead().indexGetForName(CONSTRAINT_NAME);
        try (NodeValueIndexCursor cursor = kernelTransaction.cursors().allocateNodeValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
            dataRead.lockingNodeUniqueIndexSeek(indexReference, cursor, PropertyIndexQuery.ExactPredicate.exact(propertyId, "value"));
        }
        transaction.commit();
    }
}
Also used : TokenRead(org.neo4j.internal.kernel.api.TokenRead) Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 22 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.

the class LuceneFulltextTestSupport method assertQueryFindsNodeIdsInOrder.

void assertQueryFindsNodeIdsInOrder(KernelTransaction ktx, String indexName, String query, long... ids) throws Exception {
    IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
    IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
    try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
        int num = 0;
        float score = Float.MAX_VALUE;
        ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
        while (cursor.next()) {
            long nextId = cursor.nodeReference();
            float nextScore = cursor.score();
            assertThat(nextScore).isLessThanOrEqualTo(score);
            score = nextScore;
            assertEquals(ids[num], nextId, format("Result returned node id %d, expected %d", nextId, ids[num]));
            num++;
        }
        assertEquals(ids.length, num, "Number of results differ from expected");
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 23 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.

the class MultipleOpenCursorsTest method multipleIteratorsNestedInnerNewExists.

@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInnerNewExists(IndexCoordinator indexCoordinator) throws Exception {
    indexCoordinator.init(db);
    try (Transaction tx = db.beginTx()) {
        // when
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExists(ktx)) {
            List<Long> actual1 = new ArrayList<>();
            while (cursor1.next()) {
                actual1.add(cursor1.nodeReference());
                try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExists(ktx)) {
                    List<Long> actual2 = asList(cursor2);
                    indexCoordinator.assertExistsResult(actual2);
                }
            }
            // then
            indexCoordinator.assertExistsResult(actual1);
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 24 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.

the class MultipleOpenCursorsTest method multipleIteratorsNotNestedRange.

@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNotNestedRange(IndexCoordinator indexCoordinator) throws KernelException {
    assumeTrue(indexCoordinator.supportRangeQuery());
    indexCoordinator.init(db);
    try (Transaction tx = db.beginTx()) {
        // when
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeValueIndexCursor cursor1 = indexCoordinator.queryRange(ktx);
            NodeValueIndexCursor cursor2 = indexCoordinator.queryRange(ktx)) {
            List<Long> actual1 = asList(cursor1);
            List<Long> actual2 = asList(cursor2);
            // then
            indexCoordinator.assertRangeResult(actual1);
            indexCoordinator.assertRangeResult(actual2);
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 25 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.

the class MultipleOpenCursorsTest method multipleIteratorsNestedInterleavedExists.

@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInterleavedExists(IndexCoordinator indexCoordinator) throws Exception {
    indexCoordinator.init(db);
    try (Transaction tx = db.beginTx()) {
        // when
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExists(ktx)) {
            List<Long> actual1 = new ArrayList<>();
            try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExists(ktx)) {
                List<Long> actual2 = new ArrayList<>();
                // Interleave
                exhaustInterleaved(cursor1, actual1, cursor2, actual2);
                // then
                indexCoordinator.assertExistsResult(actual1);
                indexCoordinator.assertExistsResult(actual2);
            }
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)42 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)20 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)20 Test (org.junit.jupiter.api.Test)18 Transaction (org.neo4j.graphdb.Transaction)16 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)16 ArrayList (java.util.ArrayList)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 TokenRead (org.neo4j.internal.kernel.api.TokenRead)7 Read (org.neo4j.internal.kernel.api.Read)6 Value (org.neo4j.values.storable.Value)6 KernelException (org.neo4j.exceptions.KernelException)3 Node (org.neo4j.graphdb.Node)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 Label (org.neo4j.graphdb.Label)2 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)2 NodeIndexCursor (org.neo4j.internal.kernel.api.NodeIndexCursor)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2