Search in sources :

Example 36 with NodeCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseRelationshipTraversalCursor.

@Test
void shouldReuseRelationshipTraversalCursor() {
    NodeCursor node = cursors.allocateNodeCursor(NULL);
    RelationshipTraversalCursor c1 = cursors.allocateRelationshipTraversalCursor(NULL);
    read.singleNode(startNode, node);
    node.next();
    node.relationships(c1, ALL_RELATIONSHIPS);
    node.close();
    c1.close();
    RelationshipTraversalCursor c2 = cursors.allocateRelationshipTraversalCursor(NULL);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 37 with NodeCursor

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

the class CompositeUniquenessConstraintValidationIT method clean.

@AfterEach
public void clean() throws Exception {
    if (transaction != null) {
        transaction.close();
        transaction = null;
    }
    newTransaction();
    transaction.schemaWrite().constraintDrop(constraintDescriptor);
    commit();
    try (KernelTransaction tx = kernel.beginTransaction(KernelTransaction.Type.IMPLICIT, LoginContext.AUTH_DISABLED)) {
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
            tx.dataRead().allNodesScan(node);
            while (node.next()) {
                tx.dataWrite().nodeDelete(node.nodeReference());
            }
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) AfterEach(org.junit.jupiter.api.AfterEach)

Example 38 with NodeCursor

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

the class KernelIT method txReturnsCorrectIdWhenReadOnly.

@Test
void txReturnsCorrectIdWhenReadOnly() throws Exception {
    executeDummyTxs(db, 42);
    KernelTransaction tx = newTransaction();
    try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext())) {
        tx.dataRead().singleNode(1, node);
        node.next();
    }
    assertEquals(KernelTransaction.READ_ONLY_ID, tx.commit());
    assertFalse(tx.isOpen());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 39 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeRelationshipInTransaction.

@Test
void shouldSeeRelationshipInTransaction() throws Exception {
    long n1, n2;
    try (KernelTransaction tx = beginTransaction()) {
        n1 = tx.dataWrite().nodeCreate();
        n2 = tx.dataWrite().nodeCreate();
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        long r = tx.dataWrite().relationshipCreate(n1, label, n2);
        try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
            RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
            tx.dataRead().singleNode(n1, node);
            assertTrue(node.next(), "should access node");
            node.relationships(relationship, ALL_RELATIONSHIPS);
            assertTrue(relationship.next(), "should find relationship");
            assertEquals(r, relationship.relationshipReference());
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 40 with NodeCursor

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

the class RelationshipTransactionStateTestBase method shouldNewRelationshipBetweenAlreadyConnectedSparseNodes.

@Test
void shouldNewRelationshipBetweenAlreadyConnectedSparseNodes() throws Exception {
    long start;
    long end;
    long existingRelationship;
    int type;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        start = write.nodeCreate();
        end = write.nodeCreate();
        type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        existingRelationship = write.relationshipCreate(start, type, end);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        long newRelationship = write.relationshipCreate(start, type, write.nodeCreate());
        try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
            RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(NULL)) {
            org.neo4j.internal.kernel.api.Read read = tx.dataRead();
            read.singleNode(start, node);
            assertTrue(node.next());
            assertFalse(node.supportsFastDegreeLookup());
            Degrees degrees = node.degrees(selection(type, BOTH));
            assertEquals(2, degrees.outgoingDegree());
            assertEquals(0, degrees.incomingDegree());
            assertRelationships(OUTGOING, node, type, traversal, newRelationship, existingRelationship);
        }
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Read(org.neo4j.internal.kernel.api.Read) Degrees(org.neo4j.storageengine.api.Degrees) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Aggregations

NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)113 Test (org.junit.jupiter.api.Test)85 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)62 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)30 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)26 Read (org.neo4j.internal.kernel.api.Read)20 Write (org.neo4j.internal.kernel.api.Write)17 Degrees (org.neo4j.storageengine.api.Degrees)11 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)10 ArrayList (java.util.ArrayList)8 ExecutorService (java.util.concurrent.ExecutorService)7 LongList (org.eclipse.collections.api.list.primitive.LongList)7 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)7 CachingExpandInto (org.neo4j.internal.kernel.api.helpers.CachingExpandInto)6 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)5 RelationshipSelection (org.neo4j.storageengine.api.RelationshipSelection)5 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)4 Future (java.util.concurrent.Future)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 NotFoundException (org.neo4j.graphdb.NotFoundException)3