Search in sources :

Example 26 with DefinedProperty

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

the class StateHandlingStatementOperations method nodeSetProperty.

@Override
public Property nodeSetProperty(KernelStatement state, long nodeId, DefinedProperty property) 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, property.propertyKeyId())) {
            if (!properties.next()) {
                autoIndexing.nodes().propertyAdded(ops, nodeId, property);
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.nodes().propertyChanged(ops, nodeId, existingProperty, property);
            }
        }
        if (existingProperty == NO_SUCH_PROPERTY) {
            state.txState().nodeDoAddProperty(node.id(), property);
            indexTxStateUpdater.onPropertyAdd(state, node, property);
            return Property.noProperty(property.propertyKeyId(), EntityType.NODE, node.id());
        } else {
            state.txState().nodeDoChangeProperty(node.id(), existingProperty, property);
            indexTxStateUpdater.onPropertyChange(state, node, existingProperty, property);
            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 27 with DefinedProperty

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

the class TransactionToRecordStateVisitor method visitRelPropertyChanges.

@Override
public void visitRelPropertyChanges(long id, Iterator<StorageProperty> added, Iterator<StorageProperty> changed, Iterator<Integer> removed) {
    while (removed.hasNext()) {
        recordState.relRemoveProperty(id, removed.next());
    }
    while (changed.hasNext()) {
        DefinedProperty prop = (DefinedProperty) changed.next();
        recordState.relChangeProperty(id, prop.propertyKeyId(), prop.value());
    }
    while (added.hasNext()) {
        DefinedProperty prop = (DefinedProperty) added.next();
        recordState.relAddProperty(id, prop.propertyKeyId(), prop.value());
    }
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty)

Example 28 with DefinedProperty

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

the class NodeUpdates method setProperties.

public void setProperties(PropertyUpdate propertyUpdates, DefinedProperty[] definedProperties) {
    propertiesBefore.clear();
    propertiesAfter.clear();
    propertiesUnchanged.clear();
    PropertyUpdate current = propertyUpdates;
    while (current != null) {
        switch(current.mode) {
            case ADDED:
                propertiesAfter.put(current.propertyKeyId, current.value);
                break;
            case REMOVED:
                propertiesBefore.put(current.propertyKeyId, current.value);
                break;
            case CHANGED:
                propertiesBefore.put(current.propertyKeyId, ((PropertyChanged) current).before);
                propertiesAfter.put(current.propertyKeyId, current.value);
                break;
            default:
                throw new IllegalStateException(current.mode.toString());
        }
        current = current.next;
    }
    for (DefinedProperty property : definedProperties) {
        if (!propertiesAfter.containsKey(property.propertyKeyId()) && !propertiesBefore.containsKey(property.propertyKeyId())) {
            propertiesUnchanged.put(property.propertyKeyId(), property.value());
        }
    }
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty)

Example 29 with DefinedProperty

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

the class TransactionRecordStateTest method shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates.

@Test
public void shouldConvertMixedLabelRemovalAndAddPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    addLabelsToNode(recordState, nodeId, bothLabelIds);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    removeLabelsFromNode(recordState, nodeId, secondLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, bothLabelIds, oneLabelId).added(property2.propertyKeyId(), property2.value()).buildWithExistingProperties(property1, property2);
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 30 with DefinedProperty

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

the class TransactionRecordStateTest method shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates.

@Test
public void shouldConvertMixedLabelRemovalAndRemovePropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    DefinedProperty property1 = recordState.nodeAddProperty(nodeId, propertyId1, value1);
    DefinedProperty property2 = recordState.nodeAddProperty(nodeId, propertyId2, value2);
    addLabelsToNode(recordState, nodeId, bothLabelIds);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeRemoveProperty(nodeId, property1.propertyKeyId());
    removeLabelsFromNode(recordState, nodeId, secondLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, bothLabelIds, oneLabelId).removed(property1.propertyKeyId(), property1.value()).buildWithExistingProperties(property2);
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

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