Skip to content

Commit 63c6f70

Browse files
Query: add missing type parameters, fix docs, resolve warnings.
1 parent 29c60a7 commit 63c6f70

File tree

1 file changed

+19
-12
lines changed
  • objectbox-java/src/main/java/io/objectbox/query

1 file changed

+19
-12
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Query<T> {
5353

5454
native Object nativeFindUnique(long handle, long cursorHandle);
5555

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;
5757

5858
native long[] nativeFindIds(long handle, long cursorHandle, long offset, long limit);
5959

@@ -95,7 +95,7 @@ native void nativeSetParameter(long handle, int entityId, int propertyId, @Nulla
9595
private final QueryFilter<T> filter;
9696
private final Comparator<T> comparator;
9797
private final int queryAttempts;
98-
private final int initialRetryBackOffInMs = 10;
98+
private static final int INITIAL_RETRY_BACK_OFF_IN_MS = 10;
9999

100100
long handle;
101101

@@ -111,6 +111,10 @@ native void nativeSetParameter(long handle, int entityId, int propertyId, @Nulla
111111
this.comparator = comparator;
112112
}
113113

114+
/**
115+
* Explicitly call {@link #close()} instead.
116+
*/
117+
@SuppressWarnings("deprecation") // finalize()
114118
@Override
115119
protected void finalize() throws Throwable {
116120
close();
@@ -218,8 +222,8 @@ public List<T> find(final long offset, final long limit) {
218222
ensureNoFilterNoComparator();
219223
return callInReadTx(new Callable<List<T>>() {
220224
@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);
223227
resolveEagerRelations(entities);
224228
return entities;
225229
}
@@ -230,7 +234,7 @@ public List<T> call() {
230234
* Very efficient way to get just the IDs without creating any objects. IDs can later be used to lookup objects
231235
* (lookups by ID are also very efficient in ObjectBox).
232236
* <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!
234238
*/
235239
@Nonnull
236240
public long[] findIds() {
@@ -240,7 +244,7 @@ public long[] findIds() {
240244
/**
241245
* Like {@link #findIds()} but with a offset/limit param, e.g. for pagination.
242246
* <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!
244248
*/
245249
@Nonnull
246250
public long[] findIds(final long offset, final long limit) {
@@ -275,7 +279,7 @@ public PropertyQuery property(Property property) {
275279
}
276280

277281
<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);
279283
}
280284

281285
/**
@@ -326,37 +330,38 @@ public LazyList<T> findLazyCached() {
326330
return new LazyList<>(box, findIds(), true);
327331
}
328332

329-
void resolveEagerRelations(List entities) {
333+
void resolveEagerRelations(List<T> entities) {
330334
if (eagerRelations != null) {
331335
int entityIndex = 0;
332-
for (Object entity : entities) {
336+
for (T entity : entities) {
333337
resolveEagerRelationForNonNullEagerRelations(entity, entityIndex);
334338
entityIndex++;
335339
}
336340
}
337341
}
338342

339343
/** Note: no null check on eagerRelations! */
340-
void resolveEagerRelationForNonNullEagerRelations(@Nonnull Object entity, int entityIndex) {
344+
void resolveEagerRelationForNonNullEagerRelations(@Nonnull T entity, int entityIndex) {
341345
for (EagerRelation eagerRelation : eagerRelations) {
342346
if (eagerRelation.limit == 0 || entityIndex < eagerRelation.limit) {
343347
resolveEagerRelation(entity, eagerRelation);
344348
}
345349
}
346350
}
347351

348-
void resolveEagerRelation(@Nullable Object entity) {
352+
void resolveEagerRelation(@Nullable T entity) {
349353
if (eagerRelations != null && entity != null) {
350354
for (EagerRelation eagerRelation : eagerRelations) {
351355
resolveEagerRelation(entity, eagerRelation);
352356
}
353357
}
354358
}
355359

356-
void resolveEagerRelation(@Nonnull Object entity, EagerRelation eagerRelation) {
360+
void resolveEagerRelation(@Nonnull T entity, EagerRelation eagerRelation) {
357361
if (eagerRelations != null) {
358362
RelationInfo relationInfo = eagerRelation.relationInfo;
359363
if (relationInfo.toOneGetter != null) {
364+
//noinspection unchecked Can't know target entity type.
360365
ToOne toOne = relationInfo.toOneGetter.getToOne(entity);
361366
if (toOne != null) {
362367
toOne.getTarget();
@@ -365,8 +370,10 @@ void resolveEagerRelation(@Nonnull Object entity, EagerRelation eagerRelation) {
365370
if (relationInfo.toManyGetter == null) {
366371
throw new IllegalStateException("Relation info without relation getter: " + relationInfo);
367372
}
373+
//noinspection unchecked Can't know target entity type.
368374
List toMany = relationInfo.toManyGetter.getToMany(entity);
369375
if (toMany != null) {
376+
//noinspection ResultOfMethodCallIgnored Triggers fetching target entities.
370377
toMany.size();
371378
}
372379
}

0 commit comments

Comments
 (0)