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