Search in sources :

Example 11 with PropertyCursor

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

the class NodeTransactionStateTestBase method shouldSeeAddedPropertyFromExistingNodeWithoutPropertiesInTransaction.

@Test
void shouldSeeAddedPropertyFromExistingNodeWithoutPropertiesInTransaction() throws Exception {
    // Given
    long nodeId;
    String propKey = "prop1";
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        int propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(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);
            assertTrue(property.next());
            assertEquals(propToken, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("hello"));
            assertFalse(property.next(), "should only find one properties");
            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("hello");
    }
}
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 12 with PropertyCursor

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

the class NodeTransactionStateTestBase method shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction.

@Test
void shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception {
    // Given
    long nodeId;
    String propKey1 = "prop1";
    String propKey2 = "prop2";
    int propToken1;
    int propToken2;
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken1, stringValue("hello")));
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken2, stringValue("world")));
        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);
            // property 2, start with tx state
            assertTrue(property.next());
            assertEquals(propToken2, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("world"));
            // property 1, from disk
            assertTrue(property.next());
            assertEquals(propToken1, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("hello"));
            assertFalse(property.next(), "should only find two properties");
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
        assertThat(tx.getNodeById(nodeId).getProperty(propKey1)).isEqualTo("hello");
        assertThat(tx.getNodeById(nodeId).getProperty(propKey2)).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 13 with PropertyCursor

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

the class NodeTransactionStateTestBase method propertyTypeShouldBeTxStateAware.

@Test
void propertyTypeShouldBeTxStateAware() throws Exception {
    // Given
    long node;
    try (KernelTransaction tx = beginTransaction()) {
        node = tx.dataWrite().nodeCreate();
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction()) {
        try (NodeCursor nodes = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor properties = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(node, nodes);
            assertTrue(nodes.next());
            assertFalse(hasProperties(nodes, properties));
            int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
            tx.dataWrite().nodeSetProperty(node, prop, stringValue("foo"));
            nodes.properties(properties);
            assertTrue(properties.next());
            assertThat(properties.propertyType()).isEqualTo(ValueGroup.TEXT);
        }
    }
}
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 14 with PropertyCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseFullAccessPropertyCursor.

@Test
void shouldReuseFullAccessPropertyCursor() {
    NodeCursor node = cursors.allocateNodeCursor(NULL);
    PropertyCursor c1 = cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE);
    read.singleNode(propNode, node);
    node.next();
    node.properties(c1);
    node.close();
    c1.close();
    PropertyCursor c2 = cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 15 with PropertyCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction.

@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction() throws Exception {
    // Given
    long relationshipId;
    String propKey = "prop1";
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        int propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
        try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL);
            PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
            tx.dataRead().singleRelationship(relationshipId, relationship);
            assertTrue(relationship.next(), "should access relationship");
            relationship.properties(property);
            assertTrue(property.next());
            assertEquals(propToken, property.propertyKey());
            assertEquals(property.propertyValue(), stringValue("hello"));
            assertFalse(property.next(), "should only find one properties");
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
        assertThat(transaction.getRelationshipById(relationshipId).getProperty(propKey)).isEqualTo("hello");
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) 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