/** * Runs a ParseQuery against the store's contents. * * @return The objects that match the query's constraints. */ /* package for OfflineQueryLogic */ <T extends ParseObject> Task<List<T>> findAsync( ParseQuery.State<T> query, ParseUser user, ParsePin pin, ParseSQLiteDatabase db) { return findAsync(query, user, pin, false, db); }
@Override public Task<Boolean> matchesAsync(final T object, ParseSQLiteDatabase db) { /* * As an optimization, we do this lazily. Then we may not have to do it at all, if this part * of the query gets short-circuited. */ if (subQueryResults == null) { //TODO (grantland): We need to pass through the original pin we were limiting the parent // query on. subQueryResults = store.findAsync(subQuery, user, null, db); } return subQueryResults.onSuccess(new Continuation<List<T>, Boolean>() { @Override public Boolean then(Task<List<T>> task) throws ParseException { return matches(object, task.getResult()); } }); }
private Task<ParsePin> getParsePin(final String name, ParseSQLiteDatabase db) { ParseQuery.State<ParsePin> query = new ParseQuery.State.Builder<>(ParsePin.class) .whereEqualTo(ParsePin.KEY_NAME, name) .build(); /* We need to call directly to the OfflineStore since we don't want/need a user to query for * ParsePins */ return findAsync(query, null, null, db).onSuccess(new Continuation<List<ParsePin>, ParsePin>() { @Override public ParsePin then(Task<List<ParsePin>> task) { ParsePin pin = null; if (task.getResult() != null && task.getResult().size() > 0) { pin = task.getResult().get(0); } //TODO (grantland): What do we do if there are more than 1 result? if (pin == null) { pin = ParseObject.create(ParsePin.class); pin.setName(name); } return pin; } }); }