use of com.google.appengine.api.datastore.Query.Filter in project java-docs-samples by GoogleCloudPlatform.
the class IndexesTest method 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);
}
use of com.google.appengine.api.datastore.Query.Filter in project java-docs-samples by GoogleCloudPlatform.
the class MetadataNamespacesTest method getNamespaces.
// [START namespace_query_example]
List<String> getNamespaces(DatastoreService ds, String start, String end) {
// Start with unrestricted namespace query
Query q = new Query(Entities.NAMESPACE_METADATA_KIND);
List<Filter> subFilters = new ArrayList();
// Limit to specified range, if any
if (start != null) {
subFilters.add(new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN_OR_EQUAL, Entities.createNamespaceKey(start)));
}
if (end != null) {
subFilters.add(new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.LESS_THAN_OR_EQUAL, Entities.createNamespaceKey(end)));
}
q.setFilter(CompositeFilterOperator.and(subFilters));
// Initialize result list
List<String> results = new ArrayList<String>();
// Build list of query results
for (Entity e : ds.prepare(q).asIterable()) {
results.add(Entities.getNamespaceFromNamespaceKey(e.getKey()));
}
// Return result list
return results;
}
use of com.google.appengine.api.datastore.Query.Filter in project java-docs-samples by GoogleCloudPlatform.
the class MetadataKindsTest method printLowercaseKinds.
// [START kind_query_example]
void printLowercaseKinds(DatastoreService ds, PrintWriter writer) {
// Start with unrestricted kind query
Query q = new Query(Entities.KIND_METADATA_KIND);
List<Filter> subFils = new ArrayList();
// Limit to lowercase initial letters
subFils.add(new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN_OR_EQUAL, Entities.createKindKey("a")));
// Character after 'z'
String endChar = Character.toString((char) ('z' + 1));
subFils.add(new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.LESS_THAN, Entities.createKindKey(endChar)));
q.setFilter(CompositeFilterOperator.and(subFils));
// Print heading
writer.println("Lowercase kinds:");
// Print query results
for (Entity e : ds.prepare(q).asIterable()) {
writer.println(" " + e.getKey().getName());
}
}
use of com.google.appengine.api.datastore.Query.Filter in project Cached-Datastore by Emperorlou.
the class QueryHelper method getFilteredList_Keys.
public List<Key> getFilteredList_Keys(String kind, int limit, String fieldName, FilterOperator operator, Object equalToValue, String fieldName2, FilterOperator operator2, Object equalToValue2) {
FilterPredicate f1 = new FilterPredicate(fieldName, operator, equalToValue);
FilterPredicate f2 = new FilterPredicate(fieldName2, operator2, equalToValue2);
Filter filter = CompositeFilterOperator.and(f1, f2);
return ds.fetchAsList_Keys(kind, filter, 1000);
}
use of com.google.appengine.api.datastore.Query.Filter in project Cached-Datastore by Emperorlou.
the class QueryHelper method getFilteredORList.
public List<CachedEntity> getFilteredORList(Cursor cursor, String kind, String fieldName, Object equalToValue, String fieldName2, Object equalToValue2, String fieldName3, Object equalToValue3) {
FilterPredicate f1 = new FilterPredicate(fieldName, FilterOperator.EQUAL, equalToValue);
FilterPredicate f2 = new FilterPredicate(fieldName2, FilterOperator.EQUAL, equalToValue2);
FilterPredicate f3 = new FilterPredicate(fieldName3, FilterOperator.EQUAL, equalToValue3);
Filter filter = CompositeFilterOperator.or(f1, f2, f3);
Query q = new Query(kind);
q.setFilter(filter);
return ds.fetchAsList(q, 1000, cursor);
}
Aggregations