@Override public Task<Boolean> existsAsync() { // We need to set `ignoreACLs` since we can't use ACLs without the current user. ParseQuery<T> query = ParseQuery.<T>getQuery(className) .fromPin(pinName) .ignoreACLs(); return query.countInBackground().onSuccessTask(new Continuation<Integer, Task<Boolean>>() { @Override public Task<Boolean> then(Task<Integer> task) { boolean exists = task.getResult() == 1; if (exists) { return Task.forResult(true); } return legacy.existsAsync(); } }); }
public static Task<List<EventuallyPin>> findAllPinned(Collection<String> excludeUUIDs) { ParseQuery<EventuallyPin> query = new ParseQuery<>(EventuallyPin.class) .fromPin(PIN_NAME) .ignoreACLs() .orderByAscending("time"); if (excludeUUIDs != null) { query.whereNotContainedIn("uuid", excludeUUIDs); } // We need pass in a null user because we don't want the query to fetch the current user // from LDS. return query.findInBackground().onSuccessTask(new Continuation<List<EventuallyPin>, Task<List<EventuallyPin>>>() { @Override public Task<List<EventuallyPin>> then(Task<List<EventuallyPin>> task) { final List<EventuallyPin> pins = task.getResult(); List<Task<Void>> tasks = new ArrayList<>(); for (EventuallyPin pin : pins) { ParseObject object = pin.getObject(); if (object != null) { tasks.add(object.fetchFromLocalDatastoreAsync().makeVoid()); } } return Task.whenAll(tasks).continueWithTask(new Continuation<Void, Task<List<EventuallyPin>>>() { @Override public Task<List<EventuallyPin>> then(Task<Void> task) { return Task.forResult(pins); } }); } }); }
@Override public Task<T> getAsync() { // We need to set `ignoreACLs` since we can't use ACLs without the current user. ParseQuery<T> query = ParseQuery.<T>getQuery(className) .fromPin(pinName) .ignoreACLs(); return query.findInBackground().onSuccessTask(new Continuation<List<T>, Task<T>>() { @Override public Task<T> then(Task<List<T>> task) { List<T> results = task.getResult(); if (results != null) { if (results.size() == 1) { return Task.forResult(results.get(0)); } else { return ParseObject.unpinAllInBackground(pinName).cast(); } } return Task.forResult(null); } }).onSuccessTask(new Continuation<T, Task<T>>() { @Override public Task<T> then(Task<T> task) { T ldsObject = task.getResult(); if (ldsObject != null) { return task; } return migrate(legacy, OfflineObjectStore.this).cast(); } }); }
@Test public void testFromPin() { ParseQuery<ParseObject> query = new ParseQuery<>("Test"); Parse.enableLocalDatastore(null); query.fromPin(); // We generate a state to verify the content of the builder ParseQuery.State state = query.getBuilder().build(); assertTrue(state.isFromLocalDatastore()); assertEquals(ParseObject.DEFAULT_PIN, state.pinName()); }
postParseQuery = ParseQuery.getQuery(Post.class); if (!NetworkConnectivityReceiver.isNetworkAvailable(getContext())) { postParseQuery.fromPin(featureId);
postParseQuery = ParseQuery.getQuery(Post.class); if (!NetworkConnectivityReceiver.isNetworkAvailable(getContext())) { postParseQuery.fromPin(eventId);
query.fromPin(LocalDataStore.EVENT_PIN);
query.fromPin(LocalDataStore.FEATURES_PIN);
postQuery.fromPin(LocalDataStore.POSTS_PIN);
query.fromPin(LocalDataStore.FEATURES_PIN);