use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class TransactionImpl method allNodesWithLabel.
private ResourceIterator<Node> allNodesWithLabel(final Label myLabel) {
KernelTransaction ktx = kernelTransaction();
int labelId = ktx.tokenRead().nodeLabel(myLabel.name());
if (labelId == TokenRead.NO_TOKEN) {
return emptyResourceIterator();
}
var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.NODE));
if (index != IndexDescriptor.NO_INDEX) {
try {
var session = ktx.dataRead().tokenReadSession(index);
var cursor = ktx.cursors().allocateNodeLabelIndexCursor(ktx.cursorContext());
ktx.dataRead().nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(labelId));
return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
} catch (KernelException e) {
// ignore, fallback to all node scan
}
}
return allNodesByLabelWithoutIndex(ktx, labelId);
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class TokenIndexAccessorTest method assertReaderFindsExpected.
private static void assertReaderFindsExpected(TokenIndexReader reader, IndexOrder indexOrder, long tokenId, LongList expectedIds, ThrowingConsumer<TokenIndexReader, Exception> innerCalling) throws Exception {
if (indexOrder.equals(IndexOrder.DESCENDING)) {
expectedIds = expectedIds.toReversed();
}
try (CollectingEntityTokenClient collectingEntityTokenClient = new CollectingEntityTokenClient(tokenId)) {
IndexQueryConstraints constraint = IndexQueryConstraints.constrained(indexOrder, false);
TokenPredicate query = new TokenPredicate((int) tokenId);
reader.query(collectingEntityTokenClient, constraint, query, NULL);
// Then
int count = 0;
while (collectingEntityTokenClient.next()) {
innerCalling.accept(reader);
count++;
}
assertThat(count).isEqualTo(expectedIds.size());
assertThat(collectingEntityTokenClient.actualIds).isEqualTo(expectedIds);
}
}
Aggregations