Search in sources :

Example 91 with NodeCursor

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

the class NodeWriteTestBase method shouldSetAndReadLargeByteArrayPropertyToNode.

@Test
void shouldSetAndReadLargeByteArrayPropertyToNode() throws Exception {
    // Given
    int prop;
    long node = createNode();
    Value largeByteArray = Values.of(new byte[100_000]);
    // When
    try (KernelTransaction tx = beginTransaction()) {
        prop = tx.token().propertyKeyGetOrCreateForName(propertyKey);
        assertThat(tx.dataWrite().nodeSetProperty(node, prop, largeByteArray)).isEqualTo(NO_VALUE);
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
        tx.dataRead().singleNode(node, nodeCursor);
        assertTrue(nodeCursor.next());
        nodeCursor.properties(propertyCursor);
        assertTrue(propertyCursor.next());
        assertEquals(propertyCursor.propertyKey(), prop);
        assertThat(propertyCursor.propertyValue()).isEqualTo(largeByteArray);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Values.intValue(org.neo4j.values.storable.Values.intValue) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 92 with NodeCursor

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

the class Operations method nodeDetachDelete.

@Override
public int nodeDetachDelete(long nodeId) {
    ktx.assertOpen();
    commandCreationContext.acquireNodeDeletionLock(ktx.txState(), ktx.lockClient(), ktx.lockTracer(), nodeId);
    NodeCursor nodeCursor = ktx.ambientNodeCursor();
    ktx.dataRead().singleNode(nodeId, nodeCursor);
    int deletedRelationships = 0;
    if (nodeCursor.next()) {
        try (var rels = RelationshipSelections.allCursor(ktx.cursors(), nodeCursor, null, ktx.cursorContext())) {
            while (rels.next()) {
                boolean deleted = relationshipDelete(rels.relationshipReference());
                if (additionLockVerification && !deleted) {
                    throw new RuntimeException("Relationship chain modified even when node delete lock was held: " + rels);
                }
                deletedRelationships++;
            }
        }
    }
    // we are already holding the lock
    nodeDelete(nodeId, false);
    return deletedRelationships;
}
Also used : NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Example 93 with NodeCursor

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

the class TransactionTestBase method assertNoNode.

private void assertNoNode(long nodeId) throws TransactionFailureException {
    try (KernelTransaction tx = beginTransaction();
        NodeCursor cursor = tx.cursors().allocateNodeCursor(NULL)) {
        tx.dataRead().singleNode(nodeId, cursor);
        assertFalse(cursor.next());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Example 94 with NodeCursor

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

the class TransactionTestBase method assertNodeExists.

private void assertNodeExists(long nodeId) throws TransactionFailureException {
    try (KernelTransaction tx = beginTransaction();
        NodeCursor cursor = tx.cursors().allocateNodeCursor(NULL)) {
        tx.dataRead().singleNode(nodeId, cursor);
        assertTrue(cursor.next());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor)

Example 95 with NodeCursor

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

the class FulltextIndexTransactionState method updateSearcher.

private void updateSearcher(QueryContext context, CursorContext cursorContext, MemoryTracker memoryTracker) throws Exception {
    Read read = context.getRead();
    CursorFactory cursors = context.cursors();
    ReadableTransactionState state = context.getTransactionStateOrNull();
    // Clear this, so we don't filter out entities who have had their changes reversed since last time.
    modifiedEntityIdsInThisTransaction.clear();
    writer.resetWriterState();
    try (NodeCursor nodeCursor = visitingNodes ? cursors.allocateFullAccessNodeCursor(cursorContext) : null;
        RelationshipScanCursor relationshipCursor = visitingNodes ? null : cursors.allocateRelationshipScanCursor(cursorContext);
        PropertyCursor propertyCursor = cursors.allocateFullAccessPropertyCursor(cursorContext, memoryTracker)) {
        state.accept(txStateVisitor.init(read, nodeCursor, relationshipCursor, propertyCursor));
    }
    currentSearcher = writer.getNearRealTimeSearcher();
    toCloseLater.add(currentSearcher);
    lastUpdateRevision = state.getDataRevision();
}
Also used : Read(org.neo4j.internal.kernel.api.Read) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

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