@Test public void testLimit() { ParseQuery<ParseObject> query = new ParseQuery<>("Test"); query.setLimit(5); assertEquals(5, query.getLimit()); }
/** * Override this method to manually paginate the provided {@code ParseQuery}. By default, this * method will set the {@code limit} value to {@link #getObjectsPerPage()} and the {@code skip} * value to {@link #getObjectsPerPage()} * {@code page}. * <p/> * Overriding this method will not be necessary, in most cases. * * @param page the page number of results to fetch from Parse. * @param query the {@link ParseQuery} used to fetch items from Parse. This query will be mutated and * used in its mutated form. */ protected void setPageOnQuery(int page, ParseQuery<T> query) { query.setLimit(objectsPerPage + 1); query.setSkip(page * objectsPerPage); }
@Test public void testMultipleQueriesWithInflightChanges() throws ParseException { Parse.enableLocalDatastore(null); TestQueryController controller = new TestQueryController(); TaskCompletionSource<Void> tcs = new TaskCompletionSource<>(); controller.await(tcs.getTask()); ParseQuery<ParseObject> query = ParseQuery.getQuery("TestObject"); query.setUser(new ParseUser()); ParseCorePlugins.getInstance().registerQueryController(controller); List<Task<Void>> tasks = Arrays.asList( query.fromNetwork().findInBackground().makeVoid(), query.fromLocalDatastore().findInBackground().makeVoid(), query.setLimit(10).findInBackground().makeVoid(), query.whereEqualTo("key", "value").countInBackground().makeVoid()); assertTrue(query.isRunning()); tcs.trySetResult(null); ParseTaskUtils.wait(Task.whenAll(tasks)); assertFalse(query.isRunning()); }
public void updateLocation(){ final ParseGeoPoint userLocation = new ParseGeoPoint(location.getLatitude(), location.getLongitude()); ParseQuery<ParseObject> query = ParseQuery.getQuery("Requests"); query.whereDoesNotExist("driverUsername"); query.whereNear("requesterLocation", userLocation); query.setLimit(10); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> objects, ParseException e) { if ( e == null){ if(objects.size() > 0){ listViewContent.clear(); usernames.clear(); latitudes.clear(); longitudes.clear(); for (ParseObject object : objects){ Double distanceInMiles = userLocation.distanceInMilesTo((ParseGeoPoint) object.get("requesterLocation")); Double distaneOneDP = (double) Math.round(distanceInMiles *10) / 10; listViewContent.add(String.valueOf(distaneOneDP)+ " miles"); usernames.add(object.getString("requesterUsername")); latitudes.add(object.getParseGeoPoint("requesterLocation").getLatitude()); longitudes.add(object.getParseGeoPoint("requesterLocation").getLongitude()); } arrayAdapter.notifyDataSetChanged(); } } } }); } //restart the location updates on phone wake
/** * Returns a new instance of {@link ParseQuery} to be used to load the next page of results. * * Its limit should be one more than {@code pageSize} so that {@code hasNextPage} can be * determined. * * @param page The page the query should load. * @return a new instance of {@link ParseQuery}. */ protected ParseQuery<T> createQuery(int page) { ParseQuery<T> query = new ParseQuery<>(getQuery()); query.setSkip(getPageSize() * page); // Limit is pageSize + 1 so we can detect if there are more pages query.setLimit(getPageSize() + 1); return query; }
/** * Limit 10000 by skip */ @NonNull @CheckReturnValue public static <R extends ParseObject> Observable<R> all(@NonNull final ParseQuery<R> query, int count) { final int limit = 1000; // limit limitation query.setSkip(0); query.setLimit(limit); Observable<R> find = find(query); for (int i = limit; i < count; i+= limit) { if (i >= 10000) break; // skip limitation query.setSkip(i); query.setLimit(limit); find.concatWith(find(query)); } return find.distinct(o -> o.getObjectId()); }
@Test public void testParseObservableAllNextAfterCompleted() { List<ParseUser> users = mocker(ParseUser.class).when(user -> user.getObjectId()).thenReturn(user -> String.valueOf(user.hashCode())).asList(3); rx.parse2.ParseObservable.all(mocker(ParseQuery.class) .when(query -> query.countInBackground()).thenReturn(query -> Task.forResult(users.size())) .when(query -> query.findInBackground()).thenReturn(query -> Task.forResult(users)) .when(query -> query.setSkip(any(int.class))).thenReturn(query -> null) .when(query -> query.setLimit(any(int.class))).thenReturn(query -> null).mock()) //.doOnNext(user -> System.out.println("" + ((ParseUser) user).getObjectId()))) .test() .assertNoErrors() //.assertValue(check(l -> assertThat(l).isEqualTo(users))) .assertComplete(); }
@Test public void testParseObservableAllForMass() { // FIXME: how mockito to make mass mocks? List<ParseUser> users = Observable.range(1, 1001) .map(i -> mocker(ParseUser.class).when(user -> user.getObjectId()).thenReturn(user -> "" + i + user.hashCode()).mock()) .toList() .blockingGet(); rx.parse2.ParseObservable.all(mocker(ParseQuery.class) .when(query -> query.countInBackground()).thenReturn(query -> Task.forResult(users.size())) .when(query -> query.findInBackground()).thenReturn(query -> Task.forResult(users)) .when(query -> query.setSkip(any(int.class))).thenReturn(query -> null) .when(query -> query.setLimit(any(int.class))).thenReturn(query -> null).mock()) .test() .assertNoErrors() //.assertValue(check(l -> assertThat(l).isEqualTo(users))) .assertComplete(); }