use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class Operations method enforceNodeKeyConstraint.
private void enforceNodeKeyConstraint(SchemaDescriptor 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.validateNodeKeyConstraint(cursor, nodeCursor, propertyCursor, schema.asLabelSchemaDescriptor(), token);
}
} else {
try (var cursor = cursors.allocateFullAccessNodeCursor(ktx.cursorContext())) {
allStoreHolder.allNodesScan(cursor);
constraintSemantics.validateNodeKeyConstraint(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 Operations method enforceRelationshipPropertyExistenceConstraint.
private void enforceRelationshipPropertyExistenceConstraint(RelationTypeSchemaDescriptor schema) throws KernelException {
var index = allStoreHolder.findUsableTokenIndex(RELATIONSHIP);
if (index != IndexDescriptor.NO_INDEX) {
try (var fullAccessIndexCursor = cursors.allocateFullAccessRelationshipTypeIndexCursor();
var fullAccessCursor = cursors.allocateFullAccessRelationshipScanCursor(ktx.cursorContext())) {
var session = allStoreHolder.tokenReadSession(index);
allStoreHolder.relationshipTypeScan(session, fullAccessIndexCursor, unconstrained(), new TokenPredicate(schema.getRelTypeId()));
constraintSemantics.validateRelationshipPropertyExistenceConstraint(fullAccessIndexCursor, fullAccessCursor, propertyCursor, schema, token);
}
} else {
// fallback to all relationship scan
try (var fullAccessCursor = cursors.allocateFullAccessRelationshipScanCursor(ktx.cursorContext())) {
allStoreHolder.allRelationshipsScan(fullAccessCursor);
constraintSemantics.validateRelationshipPropertyExistenceConstraint(new FilteringRelationshipScanCursorWrapper(fullAccessCursor, CursorPredicates.hasType(schema.getRelTypeId())), propertyCursor, schema, token);
}
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class DefaultTokenIndexReaderTest method shouldFindMultipleWithProgressorAscending.
@Test
void shouldFindMultipleWithProgressorAscending() {
// WHEN
var reader = new DefaultTokenIndexReader(index);
SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
reader.query(tokenClient, IndexQueryConstraints.constrained(IndexOrder.ASCENDING, false), 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 RelationshipTypeIndexIT method assertContainIds.
private void assertContainIds(List<Long> expectedIds) throws IndexNotFoundKernelException {
int relationshipTypeId = getRelationshipTypeId();
IndexProxy indexProxy = getIndexProxy();
List<Long> actualIds = new ArrayList<>();
try (TokenIndexReader reader = indexProxy.newTokenReader()) {
SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
reader.query(tokenClient, unconstrained(), new TokenPredicate(relationshipTypeId), CursorContext.NULL);
while (tokenClient.next()) {
actualIds.add(tokenClient.reference);
}
}
expectedIds.sort(Long::compareTo);
actualIds.sort(Long::compareTo);
assertThat(actualIds).as("contains expected relationships").isEqualTo(expectedIds);
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class KernelAPIParallelLabelScanStressIT method labelScan.
private Runnable labelScan(Read read, NodeLabelIndexCursor cursor, IndexDescriptor index, int label) {
return throwing(() -> {
var tokenReadSession = read.tokenReadSession(index);
read.nodeLabelScan(tokenReadSession, cursor, unconstrained(), new TokenPredicate(label));
int n = 0;
while (cursor.next()) {
n++;
}
assertEquals(N_NODES, n, "correct number of nodes");
});
}
Aggregations