1919
2020/** package */ class ParseRESTQueryCommand extends ParseRESTCommand {
2121
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+
2231 public static <T extends ParseObject > ParseRESTQueryCommand findCommand (
2332 ParseQuery .State <T > state , String sessionToken ) {
2433 String httpPath = String .format ("classes/%s" , state .className ());
@@ -41,38 +50,41 @@ public static <T extends ParseObject> ParseRESTQueryCommand countCommand(
4150 HashMap <String , String > parameters = new HashMap <>();
4251 List <String > order = state .order ();
4352 if (!order .isEmpty ()) {
44- parameters .put ("order" , ParseTextUtils .join ("," , order ));
53+ parameters .put (KEY_ORDER , ParseTextUtils .join ("," , order ));
4554 }
4655
4756 ParseQuery .QueryConstraints conditions = state .constraints ();
4857 if (!conditions .isEmpty ()) {
4958 JSONObject encodedConditions =
5059 (JSONObject ) encoder .encode (conditions );
51- parameters .put ("where" , encodedConditions .toString ());
60+ parameters .put (KEY_WHERE , encodedConditions .toString ());
5261 }
5362
5463 // This is nullable since we allow unset selectedKeys as well as no selectedKeys
5564 Set <String > selectedKeys = state .selectedKeys ();
5665 if (selectedKeys != null ) {
57- parameters .put ("keys" , ParseTextUtils .join ("," , selectedKeys ));
66+ parameters .put (KEY_KEYS , ParseTextUtils .join ("," , selectedKeys ));
5867 }
5968
6069 Set <String > includeds = state .includes ();
6170 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 ));
6380 }
6481
6582 if (count ) {
66- parameters .put ("count" , Integer .toString (1 ));
83+ parameters .put (KEY_COUNT , Integer .toString (1 ));
6784 } else {
68- int limit = state .limit ();
69- if (limit >= 0 ) {
70- parameters .put ("limit" , Integer .toString (limit ));
71- }
72-
7385 int skip = state .skip ();
7486 if (skip > 0 ) {
75- parameters .put ("skip" , Integer .toString (skip ));
87+ parameters .put (KEY_SKIP , Integer .toString (skip ));
7688 }
7789 }
7890
@@ -83,7 +95,7 @@ public static <T extends ParseObject> ParseRESTQueryCommand countCommand(
8395 }
8496
8597 if (state .isTracingEnabled ()) {
86- parameters .put ("trace" , Integer .toString (1 ));
98+ parameters .put (KEY_TRACE , Integer .toString (1 ));
8799 }
88100 return parameters ;
89101 }
0 commit comments