Search in sources :

Example 26 with RelationshipScanCursor

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

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

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

the class RelationshipEntity method getAllProperties.

public Map<String, Object> getAllProperties(PropertyCursor propertyCursor) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    Map<String, Object> properties = new HashMap<>();
    try {
        RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
        TokenRead token = transaction.tokenRead();
        singleRelationship(transaction, relationships);
        relationships.properties(propertyCursor);
        while (propertyCursor.next()) {
            properties.put(token.propertyKeyName(propertyCursor.propertyKey()), propertyCursor.propertyValue().asObjectCopy());
        }
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
    }
    return properties;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) HashMap(java.util.HashMap) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 29 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) {
    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)

Example 30 with RelationshipScanCursor

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

the class RelationshipTransactionStateTestBase method shouldScanRelationshipInTransaction.

@Test
void shouldScanRelationshipInTransaction() throws Exception {
    final int nRelationshipsInStore = 10;
    int type;
    long n1, n2;
    try (KernelTransaction tx = beginTransaction()) {
        n1 = tx.dataWrite().nodeCreate();
        n2 = tx.dataWrite().nodeCreate();
        // setup some in store relationships
        type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
        relateNTimes(nRelationshipsInStore, type, n1, n2, tx);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        long r = tx.dataWrite().relationshipCreate(n1, type, n2);
        try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
            tx.dataRead().allRelationshipsScan(relationship);
            assertCountRelationships(relationship, nRelationshipsInStore + 1, n1, type, n2);
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

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