@@ -53,7 +53,7 @@ public class Query<T> {
53
53
54
54
native Object nativeFindUnique (long handle , long cursorHandle );
55
55
56
- native List nativeFind (long handle , long cursorHandle , long offset , long limit );
56
+ native List < T > nativeFind (long handle , long cursorHandle , long offset , long limit ) throws Exception ;
57
57
58
58
native long [] nativeFindIds (long handle , long cursorHandle , long offset , long limit );
59
59
@@ -95,7 +95,7 @@ native void nativeSetParameter(long handle, int entityId, int propertyId, @Nulla
95
95
private final QueryFilter <T > filter ;
96
96
private final Comparator <T > comparator ;
97
97
private final int queryAttempts ;
98
- private final int initialRetryBackOffInMs = 10 ;
98
+ private static final int INITIAL_RETRY_BACK_OFF_IN_MS = 10 ;
99
99
100
100
long handle ;
101
101
@@ -111,6 +111,10 @@ native void nativeSetParameter(long handle, int entityId, int propertyId, @Nulla
111
111
this .comparator = comparator ;
112
112
}
113
113
114
+ /**
115
+ * Explicitly call {@link #close()} instead.
116
+ */
117
+ @ SuppressWarnings ("deprecation" ) // finalize()
114
118
@ Override
115
119
protected void finalize () throws Throwable {
116
120
close ();
@@ -218,8 +222,8 @@ public List<T> find(final long offset, final long limit) {
218
222
ensureNoFilterNoComparator ();
219
223
return callInReadTx (new Callable <List <T >>() {
220
224
@ Override
221
- public List <T > call () {
222
- List entities = nativeFind (handle , cursorHandle (), offset , limit );
225
+ public List <T > call () throws Exception {
226
+ List < T > entities = nativeFind (handle , cursorHandle (), offset , limit );
223
227
resolveEagerRelations (entities );
224
228
return entities ;
225
229
}
@@ -230,7 +234,7 @@ public List<T> call() {
230
234
* Very efficient way to get just the IDs without creating any objects. IDs can later be used to lookup objects
231
235
* (lookups by ID are also very efficient in ObjectBox).
232
236
* <p>
233
- * Note: a filter set with {@link QueryBuilder#filter} will be silently ignored!
237
+ * Note: a filter set with {@link QueryBuilder#filter(QueryFilter) } will be silently ignored!
234
238
*/
235
239
@ Nonnull
236
240
public long [] findIds () {
@@ -240,7 +244,7 @@ public long[] findIds() {
240
244
/**
241
245
* Like {@link #findIds()} but with a offset/limit param, e.g. for pagination.
242
246
* <p>
243
- * Note: a filter set with {@link QueryBuilder#filter} will be silently ignored!
247
+ * Note: a filter set with {@link QueryBuilder#filter(QueryFilter) } will be silently ignored!
244
248
*/
245
249
@ Nonnull
246
250
public long [] findIds (final long offset , final long limit ) {
@@ -275,7 +279,7 @@ public PropertyQuery property(Property property) {
275
279
}
276
280
277
281
<R > R callInReadTx (Callable <R > callable ) {
278
- return store .callInReadTxWithRetry (callable , queryAttempts , initialRetryBackOffInMs , true );
282
+ return store .callInReadTxWithRetry (callable , queryAttempts , INITIAL_RETRY_BACK_OFF_IN_MS , true );
279
283
}
280
284
281
285
/**
@@ -326,37 +330,38 @@ public LazyList<T> findLazyCached() {
326
330
return new LazyList <>(box , findIds (), true );
327
331
}
328
332
329
- void resolveEagerRelations (List entities ) {
333
+ void resolveEagerRelations (List < T > entities ) {
330
334
if (eagerRelations != null ) {
331
335
int entityIndex = 0 ;
332
- for (Object entity : entities ) {
336
+ for (T entity : entities ) {
333
337
resolveEagerRelationForNonNullEagerRelations (entity , entityIndex );
334
338
entityIndex ++;
335
339
}
336
340
}
337
341
}
338
342
339
343
/** Note: no null check on eagerRelations! */
340
- void resolveEagerRelationForNonNullEagerRelations (@ Nonnull Object entity , int entityIndex ) {
344
+ void resolveEagerRelationForNonNullEagerRelations (@ Nonnull T entity , int entityIndex ) {
341
345
for (EagerRelation eagerRelation : eagerRelations ) {
342
346
if (eagerRelation .limit == 0 || entityIndex < eagerRelation .limit ) {
343
347
resolveEagerRelation (entity , eagerRelation );
344
348
}
345
349
}
346
350
}
347
351
348
- void resolveEagerRelation (@ Nullable Object entity ) {
352
+ void resolveEagerRelation (@ Nullable T entity ) {
349
353
if (eagerRelations != null && entity != null ) {
350
354
for (EagerRelation eagerRelation : eagerRelations ) {
351
355
resolveEagerRelation (entity , eagerRelation );
352
356
}
353
357
}
354
358
}
355
359
356
- void resolveEagerRelation (@ Nonnull Object entity , EagerRelation eagerRelation ) {
360
+ void resolveEagerRelation (@ Nonnull T entity , EagerRelation eagerRelation ) {
357
361
if (eagerRelations != null ) {
358
362
RelationInfo relationInfo = eagerRelation .relationInfo ;
359
363
if (relationInfo .toOneGetter != null ) {
364
+ //noinspection unchecked Can't know target entity type.
360
365
ToOne toOne = relationInfo .toOneGetter .getToOne (entity );
361
366
if (toOne != null ) {
362
367
toOne .getTarget ();
@@ -365,8 +370,10 @@ void resolveEagerRelation(@Nonnull Object entity, EagerRelation eagerRelation) {
365
370
if (relationInfo .toManyGetter == null ) {
366
371
throw new IllegalStateException ("Relation info without relation getter: " + relationInfo );
367
372
}
373
+ //noinspection unchecked Can't know target entity type.
368
374
List toMany = relationInfo .toManyGetter .getToMany (entity );
369
375
if (toMany != null ) {
376
+ //noinspection ResultOfMethodCallIgnored Triggers fetching target entities.
370
377
toMany .size ();
371
378
}
372
379
}
0 commit comments