File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
objectbox-java/src/main/java/io/objectbox/query
tests/objectbox-java-test/src/test/java/io/objectbox/query Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments