Import com. Google. appengine. API. datastore. datastoreservicefactory;
Import com. Google. appengine. API. datastore. datastoreservice;
Import com. Google. appengine. API. datastore. query. filter;
Import com. Google. appengine. API. datastore. query. filterpredicate;
Import com. Google. appengine. API. datastore. query. filteroperator;
Import com. Google. appengine. API. datastore. query. compositefilter;
Import com. Google. appengine. API. datastore. query. compositefilteroperator;
Import com. Google. appengine. API. datastore. query;
Import com. Google. appengine. API. datastore. preparedquery;
Import com. Google. appengine. API. datastore. entity;
// Get the datastore Service
Datastoreservice datastore = datastoreservicefactory. getdatastoreservice ();
Filter heightminfilter =
New filterpredicate ("height ",
Filteroperator. greater_than_or_equal,
Minheight); // a query corresponds to a Filter Using filterpredicate; heightmaxfilter =
New filterpredicate ("height ",
Filteroperator. less_than_or_equal,
Maxheight );
// Use compositefilter to combine multiple Filters
Filter heightrangefilter =
Compositefilteroperator. And (heightminfilter, heightmaxfilter); // use compositefilter to build a filter for multiple filters in a query.
Filter
// Use class query to assemble a query
Query q = new query ("person"). setfilter (heightrangefilter );
// Use preparedquery interface to retrieve results
Preparedquery PQ = datastore. Prepare (Q );
For (entity result: PQ. asiterable ()){
String firstname = (string) result. getproperty ("firstname ");
String lastname = (string) result. getproperty ("lastname ");
Long Height = (long) result. getproperty ("height ");
System. Out. println (firstname + "" + lastname + "," + height + "inches tall ");
}