Search in sources :

Example 16 with PropertyCursor

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

the class RelationshipTransactionStateTestBase method propertyTypeShouldBeTxStateAware.

@Test
void propertyTypeShouldBeTxStateAware() throws Exception {
    // Given
    long relationship;
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction()) {
        try (RelationshipScanCursor relationships = tx.cursors().allocateRelationshipScanCursor(NULL);
            PropertyCursor properties = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
            tx.dataRead().singleRelationship(relationship, relationships);
            assertTrue(relationships.next());
            assertFalse(hasProperties(relationships, tx));
            int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
            tx.dataWrite().relationshipSetProperty(relationship, prop, stringValue("foo"));
            relationships.properties(properties);
            assertTrue(properties.next());
            assertThat(properties.propertyType()).isEqualTo(ValueGroup.TEXT);
        }
    }
}
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 17 with PropertyCursor

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

the class RelationshipEntity method hasProperty.

@Override
public boolean hasProperty(String key) {
    if (null == key) {
        return false;
    }
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int propertyKey = transaction.tokenRead().propertyKey(key);
    if (propertyKey == TokenRead.NO_TOKEN) {
        return false;
    }
    RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
    PropertyCursor properties = transaction.ambientPropertyCursor();
    singleRelationship(transaction, relationships);
    relationships.properties(properties);
    return properties.seekProperty(propertyKey);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Example 18 with PropertyCursor

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

the class RelationshipEntity method getPropertyKeys.

@Override
public Iterable<String> getPropertyKeys() {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    List<String> keys = new ArrayList<>();
    try {
        RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
        PropertyCursor properties = transaction.ambientPropertyCursor();
        singleRelationship(transaction, relationships);
        TokenRead token = transaction.tokenRead();
        relationships.properties(properties);
        while (properties.next()) {
            keys.add(token.propertyKeyName(properties.propertyKey()));
        }
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
    }
    return keys;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) ArrayList(java.util.ArrayList) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 19 with PropertyCursor

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

the class RelationshipEntity method getAllProperties.

@Override
public Map<String, Object> getAllProperties() {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    PropertyCursor propertyCursor = transaction.ambientPropertyCursor();
    return getAllProperties(propertyCursor);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Example 20 with PropertyCursor

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

the class RelationshipEntity method getProperty.

@Override
public Object getProperty(String key) {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int propertyKey = transaction.tokenRead().propertyKey(key);
    if (propertyKey == TokenRead.NO_TOKEN) {
        throw new NotFoundException(format("No such property, '%s'.", key));
    }
    RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
    PropertyCursor properties = transaction.ambientPropertyCursor();
    singleRelationship(transaction, relationships);
    relationships.properties(properties);
    if (!properties.seekProperty(propertyKey)) {
        throw new NotFoundException(format("No such property, '%s'.", key));
    }
    return properties.propertyValue().asObjectCopy();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) 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