Java Code Examples for com.google.appengine.api.datastore.Query#setAncestor()
The following examples show how to use
com.google.appengine.api.datastore.Query#setAncestor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetadataPropertiesTest.java From java-docs-samples with Apache License 2.0 | 6 votes |
List<String> propertiesOfKind(DatastoreService ds, String kind) { // Start with unrestricted keys-only property query Query q = new Query(Entities.PROPERTY_METADATA_KIND).setKeysOnly(); // Limit to specified kind q.setAncestor(Entities.createKindKey(kind)); // Initialize result list ArrayList<String> results = new ArrayList<String>(); //Build list of query results for (Entity e : ds.prepare(q).asIterable()) { results.add(e.getKey().getName()); } // Return result list return results; }
Example 2
Source File: RemoteApiSharedTests.java From appengine-java-vm-runtime with Apache License 2.0 | 6 votes |
@Override public void run( DatastoreService ds, Supplier<Key> keySupplier, Supplier<Entity> entitySupplier) { // Note that we can't use local keys here. Query will fail if you set an ancestor whose app // id does not match the "global" AppIdNamespace. // TODO(xx): Consider making it more lenient, but it's not a big deal. Users can // just use a Key that was created after installing the Remote API. Entity entity = new Entity(getFreshKindName()); entity.setProperty("prop1", 99L); ds.put(entity); // Make sure we can retrieve it via a query. Query query = new Query(entity.getKind()); query.setAncestor(entity.getKey()); query.setFilter( new Query.FilterPredicate( Entity.KEY_RESERVED_PROPERTY, Query.FilterOperator.GREATER_THAN_OR_EQUAL, entity.getKey())); Entity queryResult = ds.prepare(query).asSingleEntity(); // Queries return the Entities with the remote app id. assertRemoteAppId(queryResult.getKey()); assertEquals(99L, queryResult.getProperty("prop1")); }
Example 3
Source File: TestMetadataServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 5 votes |
List<String> propertiesOfKind(DatastoreService ds, String kind) { Query q = new Query(Query.PROPERTY_METADATA_KIND); q.setAncestor(makeKindKey(kind)); ArrayList<String> results = new ArrayList<String>(); for (Entity e : ds.prepare(q).asIterable()) { results.add(e.getKey().getName()); } return results; }
Example 4
Source File: ListTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testStrFilter() { Query q = new Query(kindName); q.setAncestor(rootKey); Query.Filter filter = Query.CompositeFilterOperator.and( new FilterPredicate("stringData", Query.FilterOperator.LESS_THAN, "qqq"), new FilterPredicate("stringData", Query.FilterOperator.GREATER_THAN, "mmm")); q.setFilter(filter); q.addSort("stringData", Query.SortDirection.ASCENDING); assertEquals(2, service.prepare(q).countEntities(fo)); List<Entity> elist = service.prepare(q).asList(fo); assertEquals(Arrays.asList("abc", "xyz", "mno"), elist.get(0).getProperty("stringData")); assertEquals(Arrays.asList("ppp", "iii", "ddd"), elist.get(1).getProperty("stringData")); }
Example 5
Source File: ListTest.java From appengine-tck with Apache License 2.0 | 5 votes |
/** * Google issueId:1458158 */ @Test public void testIntFilter() { Query q = new Query(kindName); Query.Filter filter = Query.CompositeFilterOperator.and( new FilterPredicate("intData1", Query.FilterOperator.LESS_THAN, 20), new FilterPredicate("intData1", Query.FilterOperator.GREATER_THAN, 1), new FilterPredicate("intData1", Query.FilterOperator.EQUAL, null)); q.setFilter(filter); q.addSort("intData1", Query.SortDirection.ASCENDING); q.setAncestor(rootKey); assertEquals(1, service.prepare(q).countEntities(fo)); List<Entity> elist = service.prepare(q).asList(fo); assertEquals(Arrays.asList(1L, 10L, null), elist.get(0).getProperty("intData1")); }
Example 6
Source File: PhotoManagerNoSql.java From solutions-photo-sharing-demo-java with Apache License 2.0 | 5 votes |
@Override public Iterable<Photo> getOwnedPhotos(String userId) { Query query = new Query(getKind()); query.setAncestor(userManager.createDemoUserKey(userId)); Query.Filter filter = new Query.FilterPredicate(PhotoNoSql.FIELD_NAME_ACTIVE, FilterOperator.EQUAL, true); query.setFilter(filter); FetchOptions options = FetchOptions.Builder.withDefaults(); return queryEntities(query, options); }
Example 7
Source File: TestMetadataServlet.java From appengine-java-vm-runtime with Apache License 2.0 | 4 votes |
Collection<String> representationsOf(DatastoreService ds, String kind, String property) { Query q = new Query(Query.PROPERTY_METADATA_KIND); q.setAncestor(makePropertyKey(kind, property)); Entity propInfo = ds.prepare(q).asSingleEntity(); return (Collection<String>) propInfo.getProperty("property_representation"); }