use of org.neo4j.storageengine.api.NodeItem 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));
}
}
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class TestMigrateToDenseNodeSupport method verifyDenseRepresentation.
private void verifyDenseRepresentation(GraphDatabaseService db, Node node, boolean dense) {
KernelAPI kernelAPI = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(KernelAPI.class);
try (KernelTransaction tx = kernelAPI.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = tx.acquireStatement()) {
Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId());
assertEquals(dense, nodeCursor.get().isDense());
} catch (TransactionFailureException | IllegalArgumentException | EntityNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class TwoPhaseNodeForRelationshipLockingTest method returnRelationships.
static void returnRelationships(EntityReadOperations ops, KernelStatement state, long nodeId, final boolean skipFirst, final RelationshipData... relIds) throws EntityNotFoundException {
NodeItem nodeItem = mock(NodeItem.class);
when(ops.nodeGetRelationships(state, nodeItem, Direction.BOTH)).thenAnswer(new Answer<Cursor<RelationshipItem>>() {
private boolean first = skipFirst;
@Override
public Cursor<RelationshipItem> answer(InvocationOnMock invocation) throws Throwable {
try {
return new Cursor<RelationshipItem>() {
private int i = first ? 1 : 0;
private RelationshipData relationshipData = null;
@Override
public boolean next() {
boolean next = i < relIds.length;
relationshipData = next ? relIds[i++] : null;
return next;
}
@Override
public RelationshipItem get() {
if (relationshipData == null) {
throw new NoSuchElementException();
}
return relationshipData.asRelationshipItem();
}
@Override
public void close() {
}
};
} finally {
first = false;
}
}
});
when(ops.nodeCursorById(state, nodeId)).thenAnswer(invocationOnMock -> {
Cursor<NodeItem> cursor = new Cursor<NodeItem>() {
private int i = 0;
@Override
public boolean next() {
return i++ == 0;
}
@Override
public NodeItem get() {
if (i != 1) {
throw new NoSuchElementException();
}
return nodeItem;
}
@Override
public void close() {
}
};
if (!cursor.next()) {
throw new EntityNotFoundException(EntityType.NODE, nodeId);
}
return cursor;
});
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class NodeSchemaMatcherTest method setup.
@Before
public void setup() {
state = mock(KernelStatement.class);
PrimitiveIntSet labels = Primitive.intSet();
labels.add(labelId1);
Cursor<NodeItem> nodeItemCursor = StubCursors.asNodeCursor(0, labels);
nodeItemCursor.next();
node = nodeItemCursor.get();
PrimitiveIntSet defaultPropertyIds = PrimitiveIntCollections.asSet(new int[] { propId1, propId2, unIndexedPropId });
EntityReadOperations readOps = mock(EntityReadOperations.class);
when(readOps.nodeGetPropertyKeys(state, node)).thenReturn(defaultPropertyIds);
when(readOps.nodeGetProperty(state, node, propId1)).thenReturn("hi1");
when(readOps.nodeGetProperty(state, node, propId2)).thenReturn("hi2");
when(readOps.nodeGetProperty(state, node, unIndexedPropId)).thenReturn("hi3");
nodeSchemaMatcher = new NodeSchemaMatcher<>(readOps);
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class IndexTxStateUpdaterTest method setup.
@Before
public void setup() {
state = mock(KernelStatement.class);
txState = mock(TransactionState.class);
when(state.txState()).thenReturn(txState);
SchemaReadOperations schemaReadOps = mock(SchemaReadOperations.class);
when(schemaReadOps.indexesGetAll(state)).thenAnswer(x -> filter(GENERAL, indexes.iterator()));
when(schemaReadOps.uniqueIndexesGetAll(state)).thenAnswer(x -> filter(UNIQUE, indexes.iterator()));
when(schemaReadOps.indexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId1), indexes.iterator())));
when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId1), indexes.iterator())));
when(schemaReadOps.indexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId2), indexes.iterator())));
when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId2), indexes.iterator())));
PrimitiveIntSet labels = Primitive.intSet();
labels.add(labelId1);
labels.add(labelId2);
Cursor<NodeItem> nodeItemCursor = StubCursors.asNodeCursor(0, labels);
nodeItemCursor.next();
node = nodeItemCursor.get();
PrimitiveIntSet defaultPropertyIds = PrimitiveIntCollections.asSet(new int[] { propId1, propId2, propId3 });
EntityReadOperations readOps = mock(EntityReadOperations.class);
when(readOps.nodeGetPropertyKeys(state, node)).thenReturn(defaultPropertyIds);
when(readOps.nodeGetProperties(state, node)).thenAnswer(p -> StubCursors.asPropertyCursor(Property.property(propId1, "hi1"), Property.property(propId2, "hi2"), Property.property(propId3, "hi3")));
when(readOps.nodeGetProperty(state, node, propId1)).thenReturn("hi1");
when(readOps.nodeGetProperty(state, node, propId2)).thenReturn("hi2");
when(readOps.nodeGetProperty(state, node, propId3)).thenReturn("hi3");
indexTxUpdater = new IndexTxStateUpdater(schemaReadOps, readOps);
}
Aggregations