31
31
import io .objectbox .BoxStore ;
32
32
import io .objectbox .InternalAccess ;
33
33
import io .objectbox .Property ;
34
+ import io .objectbox .exception .NonUniqueResultException ;
34
35
import io .objectbox .reactive .DataObserver ;
35
36
import io .objectbox .reactive .DataSubscriptionList ;
36
37
import io .objectbox .reactive .SubscriptionBuilder ;
37
38
import io .objectbox .relation .RelationInfo ;
38
39
import io .objectbox .relation .ToOne ;
39
40
40
41
/**
41
- * A repeatable Query returning the latest matching Objects .
42
+ * A repeatable Query returning the latest matching objects .
42
43
* <p>
43
- * Use {@link #find()} or related methods to fetch the latest results from the BoxStore.
44
+ * Use {@link #find()} or related methods to fetch the latest results from the {@link BoxStore} .
44
45
* <p>
45
46
* Use {@link #property(Property)} to only return values or an aggregate of a single Property.
46
47
* <p>
@@ -195,7 +196,12 @@ long cursorHandle() {
195
196
}
196
197
197
198
/**
198
- * Find the first Object matching the query.
199
+ * Finds the first object matching this query.
200
+ * <p>
201
+ * Note: if no {@link QueryBuilder#order} conditions are present, which object is the first one might be arbitrary
202
+ * (sometimes the one with the lowest ID, but never guaranteed to be).
203
+ *
204
+ * @return The first object if there are matches. {@code null} if no object matches.
199
205
*/
200
206
@ Nullable
201
207
public T findFirst () {
@@ -228,9 +234,10 @@ private void ensureNoComparator() {
228
234
}
229
235
230
236
/**
231
- * If there is a single matching object, returns it. If there is more than one matching object,
232
- * throws {@link io.objectbox.exception.NonUniqueResultException NonUniqueResultException}.
233
- * If there are no matches returns null.
237
+ * Finds the only object matching this query.
238
+ *
239
+ * @return The object if a single object matches. {@code null} if no object matches. Throws
240
+ * {@link NonUniqueResultException} if there are multiple objects matching the query.
234
241
*/
235
242
@ Nullable
236
243
public T findUnique () {
@@ -244,7 +251,12 @@ public T findUnique() {
244
251
}
245
252
246
253
/**
247
- * Find all Objects matching the query.
254
+ * Finds objects matching the query.
255
+ * <p>
256
+ * Note: if no {@link QueryBuilder#order} conditions are present, the order is arbitrary (sometimes ordered by ID,
257
+ * but never guaranteed to).
258
+ *
259
+ * @return A list of matching objects. An empty list if no object matches.
248
260
*/
249
261
@ Nonnull
250
262
public List <T > find () {
@@ -268,8 +280,12 @@ public List<T> find() {
268
280
}
269
281
270
282
/**
271
- * Find all Objects matching the query, skipping the first offset results and returning at most limit results.
272
- * Use this for pagination.
283
+ * Like {@link #find()}, but can skip and limit results.
284
+ * <p>
285
+ * Use to get a slice of the whole result, e.g. for "result paging".
286
+ *
287
+ * @param offset If greater than 0, skips this many results.
288
+ * @param limit If greater than 0, returns at most this many results.
273
289
*/
274
290
@ Nonnull
275
291
public List <T > find (final long offset , final long limit ) {
@@ -282,46 +298,59 @@ public List<T> find(final long offset, final long limit) {
282
298
}
283
299
284
300
/**
285
- * Returns the ID of the first matching object. If there are no results returns 0 .
301
+ * Like {@link #findFirst()}, but returns just the ID of the object .
286
302
* <p>
287
- * Like {@link #findFirst()}, but more efficient as no object is created.
303
+ * This is more efficient as no object is created.
288
304
* <p>
289
305
* Ignores any {@link QueryBuilder#filter(QueryFilter) query filter}.
306
+ *
307
+ * @return The ID of the first matching object. {@code 0} if no object matches.
290
308
*/
291
309
public long findFirstId () {
292
310
checkOpen ();
293
311
return box .internalCallWithReaderHandle (cursorHandle -> nativeFindFirstId (handle , cursorHandle ));
294
312
}
295
313
296
314
/**
297
- * If there is a single matching object, returns its ID. If there is more than one matching object,
298
- * throws {@link io.objectbox.exception.NonUniqueResultException NonUniqueResultException}.
299
- * If there are no matches returns 0.
315
+ * Like {@link #findUnique()}, but returns just the ID of the object.
300
316
* <p>
301
- * Like {@link #findUnique()}, but more efficient as no object is created.
317
+ * This is more efficient as no object is created.
302
318
* <p>
303
319
* Ignores any {@link QueryBuilder#filter(QueryFilter) query filter}.
320
+ *
321
+ * @return The ID of the object, if a single object matches. {@code 0} if no object matches. Throws
322
+ * {@link NonUniqueResultException} if there are multiple objects matching the query.
304
323
*/
305
324
public long findUniqueId () {
306
325
checkOpen ();
307
326
return box .internalCallWithReaderHandle (cursorHandle -> nativeFindUniqueId (handle , cursorHandle ));
308
327
}
309
328
310
329
/**
311
- * Very efficient way to get just the IDs without creating any objects. IDs can later be used to lookup objects
312
- * (lookups by ID are also very efficient in ObjectBox).
330
+ * Like {@link #find()}, but returns just the IDs of the objects.
331
+ * <p>
332
+ * IDs can later be used to {@link Box#get} objects.
333
+ * <p>
334
+ * This is very efficient as no objects are created.
313
335
* <p>
314
336
* Note: a filter set with {@link QueryBuilder#filter(QueryFilter)} will be silently ignored!
337
+ *
338
+ * @return An array of IDs of matching objects. An empty array if no objects match.
315
339
*/
316
340
@ Nonnull
317
341
public long [] findIds () {
318
342
return findIds (0 , 0 );
319
343
}
320
344
321
345
/**
322
- * Like {@link #findIds()} but with a offset/limit param, e.g. for pagination.
346
+ * Like {@link #findIds()}, but can skip and limit results.
347
+ * <p>
348
+ * Use to get a slice of the whole result, e.g. for "result paging".
323
349
* <p>
324
350
* Note: a filter set with {@link QueryBuilder#filter(QueryFilter)} will be silently ignored!
351
+ *
352
+ * @param offset If greater than 0, skips this many results.
353
+ * @param limit If greater than 0, returns at most this many results.
325
354
*/
326
355
@ Nonnull
327
356
public long [] findIds (final long offset , final long limit ) {
0 commit comments