com.stackmob.sdk.api
Class StackMobQuery

java.lang.Object
  extended by com.stackmob.sdk.api.StackMobQuery

public class StackMobQuery
extends Object

A class that builds queries to execute on the StackMob platform. Example usage: //this code: StackMobQuery query = new StackMobQuery("user").field("age").isGreaterThan(20).isLessThanOrEqualTo(40).field("friend").in(Arrays.asList("joe", "bob", "alice").getQuery(); //is identical to this code: StackMobQuery query = new StackMobQuery("user").fieldIsGreaterThan("user", 20).fieldIsLessThanOrEqualTo("user", 40).fieldIsIn("user", Arrays.asList("joe", "bob", "alice"); A few helpful notes about this object:


Nested Class Summary
static class StackMobQuery.Operator
           
static class StackMobQuery.Ordering
           
 
Constructor Summary
StackMobQuery(String objectName)
           
 
Method Summary
 StackMobQuery expandDepthIs(Integer i)
          set the expand depth of this query.
 StackMobQueryWithField field(String field)
           
 StackMobQuery fieldIsEqualTo(String field, String val)
          add an "=" to your query.
 StackMobQuery fieldIsGreaterThan(String field, String val)
          same as fieldIsLessThan(String, String), except applies ">" instead of "<"
 StackMobQuery fieldIsGreaterThanOrEqualTo(String field, String val)
          same as fieldIsLessThan(String, String), except applies ">=" instead of "<"
 StackMobQuery fieldIsIn(String field, List<String> values)
          add an "IN" to your query.
 StackMobQuery fieldIsLessThan(String field, String val)
          same as fieldIsLessThan(String, String), except works with Strings
 StackMobQuery fieldIslessThanOrEqualTo(String field, String val)
          same as fieldIsLessThan(String, String), except applies "<=" instead of "<"
 StackMobQuery fieldIsNear(String field, GeoPoint point)
          add a "NEAR" to your query for the given GeoPoint field.
 StackMobQuery fieldIsNearWithinKm(String field, GeoPoint point, Double maxDistanceKm)
          add a "NEAR" to your query for the given GeoPoint field.
 StackMobQuery fieldIsNearWithinMi(String field, GeoPoint point, Double maxDistanceMi)
          add a "NEAR" to your query for the given GeoPoint field.
 StackMobQuery fieldIsOrderedBy(String field, StackMobQuery.Ordering ordering)
          add an "ORDER BY" to your query
 StackMobQuery fieldIsWithinBox(String field, GeoPoint lowerLeft, GeoPoint upperRight)
          add a "WITHIN" to your query for the given GeoPoint field.
 StackMobQuery fieldIsWithinRadiusInKm(String field, GeoPoint point, Double radiusInKm)
          add a "WITHIN" to your query for the given GeoPoint field.
 StackMobQuery fieldIsWithinRadiusInMi(String field, GeoPoint point, Double radiusInMi)
          add a "WITHIN" to your query for the given GeoPoint field.
 Map<String,String> getArguments()
           
 Map<String,String> getHeaders()
           
 String getObjectName()
           
 StackMobQuery isInRange(Integer start)
          same thing as isInRange(Integer, Integer), except does not specify an end to the range.
 StackMobQuery isInRange(Integer start, Integer end)
          this method lets you add a "LIMIT" and "SKIP" to your query at once.
static StackMobQuery objects(String objectName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StackMobQuery

public StackMobQuery(String objectName)
Method Detail

objects

public static StackMobQuery objects(String objectName)

getObjectName

public String getObjectName()

getHeaders

public Map<String,String> getHeaders()

getArguments

public Map<String,String> getArguments()

field

public StackMobQueryWithField field(String field)

fieldIsNear

public StackMobQuery fieldIsNear(String field,
                                 GeoPoint point)
add a "NEAR" to your query for the given GeoPoint field. Query results are automatically returned sorted by distance closest to the queried point

Parameters:
field - the GeoPoint field whose value to test
point - the lon/lat location to center the search
Returns:
the new query that resulted from adding this operation

fieldIsNearWithinMi

public StackMobQuery fieldIsNearWithinMi(String field,
                                         GeoPoint point,
                                         Double maxDistanceMi)
add a "NEAR" to your query for the given GeoPoint field. Query results are automatically returned sorted by distance closest to the queried point

Parameters:
field - the GeoPoint field whose value to test
point - the lon/lat location to center the search
maxDistanceMi - the maximum distance in miles a matched field can be from point.
Returns:
the new query that resulted from adding this operation

fieldIsNearWithinKm

public StackMobQuery fieldIsNearWithinKm(String field,
                                         GeoPoint point,
                                         Double maxDistanceKm)
add a "NEAR" to your query for the given GeoPoint field. Query results are automatically returned sorted by distance closest to the queried point

Parameters:
field - the GeoPoint field whose value to test
point - the lon/lat location to center the search
maxDistanceKm - the maximum distance in kilometers a matched field can be from point.
Returns:
the new query that resulted from adding this operation

fieldIsWithinRadiusInMi

public StackMobQuery fieldIsWithinRadiusInMi(String field,
                                             GeoPoint point,
                                             Double radiusInMi)
add a "WITHIN" to your query for the given GeoPoint field. Query results are not sorted by distance.

Parameters:
field - the GeoPoint field whose value to test
point - the lon/lat location to center the search
radiusInMi - the maximum distance in miles a matched field can be from point.
Returns:
the new query that resulted from adding this operation

fieldIsWithinRadiusInKm

public StackMobQuery fieldIsWithinRadiusInKm(String field,
                                             GeoPoint point,
                                             Double radiusInKm)
add a "WITHIN" to your query for the given GeoPoint field. Query results are not sorted by distance.

Parameters:
field - the GeoPoint field whose value to test
point - the lon/lat location to center the search
radiusInKm - the maximum distance in kilometers a matched field can be from point.
Returns:
the new query that resulted from adding this operation

fieldIsWithinBox

public StackMobQuery fieldIsWithinBox(String field,
                                      GeoPoint lowerLeft,
                                      GeoPoint upperRight)
add a "WITHIN" to your query for the given GeoPoint field. Matched fields will be within the 2-dimensional bounds defined by the lowerLeft and upperRight GeoPoints given

Parameters:
field - the GeoPoint field whose value to test
lowerLeft - the lon/lat location of the lower left corner of the bounding box
upperRight - the lon/lat location of the upper right corner of the bounding box
Returns:
the new query that resulted from adding this operation

fieldIsIn

public StackMobQuery fieldIsIn(String field,
                               List<String> values)
add an "IN" to your query. test whether the given field's value is in the given list of possible values

Parameters:
field - the field whose value to test
values - the values against which to match
Returns:
the new query that resulted from adding this operation

fieldIsLessThan

public StackMobQuery fieldIsLessThan(String field,
                                     String val)
same as fieldIsLessThan(String, String), except works with Strings

Parameters:
field - the field whose value to test
val - the value against which to test
Returns:
the new query that resulted from adding this operation

fieldIslessThanOrEqualTo

public StackMobQuery fieldIslessThanOrEqualTo(String field,
                                              String val)
same as fieldIsLessThan(String, String), except applies "<=" instead of "<"

Parameters:
field - the field whose value to test
val - the value against which to test
Returns:
the new query that resulted from adding this operation

fieldIsGreaterThan

public StackMobQuery fieldIsGreaterThan(String field,
                                        String val)
same as fieldIsLessThan(String, String), except applies ">" instead of "<"

Parameters:
field - the field whose value to test
val - the value against which to test
Returns:
the new query that resulted from adding this operation

fieldIsGreaterThanOrEqualTo

public StackMobQuery fieldIsGreaterThanOrEqualTo(String field,
                                                 String val)
same as fieldIsLessThan(String, String), except applies ">=" instead of "<"

Parameters:
field - the field whose value to test
val - the value against which to test
Returns:
the new query that resulted from adding this operation

fieldIsEqualTo

public StackMobQuery fieldIsEqualTo(String field,
                                    String val)
add an "=" to your query. test whether the given field's value is equal to the given value

Parameters:
field - the field whose value to test
val - the value against which to test
Returns:
the new query that resulted from adding this operation

fieldIsOrderedBy

public StackMobQuery fieldIsOrderedBy(String field,
                                      StackMobQuery.Ordering ordering)
add an "ORDER BY" to your query

Parameters:
field - the field to order by
ordering - the ordering of that field
Returns:
the new query that resulted from adding this operation

expandDepthIs

public StackMobQuery expandDepthIs(Integer i)
set the expand depth of this query. the expand depth instructs the StackMob platform to detect relationships and automatically replace those relationship IDs with the values that they point to.

Parameters:
i - the expand depth. at time of writing, StackMob restricts expand depth to maximum 3
Returns:
the new query that resulted from adding this operation

isInRange

public StackMobQuery isInRange(Integer start,
                               Integer end)
this method lets you add a "LIMIT" and "SKIP" to your query at once. Can be used to implement pagination in your app.

Parameters:
start - the starting object number (inclusive)
end - the ending object number (inclusive)
Returns:
the new query that resulted from adding this operation

isInRange

public StackMobQuery isInRange(Integer start)
same thing as isInRange(Integer, Integer), except does not specify an end to the range. instead, gets all objects from a starting point (including)

Parameters:
start - the starting object number
Returns:
the new query that resulted from adding this operation


Copyright © 2012 StackMob. All Rights Reserved.