Search in sources :

Example 21 with PropertyCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction.

@Test
void shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction() throws Exception {
    // Given
    long relationshipId;
    String propKey = "prop1";
    int propToken;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
        propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(write.relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("world")), stringValue("hello"));
        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("world"));
            assertFalse(property.next(), "should only find one property");
            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("world");
    }
}
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)

Example 22 with PropertyCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction.

@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction() throws Exception {
    // Given
    long relationshipId;
    String propKey1 = "prop1";
    String propKey2 = "prop2";
    int propToken1;
    int propToken2;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
        propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        assertEquals(write.relationshipSetProperty(relationshipId, propToken1, stringValue("hello")), NO_VALUE);
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken2, stringValue("world")), 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);
            while (property.next()) {
                if (// from disk
                property.propertyKey() == propToken1) {
                    assertEquals(property.propertyValue(), stringValue("hello"));
                } else if (// from tx state
                property.propertyKey() == propToken2) {
                    assertEquals(property.propertyValue(), stringValue("world"));
                } else {
                    fail(property.propertyKey() + " was not the property you were looking for");
                }
            }
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
        Relationship relationship = transaction.getRelationshipById(relationshipId);
        assertThat(relationship.getProperty(propKey1)).isEqualTo("hello");
        assertThat(relationship.getProperty(propKey2)).isEqualTo("world");
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Relationship(org.neo4j.graphdb.Relationship) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 23 with PropertyCursor

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

the class RelationshipTransactionStateTestBase method shouldSeeNewRelationshipPropertyInTransaction.

@Test
void shouldSeeNewRelationshipPropertyInTransaction() throws Exception {
    try (KernelTransaction tx = beginTransaction()) {
        String propKey1 = "prop1";
        String propKey2 = "prop2";
        long n1 = tx.dataWrite().nodeCreate();
        long n2 = tx.dataWrite().nodeCreate();
        int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        long r = tx.dataWrite().relationshipCreate(n1, label, n2);
        int prop1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        int prop2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(tx.dataWrite().relationshipSetProperty(r, prop1, stringValue("hello")), NO_VALUE);
        assertEquals(tx.dataWrite().relationshipSetProperty(r, prop2, stringValue("world")), NO_VALUE);
        try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
            RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL);
            PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
            tx.dataRead().singleNode(n1, node);
            assertTrue(node.next(), "should access node");
            node.relationships(relationship, ALL_RELATIONSHIPS);
            assertTrue(relationship.next(), "should access relationship");
            relationship.properties(property);
            while (property.next()) {
                if (property.propertyKey() == prop1) {
                    assertEquals(property.propertyValue(), stringValue("hello"));
                } else if (property.propertyKey() == prop2) {
                    assertEquals(property.propertyValue(), stringValue("world"));
                } else {
                    fail(property.propertyKey() + " was not the property key you were looking for");
                }
            }
            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) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 24 with PropertyCursor

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

the class RelationshipTransactionStateTestBase method shouldNotSeeRemovedPropertyInTransaction.

@Test
void shouldNotSeeRemovedPropertyInTransaction() throws Exception {
    // Given
    long relationshipId;
    String propKey = "prop1";
    int propToken;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
        propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
        assertEquals(write.relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
        tx.commit();
    }
    // When/Then
    try (KernelTransaction tx = beginTransaction()) {
        assertEquals(tx.dataWrite().relationshipRemoveProperty(relationshipId, propToken), stringValue("hello"));
        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);
            assertFalse(property.next(), "should not find any properties");
            assertFalse(relationship.next(), "should only find one relationship");
        }
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
        assertFalse(transaction.getRelationshipById(relationshipId).hasProperty(propKey));
    }
}
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)

Example 25 with PropertyCursor

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

the class PropertyCursorTestBase method assertAccessSingleRelationshipProperty.

private void assertAccessSingleRelationshipProperty(long relationshipId, Object expectedValue, ValueGroup expectedValueType) {
    // given
    try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
        PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
        // when
        read.singleRelationship(relationshipId, relationship);
        assertTrue(relationship.next(), "relationship by reference");
        assertTrue(hasProperties(relationship, props), "has properties");
        relationship.properties(props);
        assertTrue(props.next(), "has properties by direct method");
        assertEquals(expectedValue, props.propertyValue(), "correct value");
        assertEquals(expectedValueType, props.propertyType(), "correct value type ");
        assertFalse(props.next(), "single property");
        read.relationshipProperties(relationship.relationshipReference(), relationship.propertiesReference(), props);
        assertTrue(props.next(), "has properties via property ref");
        assertEquals(expectedValue, props.propertyValue(), "correct value");
        assertFalse(props.next(), "single property");
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

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