google datastore filter
2024-07-15 21:11:57 222人阅读
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);//一个查询对应一个过滤器Filter用FilterPredicate;heightMaxFilter =
new FilterPredicate("height",
FilterOperator.LESS_THAN_OR_EQUAL,
maxHeight);
//Use CompositeFilter to combine multiple filters
Filter heightRangeFilter =
CompositeFilterOperator.and(heightMinFilter, heightMaxFilter);//一个查询对应多个Filter用CompositeFilter,搭建过滤器
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 :