Search in sources :

Example 6 with StorageProperty

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

the class NeoStoresTest method nodeAddProperty.

private StorageProperty nodeAddProperty(long nodeId, int key, Object value) {
    StorageProperty property = new PropertyKeyValue(key, Values.of(value));
    StorageProperty oldProperty = null;
    try (StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(NULL)) {
        nodeCursor.single(nodeId);
        if (nodeCursor.next()) {
            StorageProperty fetched = getProperty(key, nodeCursor.propertiesReference());
            if (fetched != null) {
                oldProperty = fetched;
            }
        }
    }
    if (oldProperty == null) {
        transactionState.nodeDoAddProperty(nodeId, key, property.value());
    } else {
        transactionState.nodeDoChangeProperty(nodeId, key, property.value());
    }
    return property;
}
Also used : PropertyKeyValue(org.neo4j.storageengine.api.PropertyKeyValue) StorageProperty(org.neo4j.storageengine.api.StorageProperty) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 7 with StorageProperty

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

the class IteratingPropertyReceiverTest method shouldAcceptAndThenIterateOverProperties.

@Test
public void shouldAcceptAndThenIterateOverProperties() throws PropertyNotFoundException {
    // GIVEN
    IteratingPropertyReceiver<StorageProperty> receiver = new IteratingPropertyReceiver<>();
    int propertyCount = 100;
    for (int i = 0; i < propertyCount; i++) {
        receiver.receive(Property.intProperty(1, i), 5);
    }
    // THEN
    int count = 0;
    while (receiver.hasNext()) {
        StorageProperty property = receiver.next();
        assertEquals(count++, ((Integer) property.value()).intValue());
    }
    assertFalse(receiver.hasNext());
    assertEquals(propertyCount, count);
}
Also used : StorageProperty(org.neo4j.storageengine.api.StorageProperty) Test(org.junit.Test)

Example 8 with StorageProperty

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

the class TxStateTransactionDataSnapshot method snapshotModifiedNodes.

private void snapshotModifiedNodes(MemoryTracker memoryTracker, StorageNodeCursor node, StoragePropertyCursor properties, TokenRead tokenRead) throws PropertyKeyIdNotFoundKernelException {
    for (NodeState nodeState : state.modifiedNodes()) {
        Iterator<StorageProperty> added = nodeState.addedAndChangedProperties();
        long nodeId = nodeState.getId();
        while (added.hasNext()) {
            StorageProperty property = added.next();
            var entryView = createNodePropertyEntryView(memoryTracker, tokenRead, nodeId, property.propertyKeyId(), property.value(), committedValue(nodeState, property.propertyKeyId(), node, properties));
            assignedNodeProperties.add(entryView);
        }
        nodeState.removedProperties().each(id -> {
            try {
                removedNodeProperties.add(createNodePropertyEntryView(memoryTracker, tokenRead, nodeId, id, null, committedValue(nodeState, id, node, properties)));
            } catch (PropertyKeyIdNotFoundKernelException e) {
                throw new IllegalStateException("Not existing node properties was modified for node " + nodeId, e);
            }
        });
        final LongDiffSets labels = nodeState.labelDiffSets();
        addLabelEntriesTo(nodeId, labels.getAdded(), assignedLabels);
        addLabelEntriesTo(nodeId, labels.getRemoved(), removedLabels);
    }
}
Also used : NodeState(org.neo4j.storageengine.api.txstate.NodeState) StorageProperty(org.neo4j.storageengine.api.StorageProperty) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 9 with StorageProperty

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

the class TxStateTransactionDataSnapshot method snapshotModifiedRelationships.

private void snapshotModifiedRelationships(MemoryTracker memoryTracker, StoragePropertyCursor properties, TokenRead tokenRead) throws PropertyKeyIdNotFoundKernelException {
    for (RelationshipState relState : state.modifiedRelationships()) {
        Relationship relationship = relationship(relState.getId());
        Iterator<StorageProperty> added = relState.addedAndChangedProperties();
        while (added.hasNext()) {
            StorageProperty property = added.next();
            assignedRelationshipProperties.add(createRelationshipPropertyEntryView(memoryTracker, tokenRead, relationship, property.propertyKeyId(), property.value(), committedValue(relState, property.propertyKeyId(), this.relationship, properties)));
        }
        relState.removedProperties().each(id -> {
            try {
                var entryView = createRelationshipPropertyEntryView(memoryTracker, tokenRead, relationship, id, null, committedValue(relState, id, this.relationship, properties));
                removedRelationshipProperties.add(entryView);
            } catch (PropertyKeyIdNotFoundKernelException e) {
                throw new IllegalStateException("Not existing properties was modified for relationship " + relState.getId(), e);
            }
        });
    }
}
Also used : Relationship(org.neo4j.graphdb.Relationship) RelationshipState(org.neo4j.storageengine.api.txstate.RelationshipState) StorageProperty(org.neo4j.storageengine.api.StorageProperty) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 10 with StorageProperty

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

the class EntityValueUpdatesTest method propertyLoader.

private static StorageReader propertyLoader(StorageProperty... properties) {
    StubStorageCursors stub = new StubStorageCursors();
    for (StorageProperty property : properties) {
        stub.propertyKeyTokenHolder().addToken(new NamedToken(String.valueOf(property.propertyKeyId()), property.propertyKeyId()));
    }
    Map<String, Value> propertyMap = new HashMap<>();
    for (StorageProperty p : properties) {
        propertyMap.put(String.valueOf(p.propertyKeyId()), p.value());
    }
    stub.withNode(ENTITY_ID).properties(propertyMap);
    stub.withRelationship(ENTITY_ID, 1, 1, 2).properties(propertyMap);
    return stub;
}
Also used : HashMap(java.util.HashMap) Value(org.neo4j.values.storable.Value) PropertyKeyValue(org.neo4j.storageengine.api.PropertyKeyValue) StorageProperty(org.neo4j.storageengine.api.StorageProperty) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) NamedToken(org.neo4j.token.api.NamedToken)

Aggregations

StorageProperty (org.neo4j.storageengine.api.StorageProperty)13 Test (org.junit.jupiter.api.Test)3 PropertyKeyValue (org.neo4j.storageengine.api.PropertyKeyValue)3 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)2 IntIterable (org.eclipse.collections.api.IntIterable)2 LongSet (org.eclipse.collections.api.set.primitive.LongSet)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 Relationship (org.neo4j.graphdb.Relationship)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 NodeState (org.neo4j.storageengine.api.txstate.NodeState)2 RelationshipState (org.neo4j.storageengine.api.txstate.RelationshipState)2 TxStateVisitor (org.neo4j.storageengine.api.txstate.TxStateVisitor)2 Value (org.neo4j.values.storable.Value)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 LabelNotFoundKernelException (org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException)1 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)1 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)1 Lock (org.neo4j.kernel.impl.locking.Lock)1 NodeItem (org.neo4j.storageengine.api.NodeItem)1