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


Java FilterOperator.GREATER_THAN属性代码示例

本文整理汇总了Java中com.google.appengine.api.datastore.Query.FilterOperator.GREATER_THAN属性的典型用法代码示例。如果您正苦于以下问题:Java FilterOperator.GREATER_THAN属性的具体用法?Java FilterOperator.GREATER_THAN怎么用?Java FilterOperator.GREATER_THAN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.appengine.api.datastore.Query.FilterOperator的用法示例。


在下文中一共展示了FilterOperator.GREATER_THAN属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: propertyFilterExample_returnsMatchingEntities

@Test
public void propertyFilterExample_returnsMatchingEntities() throws Exception {
  // [START unindexed_properties_1]
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Key acmeKey = KeyFactory.createKey("Company", "Acme");

  Entity tom = new Entity("Person", "Tom", acmeKey);
  tom.setProperty("name", "Tom");
  tom.setProperty("age", 32);
  datastore.put(tom);

  Entity lucy = new Entity("Person", "Lucy", acmeKey);
  lucy.setProperty("name", "Lucy");
  lucy.setUnindexedProperty("age", 29);
  datastore.put(lucy);

  Filter ageFilter = new FilterPredicate("age", FilterOperator.GREATER_THAN, 25);

  Query q = new Query("Person").setAncestor(acmeKey).setFilter(ageFilter);

  // Returns tom but not lucy, because her age is unindexed
  List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
  // [END unindexed_properties_1]

  assertThat(results).named("query results").containsExactly(tom);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:27,代码来源:IndexesTest.java

示例2: keyFilterExample_returnsMatchingEntities

@Test
public void keyFilterExample_returnsMatchingEntities() throws Exception {
  // Arrange
  Entity a = new Entity("Person", "a");
  Entity b = new Entity("Person", "b");
  Entity c = new Entity("Person", "c");
  Entity aa = new Entity("Person", "aa", b.getKey());
  Entity bb = new Entity("Person", "bb", b.getKey());
  Entity aaa = new Entity("Person", "aaa", bb.getKey());
  Entity bbb = new Entity("Person", "bbb", bb.getKey());
  datastore.put(ImmutableList.<Entity>of(a, b, c, aa, bb, aaa, bbb));

  // Act
  Key lastSeenKey = bb.getKey();
  // [START key_filter_example]
  Filter keyFilter =
      new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, lastSeenKey);
  Query q = new Query("Person").setFilter(keyFilter);
  // [END key_filter_example]

  // Assert
  List<Entity> results =
      datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
  assertThat(results)
      .named("query results")
      .containsExactly(
          aaa, // Ancestor path "b/bb/aaa" is greater than "b/bb".
          bbb, // Ancestor path "b/bb/bbb" is greater than "b/bb".
          c); // Key name identifier "c" is greater than b.
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:30,代码来源:QueriesTest.java

示例3: keyFilterExample_kindless_returnsMatchingEntities

@Test
public void keyFilterExample_kindless_returnsMatchingEntities() throws Exception {
  // Arrange
  Entity a = new Entity("Child", "a");
  Entity b = new Entity("Child", "b");
  Entity c = new Entity("Child", "c");
  Entity aa = new Entity("Child", "aa", b.getKey());
  Entity bb = new Entity("Child", "bb", b.getKey());
  Entity aaa = new Entity("Child", "aaa", bb.getKey());
  Entity bbb = new Entity("Child", "bbb", bb.getKey());
  Entity adult = new Entity("Adult", "a");
  Entity zooAnimal = new Entity("ZooAnimal", "a");
  datastore.put(ImmutableList.<Entity>of(a, b, c, aa, bb, aaa, bbb, adult, zooAnimal));

  // Act
  Key lastSeenKey = bb.getKey();
  // [START kindless_query_example]
  Filter keyFilter =
      new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, lastSeenKey);
  Query q = new Query().setFilter(keyFilter);
  // [END kindless_query_example]

  // Assert
  List<Entity> results =
      datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
  assertThat(results)
      .named("query results")
      .containsExactly(
          aaa, // Ancestor path "b/bb/aaa" is greater than "b/bb".
          bbb, // Ancestor path "b/bb/bbb" is greater than "b/bb".
          zooAnimal, // Kind "ZooAnimal" is greater than "Child"
          c); // Key name identifier "c" is greater than b.
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:33,代码来源:QueriesTest.java

示例4: ancestorQueryExample_kindlessKeyFilter_returnsMatchingEntities

@Test
public void ancestorQueryExample_kindlessKeyFilter_returnsMatchingEntities() throws Exception {
  // Arrange
  Entity a = new Entity("Grandparent", "a");
  Entity b = new Entity("Grandparent", "b");
  Entity c = new Entity("Grandparent", "c");
  Entity aa = new Entity("Parent", "aa", a.getKey());
  Entity ba = new Entity("Parent", "ba", b.getKey());
  Entity bb = new Entity("Parent", "bb", b.getKey());
  Entity bc = new Entity("Parent", "bc", b.getKey());
  Entity cc = new Entity("Parent", "cc", c.getKey());
  Entity aaa = new Entity("Child", "aaa", aa.getKey());
  Entity bbb = new Entity("Child", "bbb", bb.getKey());
  datastore.put(ImmutableList.<Entity>of(a, b, c, aa, ba, bb, bc, cc, aaa, bbb));

  // Act
  Key ancestorKey = b.getKey();
  Key lastSeenKey = bb.getKey();
  // [START kindless_ancestor_key_query_example]
  Filter keyFilter =
      new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, lastSeenKey);
  Query q = new Query().setAncestor(ancestorKey).setFilter(keyFilter);
  // [END kindless_ancestor_key_query_example]

  // Assert
  List<Entity> results =
      datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults());
  assertThat(results).named("query results").containsExactly(bc, bbb);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:29,代码来源:QueriesTest.java

示例5: ancestorQueryExample_kindlessKeyFilterFull_returnsMatchingEntities

@Test
public void ancestorQueryExample_kindlessKeyFilterFull_returnsMatchingEntities()
    throws Exception {
  // [START kindless_ancestor_query_example]
  DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

  Entity tom = new Entity("Person", "Tom");
  Key tomKey = tom.getKey();
  datastore.put(tom);

  Entity weddingPhoto = new Entity("Photo", tomKey);
  weddingPhoto.setProperty("imageURL", "http://domain.com/some/path/to/wedding_photo.jpg");

  Entity weddingVideo = new Entity("Video", tomKey);
  weddingVideo.setProperty("videoURL", "http://domain.com/some/path/to/wedding_video.avi");

  List<Entity> mediaList = Arrays.asList(weddingPhoto, weddingVideo);
  datastore.put(mediaList);

  // By default, ancestor queries include the specified ancestor itself.
  // The following filter excludes the ancestor from the query results.
  Filter keyFilter =
      new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, tomKey);

  Query mediaQuery = new Query().setAncestor(tomKey).setFilter(keyFilter);

  // Returns both weddingPhoto and weddingVideo,
  // even though they are of different entity kinds
  List<Entity> results =
      datastore.prepare(mediaQuery).asList(FetchOptions.Builder.withDefaults());
  // [END kindless_ancestor_query_example]

  assertThat(results).named("query result keys").containsExactly(weddingPhoto, weddingVideo);
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:34,代码来源:QueriesTest.java

示例6: 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

示例7: getToken

private static Entity getToken(String token) {
	Filter tokenFilter = new FilterPredicate("token", FilterOperator.EQUAL, token);
	Filter expireFilter = new FilterPredicate("expires", FilterOperator.GREATER_THAN, new Date());
	Query query = new Query("authToken").setFilter(CompositeFilterOperator.and(tokenFilter, expireFilter));

	List<Entity> tokens = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(1));
	return !tokens.isEmpty() ? tokens.get(0) : null;
}
 
开发者ID:sushain97,项目名称:contestManagement,代码行数:8,代码来源:UserCookie.java


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