use of com.google.appengine.api.datastore.Query.FilterPredicate in project java-docs-samples by GoogleCloudPlatform.
the class QueriesTest method queryRestrictions_compositeFilter_isInvalid.
@Test
public void queryRestrictions_compositeFilter_isInvalid() throws Exception {
long minBirthYear = 1940;
long maxHeight = 200;
// [START inequality_filters_one_property_invalid_example]
Filter birthYearMinFilter = new FilterPredicate("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYear);
Filter heightMaxFilter = new FilterPredicate("height", FilterOperator.LESS_THAN_OR_EQUAL, maxHeight);
Filter invalidFilter = CompositeFilterOperator.and(birthYearMinFilter, heightMaxFilter);
Query q = new Query("Person").setFilter(invalidFilter);
// [END inequality_filters_one_property_invalid_example]
// Note: The local devserver behavior is different than the production
// version of Cloud Datastore, so there aren't any assertions we can make
// in this test. The query appears to work with the local test runner,
// but will fail in production.
}
use of com.google.appengine.api.datastore.Query.FilterPredicate in project java-docs-samples by GoogleCloudPlatform.
the class QueriesTest method retrievePersonWithLastName.
private Entity retrievePersonWithLastName(String targetLastName) {
// [START single_retrieval_example]
Query q = new Query("Person").setFilter(new FilterPredicate("lastName", FilterOperator.EQUAL, targetLastName));
PreparedQuery pq = datastore.prepare(q);
Entity result = pq.asSingleEntity();
// [END single_retrieval_example]
return result;
}
use of com.google.appengine.api.datastore.Query.FilterPredicate in project java-docs-samples by GoogleCloudPlatform.
the class MetadataPropertiesTest method printPropertyRange.
// [START property_filtering_example]
void printPropertyRange(DatastoreService ds, PrintWriter writer) {
// Start with unrestricted keys-only property query
Query q = new Query(Entities.PROPERTY_METADATA_KIND).setKeysOnly();
// Limit range
q.setFilter(CompositeFilterOperator.and(new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, Query.FilterOperator.GREATER_THAN_OR_EQUAL, Entities.createPropertyKey("Employee", "salary")), new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, Query.FilterOperator.LESS_THAN_OR_EQUAL, Entities.createPropertyKey("Manager", "salary"))));
q.addSort(Entity.KEY_RESERVED_PROPERTY, SortDirection.ASCENDING);
// Print query results
for (Entity e : ds.prepare(q).asIterable()) {
writer.println(e.getKey().getParent().getName() + ": " + e.getKey().getName());
}
}
use of com.google.appengine.api.datastore.Query.FilterPredicate in project Cached-Datastore by Emperorlou.
the class QueryHelper method getFilteredList_Keys.
public List<Key> getFilteredList_Keys(String kind, 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.FilterPredicate in project Cached-Datastore by Emperorlou.
the class QueryHelper method getFilteredList_Count.
public Long getFilteredList_Count(String kind, Integer limit, String fieldName, FilterOperator operator, Object equalToValue, String fieldName2, FilterOperator operator2, Object equalToValue2, String fieldName3, FilterOperator operator3, Object equalToValue3) {
Query q = new Query(kind);
FilterPredicate f1 = new FilterPredicate(fieldName, operator, equalToValue);
FilterPredicate f2 = new FilterPredicate(fieldName2, operator2, equalToValue2);
FilterPredicate f3 = new FilterPredicate(fieldName3, operator3, equalToValue3);
Filter f = CompositeFilterOperator.and(f1, f2, f3);
q.setFilter(f);
return ds.countEntities(q, 5000);
}
Aggregations