use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldNotFindNodeWithRemovedLabelInLabelScan.
@Test
void shouldNotFindNodeWithRemovedLabelInLabelScan() throws Exception {
// Given
Node node = createNode("label");
try (KernelTransaction tx = beginTransaction();
NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
// when
tx.dataWrite().nodeRemoveLabel(node.node, node.labels[0]);
tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(node.labels[0]));
// then
assertFalse(cursor.next());
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldFindSwappedNodeInLabelScan.
@Test
void shouldFindSwappedNodeInLabelScan() throws Exception {
// Given
Node node1 = createNode("label");
Node node2 = createNode();
try (KernelTransaction tx = beginTransaction();
NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
// when
tx.dataWrite().nodeRemoveLabel(node1.node, node1.labels[0]);
tx.dataWrite().nodeAddLabel(node2.node, node1.labels[0]);
tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(node1.labels[0]));
// then
assertTrue(cursor.next());
assertEquals(node2.node, cursor.nodeReference());
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class Operations method enforceNodePropertyExistenceConstraint.
private void enforceNodePropertyExistenceConstraint(LabelSchemaDescriptor schema) throws KernelException {
IndexDescriptor index = allStoreHolder.findUsableTokenIndex(NODE);
if (index != IndexDescriptor.NO_INDEX) {
try (var cursor = cursors.allocateFullAccessNodeLabelIndexCursor(ktx.cursorContext())) {
var session = allStoreHolder.tokenReadSession(index);
allStoreHolder.nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(schema.getLabelId()));
constraintSemantics.validateNodePropertyExistenceConstraint(cursor, nodeCursor, propertyCursor, schema.asLabelSchemaDescriptor(), token);
}
} else {
try (var cursor = cursors.allocateFullAccessNodeCursor(ktx.cursorContext())) {
allStoreHolder.allNodesScan(cursor);
constraintSemantics.validateNodePropertyExistenceConstraint(new FilteringNodeCursorWrapper(cursor, CursorPredicates.hasLabel(schema.getLabelId())), propertyCursor, schema.asLabelSchemaDescriptor(), token);
}
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class DefaultTokenIndexReaderTest method shouldFindMultipleEntitiesInEachRange.
@Test
void shouldFindMultipleEntitiesInEachRange() {
// WHEN
var reader = new DefaultTokenIndexReader(index);
SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
reader.query(tokenClient, unconstrained(), new TokenPredicate(LABEL_ID), NULL);
// THEN
assertArrayEquals(expected, asArray(tokenClient));
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class DefaultTokenIndexReaderTest method shouldFindMultipleWithProgressorDescending.
@Test
void shouldFindMultipleWithProgressorDescending() {
// WHEN
var reader = new DefaultTokenIndexReader(index);
SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
reader.query(tokenClient, IndexQueryConstraints.constrained(IndexOrder.DESCENDING, false), new TokenPredicate(LABEL_ID), NULL);
// THEN
ArrayUtils.reverse(expected);
assertArrayEquals(expected, asArray(tokenClient));
}
Aggregations