use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class UniqueIndexSeekIT method lockNodeUsingUniqueIndexSeek.
private static void lockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, String nameProperty) throws KernelException {
try (Transaction transaction = database.beginTx()) {
KernelTransaction kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
TokenRead tokenRead = kernelTransaction.tokenRead();
Read dataRead = kernelTransaction.dataRead();
int propertyId = tokenRead.propertyKey(nameProperty);
IndexDescriptor indexReference = kernelTransaction.schemaRead().indexGetForName(CONSTRAINT_NAME);
try (NodeValueIndexCursor cursor = kernelTransaction.cursors().allocateNodeValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
dataRead.lockingNodeUniqueIndexSeek(indexReference, cursor, PropertyIndexQuery.ExactPredicate.exact(propertyId, "value"));
}
transaction.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class LuceneFulltextTestSupport method assertQueryFindsNodeIdsInOrder.
void assertQueryFindsNodeIdsInOrder(KernelTransaction ktx, String indexName, String query, long... ids) throws Exception {
IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
int num = 0;
float score = Float.MAX_VALUE;
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
while (cursor.next()) {
long nextId = cursor.nodeReference();
float nextScore = cursor.score();
assertThat(nextScore).isLessThanOrEqualTo(score);
score = nextScore;
assertEquals(ids[num], nextId, format("Result returned node id %d, expected %d", nextId, ids[num]));
num++;
}
assertEquals(ids.length, num, "Number of results differ from expected");
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class MultipleOpenCursorsTest method multipleIteratorsNestedInnerNewExists.
@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInnerNewExists(IndexCoordinator indexCoordinator) throws Exception {
indexCoordinator.init(db);
try (Transaction tx = db.beginTx()) {
// when
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExists(ktx)) {
List<Long> actual1 = new ArrayList<>();
while (cursor1.next()) {
actual1.add(cursor1.nodeReference());
try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExists(ktx)) {
List<Long> actual2 = asList(cursor2);
indexCoordinator.assertExistsResult(actual2);
}
}
// then
indexCoordinator.assertExistsResult(actual1);
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class MultipleOpenCursorsTest method multipleIteratorsNotNestedRange.
@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNotNestedRange(IndexCoordinator indexCoordinator) throws KernelException {
assumeTrue(indexCoordinator.supportRangeQuery());
indexCoordinator.init(db);
try (Transaction tx = db.beginTx()) {
// when
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeValueIndexCursor cursor1 = indexCoordinator.queryRange(ktx);
NodeValueIndexCursor cursor2 = indexCoordinator.queryRange(ktx)) {
List<Long> actual1 = asList(cursor1);
List<Long> actual2 = asList(cursor2);
// then
indexCoordinator.assertRangeResult(actual1);
indexCoordinator.assertRangeResult(actual2);
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class MultipleOpenCursorsTest method multipleIteratorsNestedInterleavedExists.
@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInterleavedExists(IndexCoordinator indexCoordinator) throws Exception {
indexCoordinator.init(db);
try (Transaction tx = db.beginTx()) {
// when
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExists(ktx)) {
List<Long> actual1 = new ArrayList<>();
try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExists(ktx)) {
List<Long> actual2 = new ArrayList<>();
// Interleave
exhaustInterleaved(cursor1, actual1, cursor2, actual2);
// then
indexCoordinator.assertExistsResult(actual1);
indexCoordinator.assertExistsResult(actual2);
}
}
tx.commit();
}
}
Aggregations