use of org.neo4j.collection.primitive.PrimitiveIntSet 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.collection.primitive.PrimitiveIntSet 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.collection.primitive.PrimitiveIntSet 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);
}
use of org.neo4j.collection.primitive.PrimitiveIntSet in project neo4j by neo4j.
the class KernelIT method transactionStateShouldReflectRemovingLabelImmediately.
@Test
public void transactionStateShouldReflectRemovingLabelImmediately() throws Exception {
// GIVEN
Transaction tx = db.beginTx();
Statement statement = statementContextSupplier.get();
Node node = db.createNode();
int labelId1 = statement.tokenWriteOperations().labelGetOrCreateForName("labello1");
int labelId2 = statement.tokenWriteOperations().labelGetOrCreateForName("labello2");
statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId1);
statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId2);
statement.close();
tx.success();
tx.close();
tx = db.beginTx();
statement = statementContextSupplier.get();
// WHEN
statement.dataWriteOperations().nodeRemoveLabel(node.getId(), labelId2);
// THEN
PrimitiveIntSet labels = PrimitiveIntCollections.asSet(statement.readOperations().nodeGetLabels(node.getId()));
assertFalse(statement.readOperations().nodeHasLabel(node.getId(), labelId2));
assertEquals(PrimitiveIntCollections.asSet(new int[] { labelId1 }), labels);
statement.close();
tx.success();
tx.close();
}
Aggregations