use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class StateOperationsAutoIndexingTest method shouldSignalNodePropertyChangedToAutoIndex.
@Test
public void shouldSignalNodePropertyChangedToAutoIndex() throws Exception {
// Given
DefinedProperty property = property(1, "Hello!");
PropertyItem existingProperty = mock(PropertyItem.class);
when(existingProperty.propertyKeyId()).thenReturn(property.propertyKeyId());
when(existingProperty.value()).thenReturn("Goodbye!");
NodeItem node = mock(NodeItem.class);
when(node.labels()).thenReturn(PrimitiveIntCollections.emptySet());
when(storeStmt.acquireSingleNodeCursor(1337)).thenReturn(cursor(node));
when(storeLayer.nodeGetProperty(eq(storeStmt), any(NodeItem.class), eq(property.propertyKeyId()))).thenReturn(cursor(existingProperty));
// When
context.nodeSetProperty(stmt, 1337, property);
// Then
verify(nodeOps).propertyChanged(eq(writeOps), eq(1337L), any(Property.class), eq(property));
}
use of org.neo4j.storageengine.api.PropertyItem 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.storageengine.api.PropertyItem in project neo4j by neo4j.
the class RelationshipProxy method getAllProperties.
@Override
public Map<String, Object> getAllProperties() {
try (Statement statement = actions.statement()) {
try (Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursorById(getId())) {
try (Cursor<PropertyItem> propertyCursor = statement.readOperations().relationshipGetProperties(relationship.get())) {
Map<String, Object> properties = new HashMap<>();
// Get all properties
while (propertyCursor.next()) {
String name = statement.readOperations().propertyKeyGetName(propertyCursor.get().propertyKeyId());
properties.put(name, propertyCursor.get().value());
}
return properties;
}
} catch (EntityNotFoundException e) {
throw new NotFoundException("Relationship not found", e);
}
} catch (PropertyKeyIdNotFoundKernelException e) {
throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
}
}
use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class PropertyExistenceEnforcer method properties.
private Cursor<PropertyItem> properties(RelationshipItem relationship) {
Lock lock = relationship.lock();
Cursor<PropertyItem> cursor = storeStatement().acquirePropertyCursor(relationship.nextPropertyId(), lock);
return txState.augmentPropertyCursor(cursor, txState.getRelationshipState(relationship.id()));
}
use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class PropertyExistenceEnforcer method validateNode.
private void validateNode(long nodeId) throws NodePropertyExistenceException {
if (labelExistenceConstraints.isEmpty()) {
return;
}
try (Cursor<NodeItem> node = nodeCursor(nodeId)) {
if (node.next()) {
PrimitiveIntSet labelIds = node.get().labels();
propertyKeyIds.clear();
try (Cursor<PropertyItem> properties = properties(node.get())) {
while (properties.next()) {
propertyKeyIds.add(properties.get().propertyKeyId());
}
}
for (LabelSchemaDescriptor descriptor : labelExistenceConstraints) {
if (labelIds.contains(descriptor.getLabelId())) {
for (int propertyId : descriptor.getPropertyIds()) {
validateNodeProperty(nodeId, propertyId, descriptor);
}
}
}
} else {
throw new IllegalStateException(format("Node %d with changes should exist.", nodeId));
}
}
}
Aggregations