Search in sources :

Example 46 with PropertyCursor

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

the class NodeEntity method getPropertyKeys.

@Override
public Iterable<String> getPropertyKeys() {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    List<String> keys = new ArrayList<>();
    try {
        NodeCursor nodes = transaction.ambientNodeCursor();
        PropertyCursor properties = transaction.ambientPropertyCursor();
        singleNode(transaction, nodes);
        TokenRead token = transaction.tokenRead();
        nodes.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) ArrayList(java.util.ArrayList) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 47 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, Object defaultValue) {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
    PropertyCursor properties = transaction.ambientPropertyCursor();
    int propertyKey = transaction.tokenRead().propertyKey(key);
    if (propertyKey == TokenRead.NO_TOKEN) {
        return defaultValue;
    }
    singleRelationship(transaction, relationships);
    relationships.properties(properties);
    return properties.seekProperty(propertyKey) ? properties.propertyValue().asObjectCopy() : defaultValue;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Example 48 with PropertyCursor

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

the class RelationshipEntity method getProperties.

@Override
public Map<String, Object> getProperties(String... keys) {
    Objects.requireNonNull(keys, "Properties keys should be not null array.");
    if (keys.length == 0) {
        return Collections.emptyMap();
    }
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int itemsToReturn = keys.length;
    TokenRead token = transaction.tokenRead();
    // Find ids, note we are betting on that the number of keys
    // is small enough not to use a set here.
    int[] propertyIds = new int[itemsToReturn];
    for (int i = 0; i < itemsToReturn; i++) {
        String key = keys[i];
        if (key == null) {
            throw new NullPointerException(String.format("Key %d was null", i));
        }
        propertyIds[i] = token.propertyKey(key);
    }
    Map<String, Object> properties = new HashMap<>(itemsToReturn);
    RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
    PropertyCursor propertyCursor = transaction.ambientPropertyCursor();
    singleRelationship(transaction, relationships);
    relationships.properties(propertyCursor);
    int propertiesToFind = itemsToReturn;
    while (propertiesToFind > 0 && propertyCursor.next()) {
        // Do a linear check if this is a property we are interested in.
        int currentKey = propertyCursor.propertyKey();
        for (int i = 0; i < itemsToReturn; i++) {
            if (propertyIds[i] == currentKey) {
                properties.put(keys[i], propertyCursor.propertyValue().asObjectCopy());
                propertiesToFind--;
                break;
            }
        }
    }
    return properties;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) HashMap(java.util.HashMap) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

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