本文整理汇总了Java中com.google.appengine.api.datastore.Query.FilterOperator.LESS_THAN属性的典型用法代码示例。如果您正苦于以下问题:Java FilterOperator.LESS_THAN属性的具体用法?Java FilterOperator.LESS_THAN怎么用?Java FilterOperator.LESS_THAN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.appengine.api.datastore.Query.FilterOperator
的用法示例。
在下文中一共展示了FilterOperator.LESS_THAN属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryInterface_orFilter_printsMatchedEntities
@Test
public void queryInterface_orFilter_printsMatchedEntities() throws Exception {
// Arrange
Entity a = new Entity("Person", "a");
a.setProperty("height", 100);
Entity b = new Entity("Person", "b");
b.setProperty("height", 150);
Entity c = new Entity("Person", "c");
c.setProperty("height", 200);
datastore.put(ImmutableList.<Entity>of(a, b, c));
StringWriter buf = new StringWriter();
PrintWriter out = new PrintWriter(buf);
long minHeight = 125;
long maxHeight = 175;
// Act
// [START interface_3]
Filter tooShortFilter = new FilterPredicate("height", FilterOperator.LESS_THAN, minHeight);
Filter tooTallFilter = new FilterPredicate("height", FilterOperator.GREATER_THAN, maxHeight);
Filter heightOutOfRangeFilter = CompositeFilterOperator.or(tooShortFilter, tooTallFilter);
Query q = new Query("Person").setFilter(heightOutOfRangeFilter);
// [END interface_3]
// Assert
List<Entity> results =
datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
assertThat(results).named("query results").containsExactly(a, c);
}
示例2: doGet
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
UserCookie userCookie = UserCookie.getCookie(req);
if (userCookie != null) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Transaction txn = datastore.beginTransaction(TransactionOptions.Builder.withXG(true));
try {
userCookie.authenticate();
Query query = new Query("authToken").setKeysOnly();
if (req.getParameterMap().containsKey("all")) {
query.setFilter(new FilterPredicate("user-id", FilterOperator.EQUAL, userCookie.getUsername()));
}
else {
Filter tokenFilter = new FilterPredicate("token", FilterOperator.EQUAL, URLDecoder.decode(userCookie.getValue(), "UTF-8"));
Filter expiredFilter = new FilterPredicate("expires", FilterOperator.LESS_THAN, new Date());
query.setFilter(CompositeFilterOperator.or(tokenFilter, expiredFilter));
}
List<Entity> tokens = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(5));
for (Entity token : tokens) {
datastore.delete(token.getKey());
}
txn.commit();
}
catch (Exception e) {
e.printStackTrace();
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
return;
}
finally {
if (txn.isActive()) {
txn.rollback();
}
}
userCookie.setMaxAge(0);
userCookie.setValue("");
resp.addCookie(userCookie);
}
resp.sendRedirect("/");
}