Skip to content

Commit ec6256f

Browse files
committed
Merge pull request #76 from ParsePlatform/wangmengyan.fix_ParseQueryAdapter_in_LDS_mode
Fix ParseQueryAdapter in LDS mode
2 parents 38c6f2e + 5a3b14d commit ec6256f

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2014, Parse, LLC. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Parse.
7+
*
8+
* As with any software that integrates with the Parse platform, your use of
9+
* this software is subject to the Parse Terms of Service
10+
* [https://www.parse.com/about/terms]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*
20+
*/
21+
22+
package com.parse;
23+
24+
public class ParseQueryAdapterOfflineEnabledTest extends ParseQueryAdapterTest {
25+
26+
@Override
27+
public void setUp() throws Exception {
28+
super.setUp();
29+
Parse.enableLocalDatastore(null);
30+
}
31+
32+
@Override
33+
public void tearDown() throws Exception {
34+
Parse.disableLocalDatastore();
35+
super.tearDown();
36+
}
37+
38+
@Override
39+
public void testLoadObjectsWithCacheThenNetworkQueryAndPagination() throws Exception {
40+
// Do nothing, there is no cache policy when LDS is enabled.
41+
}
42+
}

ParseLoginUI/src/main/java/com/parse/ParseQueryAdapter.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public static interface OnQueryLoadListener<T extends ParseObject> {
144144

145145
private List<T> objects = new ArrayList<>();
146146

147-
private Set<ParseQuery> runningQueries = Collections.newSetFromMap(new ConcurrentHashMap<ParseQuery, Boolean>());
147+
private Set<ParseQuery> runningQueries =
148+
Collections.newSetFromMap(new ConcurrentHashMap<ParseQuery, Boolean>());
148149

149150

150151
// Used to keep track of the pages of objects when using CACHE_THEN_NETWORK. When using this,
@@ -375,7 +376,8 @@ private void loadObjects(final int page, final boolean shouldClear) {
375376
objectPages.add(page, new ArrayList<T>());
376377
}
377378

378-
// In the case of CACHE_THEN_NETWORK, two callbacks will be called. Using this flag to keep track,
379+
// In the case of CACHE_THEN_NETWORK, two callbacks will be called. Using this flag to keep
380+
// track of the callbacks.
379381
final Capture<Boolean> firstCallBack = new Capture<>(true);
380382

381383
runningQueries.add(query);
@@ -390,18 +392,22 @@ public void done(List<T> foundObjects, ParseException e) {
390392
}
391393
// In the case of CACHE_THEN_NETWORK, two callbacks will be called. We can only remove the
392394
// query after the second callback.
393-
if (query.getCachePolicy() != CachePolicy.CACHE_THEN_NETWORK ||
394-
(query.getCachePolicy() == CachePolicy.CACHE_THEN_NETWORK && !firstCallBack.get())) {
395+
if (Parse.isLocalDatastoreEnabled() ||
396+
(query.getCachePolicy() != CachePolicy.CACHE_THEN_NETWORK) ||
397+
(query.getCachePolicy() == CachePolicy.CACHE_THEN_NETWORK && !firstCallBack.get())) {
395398
runningQueries.remove(query);
396399
}
400+
397401
if ((!Parse.isLocalDatastoreEnabled() &&
398-
query.getCachePolicy() == CachePolicy.CACHE_ONLY)
399-
&& (e != null) && e.getCode() == ParseException.CACHE_MISS) {
402+
query.getCachePolicy() == CachePolicy.CACHE_ONLY) &&
403+
(e != null) && e.getCode() == ParseException.CACHE_MISS) {
400404
// no-op on cache miss
401405
return;
402406
}
403407

404-
if ((e != null) && ((e.getCode() == ParseException.CONNECTION_FAILED) || (e.getCode() != ParseException.CACHE_MISS))) {
408+
if ((e != null) &&
409+
((e.getCode() == ParseException.CONNECTION_FAILED) ||
410+
(e.getCode() != ParseException.CACHE_MISS))) {
405411
hasNextPage = true;
406412
} else if (foundObjects != null) {
407413
if (shouldClear && firstCallBack.get()) {

0 commit comments

Comments
 (0)