com.google.appengine.api.datastore.Query.setAncestor()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中com.google.appengine.api.datastore.Query.setAncestor方法的一些代码示例,展示了Query.setAncestor的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setAncestor方法的具体详情如下:
包路径:com.google.appengine.api.datastore.Query
类名称:Query
方法名:setAncestor

Query.setAncestor介绍

暂无

代码示例

代码示例来源:origin: com.googlecode.cedar-common/objectify

@Override
public Query<T> ancestor(Object keyOrEntity)
{
  this.actual.setAncestor(this.factory.getRawKey(keyOrEntity));
  return this;
}

代码示例来源:origin: com.google.appengine.orm/datanucleus-appengine

private void addParentFilter(Query.FilterOperator op, Key key, Query datastoreQuery) {
 // We only support queries on parent if it is an equality filter.
 if (op != Query.FilterOperator.EQUAL) {
  throw new UnsupportedDatastoreFeatureException("Operator is of type " + op + " but the "
    + "datastore only supports parent queries using the equality operator.");
 }
 if (key == null) {
  throw new UnsupportedDatastoreFeatureException(
    "Received a null parent parameter.  The datastore does not support querying for null parents.");
 }
 datastoreQuery.setAncestor(key);
}

代码示例来源:origin: feroult/yawp

private void prepareQueryAncestor(QueryBuilder<?> builder, Query q) {
  IdRef<?> parentId = builder.getParentId();
  if (parentId == null) {
    return;
  }
  q.setAncestor(IdRefToKey.toKey(r, parentId));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test(expected = DatastoreNeedIndexException.class)
public void testQueryWithAncestorAndSortOrderRequiresConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .setAncestor(KeyFactory.createKey("Ancestor", 1))
      .addSort("someProperty"));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test(expected = DatastoreNeedIndexException.class)
public void testQueryWithAncestorAndInequalityFiltersRequiresConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .setAncestor(KeyFactory.createKey("Ancestor", 1))
      .setFilter(new Query.FilterPredicate("someProperty", GREATER_THAN, "a")));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testQueryUsingOnlyAncestorAndEqualityFiltersDoesNotRequireConfiguredIndex() throws Exception {
  executeQuery(new Query("Unindexed")
    .setAncestor(KeyFactory.createKey("Ancestor", 1))
    .setFilter(new Query.FilterPredicate("someProperty", EQUAL, "foo")));
  executeQuery(new Query("Unindexed")
    .setAncestor(KeyFactory.createKey("Ancestor", 1))
    .setFilter(
      and(new Query.FilterPredicate("someProperty", EQUAL, "foo"),
        new Query.FilterPredicate("otherProperty", EQUAL, "bar"))));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testKindlessQueryUsingOnlyAncestorAndKeyFiltersDoesNotRequireConfiguredIndex() throws Exception {
  executeQuery(new Query()
    .setAncestor(KeyFactory.createKey("Ancestor", 1))
    .setFilter(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Kind", 1))));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testFilteringByKind() throws Exception {
  Key parentKey = createQueryBasicsTestParent("testFilteringByKind");
  Entity foo = createEntity("foo", parentKey).store();
  Entity bar = createEntity("bar", parentKey).store();
  PreparedQuery preparedQuery = service.prepare(new Query("foo").setAncestor(parentKey));
  List<Entity> results = preparedQuery.asList(withDefaults());
  assertEquals(1, results.size());
  assertEquals(foo, results.get(0));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void queriesDontReturnDeletedEntities() throws Exception {
  String methodName = "queriesDontReturnDeletedEntities";
  Entity entity = createTestEntityWithUniqueMethodNameKey(SMOKE_TEST_ENTITY, methodName);
  Key key = entity.getKey();
  service.put(entity);
  service.delete(key);
  List<Entity> entities = service.prepare(new Query(SMOKE_TEST_ENTITY).setAncestor(key))
    .asList(FetchOptions.Builder.withDefaults());
  assertEquals(0, entities.size());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testQueryWithAncestorAndInequalityFilterOnKeyPropertyDoesNotRequireConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .setAncestor(KeyFactory.createKey("Ancestor", 1))
      .setFilter(new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Unindexed", 1))));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testIntegerPropertySortingIsNotLexicographic() throws Exception {
  String methodName = "testIntegerPropertySortingIsNotLexicographic";
  Entity parent = createTestEntityWithUniqueMethodNameKey(QUERY_SORTING_ENTITY, methodName);
  Key key = parent.getKey();
  Entity ten = storeTestEntityWithSingleProperty(key, 10);
  Entity five = storeTestEntityWithSingleProperty(key, 5);
  Query query = createQuery().setAncestor(key).addSort(SINGLE_PROPERTY_NAME, ASCENDING);
  List<Entity> results = service.prepare(query).asList(withDefaults());
  assertTrue(results.indexOf(five) < results.indexOf(ten));   // if sorting were lexicographic, "10" would come before "5"
  service.delete(ten.getKey(), five.getKey());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testFilterOnMultiValuedProperty() throws Exception {
  Key parentKey = createQueryBasicsTestParent("testFilterOnMultiValuedProperty");
  createEntity("Entry", parentKey)
    .withProperty("letters", Arrays.asList("a", "b", "c"))
    .store();
  Query query = new Query("Entry")
    .setAncestor(parentKey)
    .setFilter(new Query.FilterPredicate("letters", EQUAL, "a"));
  assertNotNull(service.prepare(query).asSingleEntity());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test(expected = DatastoreNeedIndexException.class)
public void testAncestorQueryWithInequalityFilterOnSomePropertyAndEqualityFilterOnSamePropertyRequiresConfiguredIndex() throws Exception {
  executeQuery(
    new Query("Unindexed")
      .setAncestor(KeyFactory.createKey("Ancestor", 1))
      .setFilter(
        and(new Query.FilterPredicate("someProperty", EQUAL, "b"),
          new Query.FilterPredicate("someProperty", GREATER_THAN, "a"))));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testQueryUsingOnlyAncestorFiltersAndEqualityFiltersOnPropertiesAndInequalityFiltersOnKeysDoesNotRequireConfiguredIndex() throws Exception {
  executeQuery(new Query("Unindexed")
    .setAncestor(KeyFactory.createKey("Ancestor", 1))
    .setFilter(
      and(new Query.FilterPredicate("someProperty", EQUAL, "foo"),
        new Query.FilterPredicate(Entity.KEY_RESERVED_PROPERTY, GREATER_THAN, KeyFactory.createKey("Unindexed", 1)))));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testProjectionQueryReturnsEntitiesContainingProjectedPropertyEvenIfPropertyValueIsNull() throws Exception {
  String methodName = "testProjectionQueryOnlyReturnsEntitiesContainingProjectedPropertyEvenIfPropertyValueIsNull";
  Entity parent = createTestEntityWithUniqueMethodNameKey("Kind", methodName);
  Key key = parent.getKey();
  Entity e1 = createEntity("Kind", key)
    .withProperty("foo", null)
    .store();
  Query query = new Query("Kind")
    .setAncestor(key)
    .addProjection(new PropertyProjection("foo", String.class));
  List<Entity> results = service.prepare(query).asList(withDefaults());
  assertEquals(Collections.singletonList(e1), results);
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void queryingByKindOnlyReturnsEntitiesOfRequestedKind() throws Exception {
  Key parentKey = createQueryBasicsTestParent("queryingByKindOnlyReturnsEntitiesOfRequestedKind");
  Entity person = new Entity(KeyFactory.createKey(parentKey, "Person", 1));
  service.put(person);
  Entity address = new Entity(KeyFactory.createKey(parentKey, "Address", 1));
  service.put(address);
  assertSingleResult(person, new Query("Person").setAncestor(parentKey));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testNullPropertyValue() throws Exception {
  Key parentKey = createQueryBasicsTestParent("testNullPropertyValue");
  createEntity("Entry", parentKey)
    .withProperty("user", null)
    .store();
  Entity entity = service.prepare(new Query("Entry")
    .setAncestor(parentKey)).asSingleEntity();
  assertNull(entity.getProperty("user"));
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testFilterEqualNull() throws Exception {
  Key parentKey = createQueryBasicsTestParent("testFilterEqualNull");
  createEntity("Entry", parentKey)
    .withProperty("user", null)
    .store();
  Query query = new Query("Entry")
    .setAncestor(parentKey)
    .setFilter(new Query.FilterPredicate("user", EQUAL, null));
  assertNotNull(service.prepare(query).asSingleEntity());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Test
public void testFilterNotEqualNull() throws Exception {
  Key parentKey = createQueryBasicsTestParent("testFilterNotEqualNull");
  createEntity("Entry", parentKey)
    .withProperty("user", "joe")
    .store();
  Query query = new Query("Entry")
    .setAncestor(parentKey)
    .setFilter(new Query.FilterPredicate("user", NOT_EQUAL, null));
  assertNotNull(service.prepare(query).asSingleEntity());
}

代码示例来源:origin: GoogleCloudPlatform/appengine-tck

@Before
public void setUp() {
  super.setUp();
  johnsParent = createTestEntityWithUniqueMethodNameKey("Person", "PreparedQueryTest");
  Key key = johnsParent.getKey();
  john = createEntity("Person", key)
    .withProperty("name", "John")
    .store();
  Query query = new Query("Person")
    .setAncestor(key)
    .setFilter(new Query.FilterPredicate("name", EQUAL, "John"));
  preparedQuery = service.prepare(query);
}

相关文章