Search in sources :

Example 1 with StoragePropertyCursor

use of org.neo4j.storageengine.api.StoragePropertyCursor in project neo4j by neo4j.

the class RecordStorageReaderPropertyTest method shouldGetAllNodeProperties.

@Test
void shouldGetAllNodeProperties() throws Exception {
    // GIVEN
    String longString = "AlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalong";
    Object[] properties = { longString, createNew(String.class), createNew(long.class), createNew(int.class), createNew(byte.class), createNew(short.class), createNew(boolean.class), createNew(char.class), createNew(float.class), createNew(double.class), array(0, String.class), array(0, long.class), array(0, int.class), array(0, byte.class), array(0, short.class), array(0, boolean.class), array(0, char.class), array(0, float.class), array(0, double.class), array(1, String.class), array(1, long.class), array(1, int.class), array(1, byte.class), array(1, short.class), array(1, boolean.class), array(1, char.class), array(1, float.class), array(1, double.class), array(256, String.class), array(256, long.class), array(256, int.class), array(256, byte.class), array(256, short.class), array(256, boolean.class), array(256, char.class), array(256, float.class), array(256, double.class) };
    for (Object value : properties) {
        // given
        long nodeId = createNode(singletonMap("prop", value), label1);
        // when
        try (StorageNodeCursor node = storageReader.allocateNodeCursor(NULL)) {
            node.single(nodeId);
            assertTrue(node.next());
            try (StoragePropertyCursor props = storageReader.allocatePropertyCursor(NULL, INSTANCE)) {
                node.properties(props);
                if (props.next()) {
                    Value propVal = props.propertyValue();
                    // then
                    assertTrue(propVal.equals(Values.of(value)), propVal + ".equals(" + value + ")");
                } else {
                    fail();
                }
            }
        }
    }
}
Also used : StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) Value(org.neo4j.values.storable.Value) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Test(org.junit.jupiter.api.Test)

Example 2 with StoragePropertyCursor

use of org.neo4j.storageengine.api.StoragePropertyCursor in project neo4j by neo4j.

the class GraphStoreFixture method nodeAsUpdates.

public EntityUpdates nodeAsUpdates(long nodeId) {
    try (StorageReader storeReader = storageEngine.newReader();
        StorageNodeCursor nodeCursor = storeReader.allocateNodeCursor(NULL);
        StoragePropertyCursor propertyCursor = storeReader.allocatePropertyCursor(NULL, INSTANCE)) {
        nodeCursor.single(nodeId);
        long[] labels;
        if (!nodeCursor.next() || !nodeCursor.hasProperties() || (labels = nodeCursor.labels()).length == 0) {
            return null;
        }
        nodeCursor.properties(propertyCursor);
        EntityUpdates.Builder update = EntityUpdates.forEntity(nodeId, true).withTokens(labels);
        while (propertyCursor.next()) {
            update.added(propertyCursor.propertyKey(), propertyCursor.propertyValue());
        }
        return update.build();
    }
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 3 with StoragePropertyCursor

use of org.neo4j.storageengine.api.StoragePropertyCursor in project neo4j by neo4j.

the class TxStateTransactionDataSnapshot method takeSnapshot.

private void takeSnapshot(MemoryTracker memoryTracker) {
    var cursorContext = transaction.cursorContext();
    try (StorageNodeCursor node = store.allocateNodeCursor(cursorContext);
        StoragePropertyCursor properties = store.allocatePropertyCursor(cursorContext, memoryTracker)) {
        TokenRead tokenRead = transaction.tokenRead();
        snapshotRemovedNodes(memoryTracker, node, properties, tokenRead);
        snapshotRemovedRelationships(memoryTracker, properties, tokenRead);
        snapshotModifiedNodes(memoryTracker, node, properties, tokenRead);
        snapshotModifiedRelationships(memoryTracker, properties, tokenRead);
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("An entity that does not exist was modified.", e);
    }
}
Also used : StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 4 with StoragePropertyCursor

use of org.neo4j.storageengine.api.StoragePropertyCursor in project neo4j by neo4j.

the class RecordStorageReaderLabelTest method labelsShouldNotLeakOutAsProperties.

@Test
void labelsShouldNotLeakOutAsProperties() throws Exception {
    // GIVEN
    long nodeId = createNode(map("name", "Node"), label1);
    int namePropertyKeyId = propertyKeyId("name");
    // WHEN THEN
    StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(NULL);
    StoragePropertyCursor propertyCursor = storageReader.allocatePropertyCursor(NULL, INSTANCE);
    nodeCursor.single(nodeId);
    assertTrue(nodeCursor.next());
    nodeCursor.properties(propertyCursor);
    assertTrue(propertyCursor.next());
    assertEquals(namePropertyKeyId, propertyCursor.propertyKey());
    assertFalse(propertyCursor.next());
}
Also used : StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Test(org.junit.jupiter.api.Test)

Example 5 with StoragePropertyCursor

use of org.neo4j.storageengine.api.StoragePropertyCursor in project neo4j by neo4j.

the class GenerateIndexUpdatesStep method process.

@Override
protected void process(long[] entityIds, BatchSender sender, CursorContext cursorContext) throws Exception {
    GeneratedIndexUpdates updates = new GeneratedIndexUpdates(gatherPropertyUpdates, gatherTokenUpdates);
    try (CURSOR nodeCursor = entityCursorBehaviour.allocateEntityScanCursor(cursorContext);
        StoragePropertyCursor propertyCursor = reader.allocatePropertyCursor(cursorContext, memoryTracker)) {
        for (long entityId : entityIds) {
            try (Lock ignored = lockFunction.apply(entityId)) {
                nodeCursor.single(entityId);
                if (nodeCursor.next()) {
                    generateUpdates(updates, nodeCursor, propertyCursor);
                    if (updates.propertiesByteSize > maxBatchSizeBytes) {
                        batchDone(updates, sender);
                        updates = new GeneratedIndexUpdates(gatherPropertyUpdates, gatherTokenUpdates);
                    }
                }
            }
        }
    }
    batchDone(updates, sender);
}
Also used : StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) Lock(org.neo4j.lock.Lock)

Aggregations

StoragePropertyCursor (org.neo4j.storageengine.api.StoragePropertyCursor)6 StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)5 Test (org.junit.jupiter.api.Test)2 Value (org.neo4j.values.storable.Value)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 SimpleStageControl (org.neo4j.internal.batchimport.staging.SimpleStageControl)1 TokenRead (org.neo4j.internal.kernel.api.TokenRead)1 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)1 GeneratedIndexUpdates (org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates)1 Lock (org.neo4j.lock.Lock)1 EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)1 StorageReader (org.neo4j.storageengine.api.StorageReader)1 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)1 Values.intValue (org.neo4j.values.storable.Values.intValue)1 Values.stringValue (org.neo4j.values.storable.Values.stringValue)1