Search in sources :

Example 56 with TokenRead

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

the class NodeEntity 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;
    Map<String, Object> properties = new HashMap<>(itemsToReturn);
    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);
    }
    NodeCursor nodes = transaction.ambientNodeCursor();
    PropertyCursor propertyCursor = transaction.ambientPropertyCursor();
    singleNode(transaction, nodes);
    nodes.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) HashMap(java.util.HashMap) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 57 with TokenRead

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

the class NodeEntity method getLabels.

public Iterable<Label> getLabels(NodeCursor nodes) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    try {
        singleNode(transaction, nodes);
        TokenSet tokenSet = nodes.labels();
        TokenRead tokenRead = transaction.tokenRead();
        List<Label> list = new ArrayList<>(tokenSet.numberOfTokens());
        for (int i = 0; i < tokenSet.numberOfTokens(); i++) {
            list.add(label(tokenRead.nodeLabelName(tokenSet.token(i))));
        }
        return list;
    } catch (LabelNotFoundKernelException e) {
        throw new IllegalStateException("Label retrieved through kernel API should exist.", e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) TokenSet(org.neo4j.internal.kernel.api.TokenSet) Label(org.neo4j.graphdb.Label) ArrayList(java.util.ArrayList) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 58 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead 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 59 with TokenRead

use of org.neo4j.internal.kernel.api.TokenRead 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

TokenRead (org.neo4j.internal.kernel.api.TokenRead)59 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)42 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 Test (org.junit.jupiter.api.Test)19 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)18 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 Transaction (org.neo4j.graphdb.Transaction)13 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)13 Label (org.neo4j.graphdb.Label)12 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)11 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)11 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)10 RelationshipType (org.neo4j.graphdb.RelationshipType)7 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 Arrays (java.util.Arrays)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 Stream (java.util.stream.Stream)5