码迷,mamicode.com
首页 > 其他好文 > 详细

google datastore filter

时间:2014-08-05 13:51:49      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:os   for   ar   new   htm   c   res   app   

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 : 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");
}

google datastore filter,布布扣,bubuko.com

google datastore filter

标签:os   for   ar   new   htm   c   res   app   

原文地址:http://www.cnblogs.com/penny-home/p/3891979.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!