use of org.neo4j.storageengine.api.NodeItem 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.NodeItem in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method nodeSetProperty.
@Override
public Property nodeSetProperty(KernelStatement state, long nodeId, DefinedProperty property) throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException, ConstraintValidationException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
Iterator<ConstraintDescriptor> constraints = getConstraintsInvolvingProperty(state, property.propertyKeyId());
Iterator<UniquenessConstraintDescriptor> uniquenessConstraints = new CastingIterator<>(constraints, UniquenessConstraintDescriptor.class);
nodeSchemaMatcher.onMatchingSchema(state, uniquenessConstraints, node, property.propertyKeyId(), constraint -> {
validateNoExistingNodeWithExactValues(state, constraint, getAllPropertyValues(state, constraint.schema(), node, property), node.id());
});
}
return entityWriteOperations.nodeSetProperty(state, nodeId, property);
}
use of org.neo4j.storageengine.api.NodeItem 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.NodeItem in project neo4j by neo4j.
the class StateHandlingStatementOperations method nodeAddLabel.
@Override
public boolean nodeAddLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
if (node.hasLabel(labelId)) {
// Label is already in state or in store, no-op
return false;
}
state.txState().nodeDoAddLabel(labelId, node.id());
indexTxStateUpdater.onLabelChange(state, labelId, node, ADDED_LABEL);
return true;
}
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.
@Test
public void shouldAllowManyLabelsAndPropertyCursor() throws Exception {
int propertyCount = 10;
int labelCount = 15;
GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
Node node;
try (Transaction tx = db.beginTx()) {
node = db.createNode();
for (int i = 0; i < propertyCount; i++) {
node.setProperty("foo" + i, "bar");
}
for (int i = 0; i < labelCount; i++) {
node.addLabel(label("label" + i));
}
tx.success();
}
Set<Integer> seenProperties = new HashSet<>();
Set<Integer> seenLabels = new HashSet<>();
try (Transaction tx = db.beginTx()) {
DependencyResolver resolver = db.getDependencyResolver();
ThreadToStatementContextBridge bridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
try (Statement statement = bridge.getTopLevelTransactionBoundToThisThread(true).acquireStatement()) {
try (Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId())) {
try (Cursor<PropertyItem> properties = statement.readOperations().nodeGetProperties(nodeCursor.get())) {
while (properties.next()) {
seenProperties.add(properties.get().propertyKeyId());
consume(nodeCursor.get().labels().iterator(), seenLabels::add);
}
}
}
}
tx.success();
}
assertEquals(propertyCount, seenProperties.size());
assertEquals(labelCount, seenLabels.size());
}
Aggregations