Search in sources :

Example 51 with RelationshipScanCursor

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

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

Example 53 with RelationshipScanCursor

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

the class RelationshipEntity method initializeData.

public boolean initializeData() {
    if (startNode == NO_ID) {
        KernelTransaction transaction = internalTransaction.kernelTransaction();
        RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
        return initializeData(relationships);
    }
    return true;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor)

Aggregations

RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)53 Test (org.junit.jupiter.api.Test)40 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)28 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)16 Write (org.neo4j.internal.kernel.api.Write)16 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)8 ExecutorService (java.util.concurrent.ExecutorService)7 LongList (org.eclipse.collections.api.list.primitive.LongList)7 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 Read (org.neo4j.internal.kernel.api.Read)4 Future (java.util.concurrent.Future)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 KernelException (org.neo4j.exceptions.KernelException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1