Search in sources :

Example 6 with PropertyCursor

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

the class NodeTransactionStateTestBase method hasPropertiesShouldSeeNewlyRemovedProperties.

@Test
void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception {
    // Given
    long node;
    int prop1, prop2, prop3;
    try (KernelTransaction tx = beginTransaction()) {
        node = tx.dataWrite().nodeCreate();
        prop1 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop1");
        prop2 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop2");
        prop3 = tx.tokenWrite().propertyKeyGetOrCreateForName("prop3");
        tx.dataWrite().nodeSetProperty(node, prop1, longValue(1));
        tx.dataWrite().nodeSetProperty(node, prop2, longValue(2));
        tx.dataWrite().nodeSetProperty(node, prop3, longValue(3));
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction()) {
        try (NodeCursor cursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor props = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(node, cursor);
            assertTrue(cursor.next());
            assertTrue(hasProperties(cursor, props));
            tx.dataWrite().nodeRemoveProperty(node, prop1);
            assertTrue(hasProperties(cursor, props));
            tx.dataWrite().nodeRemoveProperty(node, prop2);
            assertTrue(hasProperties(cursor, props));
            tx.dataWrite().nodeRemoveProperty(node, prop3);
            assertFalse(hasProperties(cursor, props));
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 7 with PropertyCursor

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

the class KernelReadTracerTest method shouldTracePropertyAccess.

@Test
void shouldTracePropertyAccess() {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (NodeCursor nodeCursor = cursors.allocateNodeCursor(NULL);
        PropertyCursor propertyCursor = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        propertyCursor.setTracer(tracer);
        read.singleNode(foo, nodeCursor);
        assertTrue(nodeCursor.next());
        nodeCursor.properties(propertyCursor);
        assertTrue(propertyCursor.next());
        tracer.assertEvents(OnProperty(propertyCursor.propertyKey()));
        assertTrue(propertyCursor.next());
        tracer.assertEvents(OnProperty(propertyCursor.propertyKey()));
        propertyCursor.removeTracer();
        assertTrue(propertyCursor.next());
        tracer.assertEvents();
        propertyCursor.setTracer(tracer);
        assertTrue(propertyCursor.next());
        tracer.assertEvents(OnProperty(propertyCursor.propertyKey()));
        assertFalse(propertyCursor.next());
        tracer.assertEvents();
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 8 with PropertyCursor

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

the class NodeTransactionStateTestBase method shouldSeeUpdatedPropertyFromExistingNodeWithPropertiesInTransaction.

@Test
void shouldSeeUpdatedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception {
    // Given
    long nodeId;
    String propKey = "prop1";
    int propToken;
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken, stringValue("hello")));
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        assertEquals(tx.dataWrite().nodeSetProperty(nodeId, propToken, stringValue("world")), stringValue("hello"));
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor property = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(nodeId, node);
            assertTrue(node.next(), "should access node");
            node.properties(property);
            assertTrue(property.next());
            assertEquals(propToken, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("world"));
            assertFalse(property.next(), "should only find one property");
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getProperty(propKey)).isEqualTo("world");
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 9 with PropertyCursor

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

the class NodeTransactionStateTestBase method shouldSeeRemovedPropertyInTransaction.

@Test
void shouldSeeRemovedPropertyInTransaction() throws Exception {
    // Given
    long nodeId;
    String propKey = "prop1";
    int propToken;
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken, stringValue("hello")));
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        assertEquals(tx.dataWrite().nodeRemoveProperty(nodeId, propToken), stringValue("hello"));
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor property = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(nodeId, node);
            assertTrue(node.next(), "should access node");
            node.properties(property);
            assertFalse(property.next(), "should not find any properties");
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertFalse(tx.getNodeById(nodeId).hasProperty(propKey));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 10 with PropertyCursor

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

the class NodeTransactionStateTestBase method hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedNode.

@Test
void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedNode() throws Exception {
    try (KernelTransaction tx = beginTransaction()) {
        long node = tx.dataWrite().nodeCreate();
        try (NodeCursor cursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor props = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(node, cursor);
            assertTrue(cursor.next());
            assertFalse(hasProperties(cursor, props));
            tx.dataWrite().nodeSetProperty(node, tx.tokenWrite().propertyKeyGetOrCreateForName("prop"), stringValue("foo"));
            assertTrue(hasProperties(cursor, props));
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)48 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)33 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)30 Test (org.junit.jupiter.api.Test)29 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)16 Write (org.neo4j.internal.kernel.api.Write)7 TokenRead (org.neo4j.internal.kernel.api.TokenRead)4 Value (org.neo4j.values.storable.Value)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)2 IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)2 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1