Search in sources :

Example 11 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class StateHandlingStatementOperations method graphSetProperty.

@Override
public Property graphSetProperty(KernelStatement state, DefinedProperty property) {
    Object existingPropertyValue = graphGetProperty(state, property.propertyKeyId());
    Property existingProperty = existingPropertyValue == null ? Property.noGraphProperty(property.propertyKeyId()) : Property.property(property.propertyKeyId(), existingPropertyValue);
    state.txState().graphDoReplaceProperty(existingProperty, property);
    return existingProperty;
}
Also used : Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty)

Example 12 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class StateHandlingStatementOperations method nodeRemoveProperty.

@Override
public Property nodeRemoveProperty(KernelStatement state, long nodeId, int propertyKeyId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
        NodeItem node = cursor.get();
        DefinedProperty existingProperty = NO_SUCH_PROPERTY;
        try (Cursor<PropertyItem> properties = nodeGetPropertyCursor(state, node, propertyKeyId)) {
            if (properties.next()) {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.nodes().propertyRemoved(ops, nodeId, propertyKeyId);
                state.txState().nodeDoRemoveProperty(node.id(), existingProperty);
                indexTxStateUpdater.onPropertyRemove(state, node, existingProperty);
            }
        }
        if (existingProperty == NO_SUCH_PROPERTY) {
            return Property.noProperty(propertyKeyId, EntityType.NODE, node.id());
        }
        return existingProperty;
    }
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem)

Example 13 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class StateHandlingStatementOperations method relationshipRemoveProperty.

@Override
public Property relationshipRemoveProperty(KernelStatement state, long relationshipId, int propertyKeyId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
        RelationshipItem relationship = cursor.get();
        Property existingProperty;
        try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, propertyKeyId)) {
            if (!properties.next()) {
                existingProperty = Property.noProperty(propertyKeyId, EntityType.RELATIONSHIP, relationship.id());
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.relationships().propertyRemoved(ops, relationshipId, propertyKeyId);
                state.txState().relationshipDoRemoveProperty(relationship.id(), (DefinedProperty) existingProperty);
            }
        }
        return existingProperty;
    }
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 14 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class StateHandlingStatementOperations method relationshipSetProperty.

@Override
public Property relationshipSetProperty(KernelStatement state, long relationshipId, DefinedProperty property) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
        RelationshipItem relationship = cursor.get();
        Property existingProperty;
        try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, property.propertyKeyId())) {
            if (!properties.next()) {
                autoIndexing.relationships().propertyAdded(ops, relationshipId, property);
                existingProperty = Property.noProperty(property.propertyKeyId(), EntityType.RELATIONSHIP, relationship.id());
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.relationships().propertyChanged(ops, relationshipId, existingProperty, property);
            }
        }
        state.txState().relationshipDoReplaceProperty(relationship.id(), existingProperty, property);
        return existingProperty;
    }
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 15 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty 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)

Aggregations

DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)47 Test (org.junit.Test)23 Pair (org.neo4j.helpers.collection.Pair)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)8 PropertyItem (org.neo4j.storageengine.api.PropertyItem)8 NodeItem (org.neo4j.storageengine.api.NodeItem)7 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)7 Property (org.neo4j.kernel.api.properties.Property)6 PropertyEntry (org.neo4j.graphdb.event.PropertyEntry)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)4 StorageProperty (org.neo4j.storageengine.api.StorageProperty)4 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Statement (org.neo4j.kernel.api.Statement)3