GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — findIds: drop no-order requirement, add offset/limit variant · heyujava/objectbox-java@48aca68

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objectbox-java/src/main/java/io/objectbox/query
    • Query.java
  • tests/objectbox-java-test/src/test/java/io/objectbox/query
    • QueryTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎objectbox-java/src/main/java/io/objectbox/query/Query.java‎

Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/query/Query.java
+11-4Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,20 @@ public List<T> call() {
236236
*/
237237
@Nonnull
238238
public long[] findIds() {
239-
if (hasOrder) {
240-
throw new UnsupportedOperationException("This method is currently only available for unordered queries");
241-
}
239+
return findIds(0,0);
240+
}
241+
242+
/**
243+
* Like {@link #findIds()} but with a offset/limit param, e.g. for pagination.
244+
* <p>
245+
* Note: a filter set with {@link QueryBuilder#filter} will be silently ignored!
246+
*/
247+
@Nonnull
248+
public long[] findIds(final long offset, final long limit) {
242249
return box.internalCallWithReaderHandle(new CallWithHandle<long[]>() {
243250
@Override
244251
public long[] call(long cursorHandle) {
245-
return nativeFindIds(handle, cursorHandle, 0, 0);
252+
return nativeFindIds(handle, cursorHandle, offset, limit);
246253
}
247254
});
248255
}
Collapse file

‎tests/objectbox-java-test/src/test/java/io/objectbox/query/QueryTest.java‎

Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/query/QueryTest.java
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public void testRemove() {
458458
}
459459

460460
@Test
461-
public void testFindKeysUnordered() {
461+
public void testFindIds() {
462462
putTestEntitiesScalars();
463463
assertEquals(10, box.query().build().findIds().length);
464464

@@ -470,6 +470,21 @@ public void testFindKeysUnordered() {
470470
assertEquals(10, keys[2]);
471471
}
472472

473+
@Test
474+
public void testFindIdsWithOrder() {
475+
putTestEntitiesScalars();
476+
Query<TestEntity> query = box.query().orderDesc(TestEntity_.simpleInt).build();
477+
long[] ids = query.findIds();
478+
assertEquals(10, ids.length);
479+
assertEquals(10, ids[0]);
480+
assertEquals(1, ids[9]);
481+
482+
ids = query.findIds(3, 2);
483+
assertEquals(2, ids.length);
484+
assertEquals(7, ids[0]);
485+
assertEquals(6, ids[1]);
486+
}
487+
473488
@Test
474489
public void testOr() {
475490
putTestEntitiesScalars();

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.