Search in sources :

Example 1 with StorageProperty

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

the class TxAllPropertyCursor method next.

@Override
public boolean next() {
    if (added == null) {
        while (cursor.next()) {
            int propertyKeyId = cursor.get().propertyKeyId();
            StorageProperty changedProperty = state.getChangedProperty(propertyKeyId);
            if (changedProperty != null) {
                this.property = (DefinedProperty) changedProperty;
                return true;
            }
            if (!state.isPropertyRemoved(propertyKeyId)) {
                this.property = Property.property(propertyKeyId, cursor.get().value());
                return true;
            }
        }
        added = state.addedProperties();
    }
    if (added != null && added.hasNext()) {
        property = (DefinedProperty) added.next();
        return true;
    } else {
        property = null;
        return false;
    }
}
Also used : StorageProperty(org.neo4j.storageengine.api.StorageProperty)

Example 2 with StorageProperty

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

the class TxSinglePropertyCursor method next.

@Override
public boolean next() {
    if (propertyKeyId == StatementConstants.NO_SUCH_PROPERTY_KEY) {
        return false;
    }
    try {
        seekFoundIt = false;
        StorageProperty changedProperty = state.getChangedProperty(propertyKeyId);
        if (changedProperty != null) {
            this.property = (DefinedProperty) changedProperty;
            return true;
        }
        StorageProperty addedProperty = state.getAddedProperty(propertyKeyId);
        if (addedProperty != null) {
            this.property = (DefinedProperty) addedProperty;
            return true;
        }
        if (state.isPropertyRemoved(propertyKeyId)) {
            this.property = null;
            return false;
        }
        if (cursor.next()) {
            this.property = null;
            return seekFoundIt = true;
        } else {
            this.property = null;
            return false;
        }
    } finally {
        propertyKeyId = StatementConstants.NO_SUCH_PROPERTY_KEY;
    }
}
Also used : StorageProperty(org.neo4j.storageengine.api.StorageProperty)

Example 3 with StorageProperty

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

the class TxStateTransactionDataSnapshot method takeSnapshot.

private void takeSnapshot() {
    try {
        for (long nodeId : state.addedAndRemovedNodes().getRemoved()) {
            try (Cursor<NodeItem> node = storeStatement.acquireSingleNodeCursor(nodeId)) {
                if (node.next()) {
                    Lock lock = node.get().lock();
                    try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(node.get().nextPropertyId(), lock)) {
                        while (properties.next()) {
                            removedNodeProperties.add(new NodePropertyEntryView(nodeId, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
                        }
                    }
                    node.get().labels().visitKeys(labelId -> {
                        removedLabels.add(new LabelEntryView(nodeId, store.labelGetName(labelId)));
                        return false;
                    });
                }
            }
        }
        for (long relId : state.addedAndRemovedRelationships().getRemoved()) {
            Relationship relationshipProxy = relationship(relId);
            try (Cursor<RelationshipItem> relationship = storeStatement.acquireSingleRelationshipCursor(relId)) {
                if (relationship.next()) {
                    Lock lock = relationship.get().lock();
                    try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(relationship.get().nextPropertyId(), lock)) {
                        while (properties.next()) {
                            removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationshipProxy, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
                        }
                    }
                }
            }
        }
        for (NodeState nodeState : state.modifiedNodes()) {
            Iterator<StorageProperty> added = nodeState.addedAndChangedProperties();
            while (added.hasNext()) {
                DefinedProperty property = (DefinedProperty) added.next();
                assignedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(nodeState, property.propertyKeyId())));
            }
            Iterator<Integer> removed = nodeState.removedProperties();
            while (removed.hasNext()) {
                Integer property = removed.next();
                removedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property), null, committedValue(nodeState, property)));
            }
            ReadableDiffSets<Integer> labels = nodeState.labelDiffSets();
            for (Integer label : labels.getAdded()) {
                assignedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
            }
            for (Integer label : labels.getRemoved()) {
                removedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
            }
        }
        for (RelationshipState relState : state.modifiedRelationships()) {
            Relationship relationship = relationship(relState.getId());
            Iterator<StorageProperty> added = relState.addedAndChangedProperties();
            while (added.hasNext()) {
                DefinedProperty property = (DefinedProperty) added.next();
                assignedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(relState, property.propertyKeyId())));
            }
            Iterator<Integer> removed = relState.removedProperties();
            while (removed.hasNext()) {
                Integer property = removed.next();
                removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property), null, committedValue(relState, property)));
            }
        }
    } catch (PropertyKeyIdNotFoundKernelException | LabelNotFoundKernelException e) {
        throw new IllegalStateException("An entity that does not exist was modified.", e);
    }
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeState(org.neo4j.storageengine.api.txstate.NodeState) LabelNotFoundKernelException(org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException) RelationshipState(org.neo4j.storageengine.api.txstate.RelationshipState) Lock(org.neo4j.kernel.impl.locking.Lock) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Relationship(org.neo4j.graphdb.Relationship) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 4 with StorageProperty

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

the class TxStateTest method doNotVisitNotModifiedLabelsOnModifiedNodes.

@Test
void doNotVisitNotModifiedLabelsOnModifiedNodes() throws KernelException {
    state.nodeDoAddProperty(1, 2, stringValue("propertyValue"));
    MutableBoolean propertiesChecked = new MutableBoolean();
    state.accept(new TxStateVisitor.Adapter() {

        @Override
        public void visitNodeLabelChanges(long id, LongSet added, LongSet removed) {
            fail("Labels were not changed.");
        }

        @Override
        public void visitNodePropertyChanges(long id, Iterator<StorageProperty> added, Iterator<StorageProperty> changed, IntIterable removed) {
            propertiesChecked.setTrue();
            assertEquals(1, id);
            assertFalse(changed.hasNext());
            assertTrue(removed.isEmpty());
            assertEquals(1, Iterators.count(added, Predicates.alwaysTrue()));
        }
    });
    assertTrue(propertiesChecked.booleanValue());
}
Also used : TxStateVisitor(org.neo4j.storageengine.api.txstate.TxStateVisitor) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) LongSet(org.eclipse.collections.api.set.primitive.LongSet) StorageProperty(org.neo4j.storageengine.api.StorageProperty) IntIterable(org.eclipse.collections.api.IntIterable) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 5 with StorageProperty

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

the class TransactionToRecordStateVisitor method visitNodePropertyChanges.

@Override
public void visitNodePropertyChanges(long id, Iterator<StorageProperty> added, Iterator<StorageProperty> changed, IntIterable removed) {
    removed.each(propId -> recordState.nodeRemoveProperty(id, propId));
    while (changed.hasNext()) {
        StorageProperty prop = changed.next();
        recordState.nodeChangeProperty(id, prop.propertyKeyId(), prop.value());
    }
    while (added.hasNext()) {
        StorageProperty prop = added.next();
        recordState.nodeAddProperty(id, prop.propertyKeyId(), prop.value());
    }
}
Also used : StorageProperty(org.neo4j.storageengine.api.StorageProperty)

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