Search in sources :

Example 1 with NodeCursor

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

the class NodeParams method getPropertyValueFromStore.

@Override
public Value getPropertyValueFromStore(KernelTransaction tx, CursorFactory cursorFactory, long reference) {
    try (NodeCursor storeCursor = cursorFactory.allocateNodeCursor(NULL);
        PropertyCursor propertyCursor = cursorFactory.allocatePropertyCursor(NULL, INSTANCE)) {
        tx.dataRead().singleNode(reference, storeCursor);
        storeCursor.next();
        storeCursor.properties(propertyCursor);
        propertyCursor.next();
        return propertyCursor.propertyValue();
    }
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Example 2 with NodeCursor

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

the class CachingExpandIntoTest method connections.

private LongSet connections(long start, Direction direction, long end, String... types) throws TransactionFailureException {
    try (KernelTransaction tx = transaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        RelationshipTraversalCursor traversalCursor = tx.cursors().allocateRelationshipTraversalCursor(tx.cursorContext())) {
        int[] typeIds = types.length == 0 ? null : stream(types).mapToInt(tx.tokenRead()::relationshipType).toArray();
        CachingExpandInto expandInto = new CachingExpandInto(tx.dataRead(), direction, MEMORY_TRACKER);
        return toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, start, typeIds, end));
    }
}
Also used : RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Example 3 with NodeCursor

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

the class CachingExpandIntoTest method shouldComputeDegreeWithType.

@Test
void shouldComputeDegreeWithType() throws Exception {
    // GIVEN
    long node;
    int in, out, loop;
    try (KernelTransaction tx = transaction()) {
        Write write = tx.dataWrite();
        node = denseNode(tx);
        TokenWrite tokenWrite = tx.tokenWrite();
        out = tokenWrite.relationshipTypeGetOrCreateForName("OUT");
        in = tokenWrite.relationshipTypeGetOrCreateForName("IN");
        loop = tokenWrite.relationshipTypeGetOrCreateForName("LOOP");
        write.relationshipCreate(node, out, write.nodeCreate());
        write.relationshipCreate(node, out, write.nodeCreate());
        write.relationshipCreate(write.nodeCreate(), in, node);
        write.relationshipCreate(node, loop, node);
        tx.commit();
    }
    try (KernelTransaction tx = transaction()) {
        Read read = tx.dataRead();
        CursorFactory cursors = tx.cursors();
        try (NodeCursor nodes = cursors.allocateNodeCursor(tx.cursorContext())) {
            CachingExpandInto expand = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
            read.singleNode(node, nodes);
            assertThat(nodes.next()).isEqualTo(true);
            assertThat(nodes.supportsFastDegreeLookup()).isEqualTo(true);
            Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
            assertThat(degrees.outgoingDegree(out)).isEqualTo(2);
            assertThat(degrees.outgoingDegree(in)).isEqualTo(0);
            assertThat(degrees.outgoingDegree(loop)).isEqualTo(1);
            assertThat(degrees.incomingDegree(out)).isEqualTo(0);
            assertThat(degrees.incomingDegree(in)).isEqualTo(1);
            assertThat(degrees.incomingDegree(loop)).isEqualTo(1);
            assertThat(degrees.totalDegree(out)).isEqualTo(2);
            assertThat(degrees.totalDegree(in)).isEqualTo(1);
            assertThat(degrees.totalDegree(loop)).isEqualTo(1);
        }
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) Degrees(org.neo4j.storageengine.api.Degrees) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 4 with NodeCursor

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

the class NodeEntity method getDegree.

@Override
public int getDegree(RelationshipType type) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int typeId = transaction.tokenRead().relationshipType(type.name());
    if (typeId == NO_TOKEN) {
        // This type doesn't even exist. Return 0
        return 0;
    }
    NodeCursor nodes = transaction.ambientNodeCursor();
    singleNode(transaction, nodes);
    return Nodes.countAll(nodes, typeId);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Example 5 with NodeCursor

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

the class NodeEntity method getRelationshipTypes.

@Override
public Iterable<RelationshipType> getRelationshipTypes() {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    try {
        NodeCursor nodes = transaction.ambientNodeCursor();
        TokenRead tokenRead = transaction.tokenRead();
        singleNode(transaction, nodes);
        Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
        List<RelationshipType> types = new ArrayList<>();
        for (int type : degrees.types()) {
            // only include this type if there are any relationships with this type
            if (degrees.totalDegree(type) > 0) {
                types.add(RelationshipType.withName(tokenRead.relationshipTypeName(type)));
            }
        }
        return types;
    } catch (KernelException e) {
        throw new NotFoundException("Relationship name not found.", e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Degrees(org.neo4j.storageengine.api.Degrees) RelationshipType(org.neo4j.graphdb.RelationshipType) ArrayList(java.util.ArrayList) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Aggregations

NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)113 Test (org.junit.jupiter.api.Test)85 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)62 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)30 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)26 Read (org.neo4j.internal.kernel.api.Read)20 Write (org.neo4j.internal.kernel.api.Write)17 Degrees (org.neo4j.storageengine.api.Degrees)11 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)10 ArrayList (java.util.ArrayList)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 CachingExpandInto (org.neo4j.internal.kernel.api.helpers.CachingExpandInto)6 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)5 RelationshipSelection (org.neo4j.storageengine.api.RelationshipSelection)5 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)4 Future (java.util.concurrent.Future)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 NotFoundException (org.neo4j.graphdb.NotFoundException)3