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;
}
}
}
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());
}
}
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());
}
}
}
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));
}
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));
}
Aggregations