Skip to content

Commit dbf80ec

Browse files
committed
Merge pull request #164 from YaoPersonal/makestaticfetchinclude
Make OfflineQueryLogic.fetchIncludeAsync static
2 parents b7bcd5e + ab9b386 commit dbf80ec

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

Parse/src/main/java/com/parse/OfflineQueryLogic.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private static boolean matchesWithinConstraint(Object constraint, Object value)
459459

460460
/**
461461
* Returns true iff the given value matches the given operator and constraint.
462-
*
462+
*
463463
* @throws UnsupportedOperationException
464464
* if the operator is not one this function can handle.
465465
*/
@@ -955,8 +955,11 @@ public int compare(T lhs, T rhs) {
955955
/**
956956
* Makes sure that the object specified by path, relative to container, is fetched.
957957
*/
958-
private Task<Void> fetchIncludeAsync(
959-
final Object container, final String path, final ParseSQLiteDatabase db)
958+
private static Task<Void> fetchIncludeAsync(
959+
final OfflineStore store,
960+
final Object container,
961+
final String path,
962+
final ParseSQLiteDatabase db)
960963
throws ParseException {
961964
// If there's no object to include, that's fine.
962965
if (container == null) {
@@ -972,7 +975,7 @@ private Task<Void> fetchIncludeAsync(
972975
task = task.onSuccessTask(new Continuation<Void, Task<Void>>() {
973976
@Override
974977
public Task<Void> then(Task<Void> task) throws Exception {
975-
return fetchIncludeAsync(item, path, db);
978+
return fetchIncludeAsync(store, item, path, db);
976979
}
977980
});
978981
}
@@ -986,7 +989,7 @@ public Task<Void> then(Task<Void> task) throws Exception {
986989
task = task.onSuccessTask(new Continuation<Void, Task<Void>>() {
987990
@Override
988991
public Task<Void> then(Task<Void> task) throws Exception {
989-
return fetchIncludeAsync(array.get(index), path, db);
992+
return fetchIncludeAsync(store, array.get(index), path, db);
990993
}
991994
});
992995
}
@@ -1020,7 +1023,7 @@ public Task<Void> then(Task<Void> task) throws Exception {
10201023
public Task<Object> then(Task<Void> task) throws Exception {
10211024
if (container instanceof ParseObject) {
10221025
// Make sure this object is fetched before descending into it.
1023-
return fetchIncludeAsync(container, null, db).onSuccess(new Continuation<Void, Object>() {
1026+
return fetchIncludeAsync(store, container, null, db).onSuccess(new Continuation<Void, Object>() {
10241027
@Override
10251028
public Object then(Task<Void> task) throws Exception {
10261029
return ((ParseObject) container).get(key);
@@ -1041,25 +1044,27 @@ public Object then(Task<Void> task) throws Exception {
10411044
}).onSuccessTask(new Continuation<Object, Task<Void>>() {
10421045
@Override
10431046
public Task<Void> then(Task<Object> task) throws Exception {
1044-
return fetchIncludeAsync(task.getResult(), rest, db);
1047+
return fetchIncludeAsync(store, task.getResult(), rest, db);
10451048
}
10461049
});
10471050
}
10481051

10491052
/**
10501053
* Makes sure all of the objects included by the given query get fetched.
10511054
*/
1052-
/* package */ <T extends ParseObject> Task<Void> fetchIncludesAsync(
1055+
/* package */ static <T extends ParseObject> Task<Void> fetchIncludesAsync(
1056+
final OfflineStore store,
10531057
final T object,
1054-
ParseQuery.State<T> state, final ParseSQLiteDatabase db) {
1058+
ParseQuery.State<T> state,
1059+
final ParseSQLiteDatabase db) {
10551060
Set<String> includes = state.includes();
10561061
// We do the fetches in series because it makes it easier to fail on the first error.
10571062
Task<Void> task = Task.forResult(null);
10581063
for (final String include : includes) {
10591064
task = task.onSuccessTask(new Continuation<Void, Task<Void>>() {
10601065
@Override
10611066
public Task<Void> then(Task<Void> task) throws Exception {
1062-
return fetchIncludeAsync(object, include, db);
1067+
return fetchIncludeAsync(store, object, include, db);
10631068
}
10641069
});
10651070
}

Parse/src/main/java/com/parse/OfflineStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public Task<List<T>> then(Task<Void> task) throws Exception {
455455
fetchedIncludesTask = fetchedIncludesTask.onSuccessTask(new Continuation<Void, Task<Void>>() {
456456
@Override
457457
public Task<Void> then(Task<Void> task) throws Exception {
458-
return queryLogic.fetchIncludesAsync(object, query, db);
458+
return OfflineQueryLogic.fetchIncludesAsync(OfflineStore.this, object, query, db);
459459
}
460460
});
461461
}

Parse/src/test/java/com/parse/OfflineQueryLogicTest.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ public void testFetchIncludesParseObject() throws ParseException {
828828
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
829829
.thenReturn(Task.<ParseObject>forResult(null));
830830

831-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
832831
ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class);
833832

834833
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
@@ -839,7 +838,7 @@ public void testFetchIncludesParseObject() throws ParseException {
839838
ParseObject unfetchedObject = new ParseObject("TestObject");
840839
object.put("foo", unfetchedObject);
841840

842-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db));
841+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db));
843842
verify(store).fetchLocallyAsync(object, db);
844843
verify(store).fetchLocallyAsync(unfetchedObject, db);
845844
verifyNoMoreInteractions(store);
@@ -851,7 +850,6 @@ public void testFetchIncludesCollection() throws ParseException {
851850
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
852851
.thenReturn(Task.<ParseObject>forResult(null));
853852

854-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
855853
ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class);
856854

857855
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
@@ -864,7 +862,7 @@ public void testFetchIncludesCollection() throws ParseException {
864862
objects.add(unfetchedObject);
865863
when(object.get("foo")).thenReturn(objects);
866864

867-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db));
865+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db));
868866
verify(store).fetchLocallyAsync(object, db);
869867
verify(store).fetchLocallyAsync(unfetchedObject, db);
870868
verifyNoMoreInteractions(store);
@@ -876,7 +874,6 @@ public void testFetchIncludesJSONArray() throws ParseException {
876874
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
877875
.thenReturn(Task.<ParseObject>forResult(null));
878876

879-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
880877
ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class);
881878

882879
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
@@ -889,7 +886,7 @@ public void testFetchIncludesJSONArray() throws ParseException {
889886
objects.put(unfetchedObject);
890887
when(object.get("foo")).thenReturn(objects);
891888

892-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db));
889+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db));
893890
verify(store).fetchLocallyAsync(object, db);
894891
verify(store).fetchLocallyAsync(unfetchedObject, db);
895892
verifyNoMoreInteractions(store);
@@ -901,7 +898,6 @@ public void testFetchIncludesMap() throws ParseException {
901898
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
902899
.thenReturn(Task.<ParseObject>forResult(null));
903900

904-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
905901
ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class);
906902

907903
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
@@ -914,7 +910,7 @@ public void testFetchIncludesMap() throws ParseException {
914910
objects.put("bar", unfetchedObject);
915911
when(object.get("foo")).thenReturn(objects);
916912

917-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db));
913+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db));
918914
verify(store).fetchLocallyAsync(object, db);
919915
verify(store).fetchLocallyAsync(unfetchedObject, db);
920916
verifyNoMoreInteractions(store);
@@ -926,7 +922,6 @@ public void testFetchIncludesJSONObject() throws Exception {
926922
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
927923
.thenReturn(Task.<ParseObject>forResult(null));
928924

929-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
930925
ParseSQLiteDatabase db = mock(ParseSQLiteDatabase.class);
931926

932927
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
@@ -939,7 +934,7 @@ public void testFetchIncludesJSONObject() throws Exception {
939934
objects.put("bar", unfetchedObject);
940935
when(object.get("foo")).thenReturn(objects);
941936

942-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, db));
937+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, db));
943938
verify(store).fetchLocallyAsync(object, db);
944939
verify(store).fetchLocallyAsync(unfetchedObject, db);
945940
verifyNoMoreInteractions(store);
@@ -951,16 +946,14 @@ public void testFetchIncludesNull() throws ParseException {
951946
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
952947
.thenReturn(Task.<ParseObject>forResult(null));
953948

954-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
955-
956949
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
957950
.include("foo")
958951
.build();
959952

960953
ParseObject object = new ParseObject("TestObject");
961954
object.put("foo", JSONObject.NULL);
962955

963-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null));
956+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null));
964957
// only itself
965958
verify(store, times(1))
966959
.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class));
@@ -972,8 +965,6 @@ public void testFetchIncludesNonParseObject() throws ParseException {
972965
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
973966
.thenReturn(Task.<ParseObject>forResult(null));
974967

975-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
976-
977968
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
978969
.include("foo")
979970
.build();
@@ -982,7 +973,7 @@ public void testFetchIncludesNonParseObject() throws ParseException {
982973
object.put("foo", 1);
983974

984975
thrown.expect(ParseException.class);
985-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null));
976+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null));
986977
// only itself
987978
verify(store, times(1))
988979
.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class));
@@ -994,15 +985,13 @@ public void testFetchIncludesDoesNotExist() throws ParseException {
994985
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
995986
.thenReturn(Task.<ParseObject>forResult(null));
996987

997-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
998-
999988
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
1000989
.include("foo")
1001990
.build();
1002991

1003992
ParseObject object = new ParseObject("TestObject");
1004993

1005-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null));
994+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null));
1006995
// only itself
1007996
verify(store, times(1))
1008997
.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class));
@@ -1014,16 +1003,14 @@ public void testFetchIncludesNestedNull() throws Exception {
10141003
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
10151004
.thenReturn(Task.<ParseObject>forResult(null));
10161005

1017-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
1018-
10191006
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
10201007
.include("foo.bar")
10211008
.build();
10221009

10231010
ParseObject object = new ParseObject("TestObject");
10241011
object.put("foo", JSONObject.NULL);
10251012

1026-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null));
1013+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null));
10271014
// only itself
10281015
verify(store, times(1))
10291016
.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class));
@@ -1035,8 +1022,6 @@ public void testFetchIncludesNestedNonParseObject() throws Exception {
10351022
when(store.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class)))
10361023
.thenReturn(Task.<ParseObject>forResult(null));
10371024

1038-
OfflineQueryLogic logic = new OfflineQueryLogic(store);
1039-
10401025
ParseQuery.State<ParseObject> query = new ParseQuery.State.Builder<>("TestObject")
10411026
.include("foo.bar")
10421027
.build();
@@ -1045,7 +1030,7 @@ public void testFetchIncludesNestedNonParseObject() throws Exception {
10451030
object.put("foo", 1);
10461031

10471032
thrown.expect(IllegalStateException.class);
1048-
ParseTaskUtils.wait(logic.fetchIncludesAsync(object, query, null));
1033+
ParseTaskUtils.wait(OfflineQueryLogic.fetchIncludesAsync(store, object, query, null));
10491034
// only itself
10501035
verify(store, times(1))
10511036
.fetchLocallyAsync(any(ParseObject.class), any(ParseSQLiteDatabase.class));

0 commit comments

Comments
 (0)