19
19
20
20
/** package */ class ParseRESTQueryCommand extends ParseRESTCommand {
21
21
22
+ /* package */ final static String KEY_ORDER = "order" ;
23
+ /* package */ final static String KEY_WHERE = "where" ;
24
+ /* package */ final static String KEY_KEYS = "keys" ;
25
+ /* package */ final static String KEY_INCLUDE = "include" ;
26
+ /* package */ final static String KEY_LIMIT = "limit" ;
27
+ /* package */ final static String KEY_COUNT = "count" ;
28
+ /* package */ final static String KEY_SKIP = "skip" ;
29
+ /* package */ final static String KEY_TRACE = "trace" ;
30
+
22
31
public static <T extends ParseObject > ParseRESTQueryCommand findCommand (
23
32
ParseQuery .State <T > state , String sessionToken ) {
24
33
String httpPath = String .format ("classes/%s" , state .className ());
@@ -41,38 +50,41 @@ public static <T extends ParseObject> ParseRESTQueryCommand countCommand(
41
50
HashMap <String , String > parameters = new HashMap <>();
42
51
List <String > order = state .order ();
43
52
if (!order .isEmpty ()) {
44
- parameters .put ("order" , ParseTextUtils .join ("," , order ));
53
+ parameters .put (KEY_ORDER , ParseTextUtils .join ("," , order ));
45
54
}
46
55
47
56
ParseQuery .QueryConstraints conditions = state .constraints ();
48
57
if (!conditions .isEmpty ()) {
49
58
JSONObject encodedConditions =
50
59
(JSONObject ) encoder .encode (conditions );
51
- parameters .put ("where" , encodedConditions .toString ());
60
+ parameters .put (KEY_WHERE , encodedConditions .toString ());
52
61
}
53
62
54
63
// This is nullable since we allow unset selectedKeys as well as no selectedKeys
55
64
Set <String > selectedKeys = state .selectedKeys ();
56
65
if (selectedKeys != null ) {
57
- parameters .put ("keys" , ParseTextUtils .join ("," , selectedKeys ));
66
+ parameters .put (KEY_KEYS , ParseTextUtils .join ("," , selectedKeys ));
58
67
}
59
68
60
69
Set <String > includeds = state .includes ();
61
70
if (!includeds .isEmpty ()) {
62
- parameters .put ("include" , ParseTextUtils .join ("," , includeds ));
71
+ parameters .put (KEY_INCLUDE , ParseTextUtils .join ("," , includeds ));
72
+ }
73
+
74
+ // Respect what the caller wanted for limit, even if count is true, because
75
+ // parse-server supports it. Currently with our APIs, when counting, limit will always be 0,
76
+ // but that logic is in ParseQuery class and we should not do that again here.
77
+ int limit = state .limit ();
78
+ if (limit >= 0 ) {
79
+ parameters .put (KEY_LIMIT , Integer .toString (limit ));
63
80
}
64
81
65
82
if (count ) {
66
- parameters .put ("count" , Integer .toString (1 ));
83
+ parameters .put (KEY_COUNT , Integer .toString (1 ));
67
84
} else {
68
- int limit = state .limit ();
69
- if (limit >= 0 ) {
70
- parameters .put ("limit" , Integer .toString (limit ));
71
- }
72
-
73
85
int skip = state .skip ();
74
86
if (skip > 0 ) {
75
- parameters .put ("skip" , Integer .toString (skip ));
87
+ parameters .put (KEY_SKIP , Integer .toString (skip ));
76
88
}
77
89
}
78
90
@@ -83,7 +95,7 @@ public static <T extends ParseObject> ParseRESTQueryCommand countCommand(
83
95
}
84
96
85
97
if (state .isTracingEnabled ()) {
86
- parameters .put ("trace" , Integer .toString (1 ));
98
+ parameters .put (KEY_TRACE , Integer .toString (1 ));
87
99
}
88
100
return parameters ;
89
101
}
0 commit comments