@Test public void testGetAsyncFromLDS() throws Exception { Parse.enableLocalDatastore(null); ParseUser user = mock(ParseUser.class); ParseQueryController queryController = mock(ParseQueryController.class); when(queryController.findAsync( any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)) ).thenReturn(Task.forResult(Collections.singletonList(user))); ParseCorePlugins.getInstance().registerQueryController(queryController); OfflineObjectStore<ParseUser> store = new OfflineObjectStore<>(ParseUser.class, PIN_NAME, null); ParseUser userAgain = ParseTaskUtils.wait(store.getAsync()); verify(queryController, times(1)) .findAsync(any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)); assertSame(user, userAgain); }
@Override public Task<T> getAsync() { 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(); } }); }
OfflineObjectStore implements ParseObjectStore<T> { @Override public Task<T> getAsync() { 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(); } }); } }
OfflineObjectStore implements ParseObjectStore<T> { @Override public Task<T> getAsync() { 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(); } }); } OfflineObjectStore(Class<T> clazz, String pinName, ParseObjectStore<T> legacy);  OfflineObjectStore(String className, String pinName, ParseObjectStore<T> legacy); }
OfflineObjectStore implements ParseObjectStore<T> { @Override public Task<T> getAsync() { 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(); } }); } OfflineObjectStore(Class<T> clazz, String pinName, ParseObjectStore<T> legacy);  OfflineObjectStore(String className, String pinName, ParseObjectStore<T> legacy); @Override Task<Void> setAsync(final T object); @Override Task<T> getAsync(); @Override Task<Boolean> existsAsync(); @Override Task<Void> deleteAsync(); }
OfflineObjectStore implements ParseObjectStore<T> { @Override public Task<T> getAsync() { 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(); } }); } OfflineObjectStore(Class<T> clazz, String pinName, ParseObjectStore<T> legacy);  OfflineObjectStore(String className, String pinName, ParseObjectStore<T> legacy); @Override Task<Void> setAsync(final T object); @Override Task<T> getAsync(); @Override Task<Boolean> existsAsync(); @Override Task<Void> deleteAsync();  }