@@ -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
@@ -90,29 +90,31 @@ native void nativeSetParameter(long handle, int entityId, int propertyId, @Nulla
9090
9191 final Box <T > box ;
9292 private final BoxStore store ;
93- private final boolean hasOrder ;
9493 private final QueryPublisher <T > publisher ;
9594 private final List <EagerRelation > eagerRelations ;
9695 private final QueryFilter <T > filter ;
9796 private final Comparator <T > comparator ;
9897 private final int queryAttempts ;
99- private final int initialRetryBackOffInMs = 10 ;
98+ private static final int INITIAL_RETRY_BACK_OFF_IN_MS = 10 ;
10099
101100 long handle ;
102101
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 ,
104103 Comparator <T > comparator ) {
105104 this .box = box ;
106105 store = box .getStore ();
107106 queryAttempts = store .internalQueryAttempts ();
108107 handle = queryHandle ;
109- this .hasOrder = hasOrder ;
110108 publisher = new QueryPublisher <>(this , box );
111109 this .eagerRelations = eagerRelations ;
112110 this .filter = filter ;
113111 this .comparator = comparator ;
114112 }
115113
114+ /**
115+ * Explicitly call {@link #close()} instead.
116+ */
117+ @ SuppressWarnings ("deprecation" ) // finalize()
116118 @ Override
117119 protected void finalize () throws Throwable {
118120 close ();
@@ -220,8 +222,8 @@ public List<T> find(final long offset, final long limit) {
220222 ensureNoFilterNoComparator ();
221223 return callInReadTx (new Callable <List <T >>() {
222224 @ 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 );
225227 resolveEagerRelations (entities );
226228 return entities ;
227229 }
@@ -232,7 +234,7 @@ public List<T> call() {
232234 * Very efficient way to get just the IDs without creating any objects. IDs can later be used to lookup objects
233235 * (lookups by ID are also very efficient in ObjectBox).
234236 * <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!
236238 */
237239 @ Nonnull
238240 public long [] findIds () {
@@ -242,7 +244,7 @@ public long[] findIds() {
242244 /**
243245 * Like {@link #findIds()} but with a offset/limit param, e.g. for pagination.
244246 * <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!
246248 */
247249 @ Nonnull
248250 public long [] findIds (final long offset , final long limit ) {
@@ -277,7 +279,7 @@ public PropertyQuery property(Property property) {
277279 }
278280
279281 <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 );
281283 }
282284
283285 /**
@@ -328,37 +330,38 @@ public LazyList<T> findLazyCached() {
328330 return new LazyList <>(box , findIds (), true );
329331 }
330332
331- void resolveEagerRelations (List entities ) {
333+ void resolveEagerRelations (List < T > entities ) {
332334 if (eagerRelations != null ) {
333335 int entityIndex = 0 ;
334- for (Object entity : entities ) {
336+ for (T entity : entities ) {
335337 resolveEagerRelationForNonNullEagerRelations (entity , entityIndex );
336338 entityIndex ++;
337339 }
338340 }
339341 }
340342
341343 /** Note: no null check on eagerRelations! */
342- void resolveEagerRelationForNonNullEagerRelations (@ Nonnull Object entity , int entityIndex ) {
344+ void resolveEagerRelationForNonNullEagerRelations (@ Nonnull T entity , int entityIndex ) {
343345 for (EagerRelation eagerRelation : eagerRelations ) {
344346 if (eagerRelation .limit == 0 || entityIndex < eagerRelation .limit ) {
345347 resolveEagerRelation (entity , eagerRelation );
346348 }
347349 }
348350 }
349351
350- void resolveEagerRelation (@ Nullable Object entity ) {
352+ void resolveEagerRelation (@ Nullable T entity ) {
351353 if (eagerRelations != null && entity != null ) {
352354 for (EagerRelation eagerRelation : eagerRelations ) {
353355 resolveEagerRelation (entity , eagerRelation );
354356 }
355357 }
356358 }
357359
358- void resolveEagerRelation (@ Nonnull Object entity , EagerRelation eagerRelation ) {
360+ void resolveEagerRelation (@ Nonnull T entity , EagerRelation eagerRelation ) {
359361 if (eagerRelations != null ) {
360362 RelationInfo relationInfo = eagerRelation .relationInfo ;
361363 if (relationInfo .toOneGetter != null ) {
364+ //noinspection unchecked Can't know target entity type.
362365 ToOne toOne = relationInfo .toOneGetter .getToOne (entity );
363366 if (toOne != null ) {
364367 toOne .getTarget ();
@@ -367,8 +370,10 @@ void resolveEagerRelation(@Nonnull Object entity, EagerRelation eagerRelation) {
367370 if (relationInfo .toManyGetter == null ) {
368371 throw new IllegalStateException ("Relation info without relation getter: " + relationInfo );
369372 }
373+ //noinspection unchecked Can't know target entity type.
370374 List toMany = relationInfo .toManyGetter .getToMany (entity );
371375 if (toMany != null ) {
376+ //noinspection ResultOfMethodCallIgnored Triggers fetching target entities.
372377 toMany .size ();
373378 }
374379 }
0 commit comments