当前位置: 首页>>代码示例>>Java>>正文


Java FilterOperator.LESS_THAN属性代码示例

本文整理汇总了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);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:32,代码来源:QueriesTest.java

示例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("/");
}
 
开发者ID:sushain97,项目名称:contestManagement,代码行数:46,代码来源:Logout.java


注:本文中的com.google.appengine.api.datastore.Query.FilterOperator.LESS_THAN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。