Java Code Examples for com.google.appengine.api.datastore.Query.CompositeFilterOperator#and()
The following examples show how to use
com.google.appengine.api.datastore.Query.CompositeFilterOperator#and() .
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: QueriesTest.java From java-docs-samples with Apache License 2.0 | 6 votes |
@Test public void queryRestrictions_compositeFilter_isInvalid() throws Exception { long minBirthYear = 1940; long maxHeight = 200; // [START gae_java8_datastore_inequality_filters_one_property_invalid] 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 gae_java8_datastore_inequality_filters_one_property_invalid] // 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. }
Example 2
Source File: QueriesTest.java From java-docs-samples with Apache License 2.0 | 5 votes |
@Test public void queryRestrictions_compositeFilter_returnsMatchedEntities() throws Exception { // Arrange Entity a = new Entity("Person", "a"); a.setProperty("birthYear", 1930); Entity b = new Entity("Person", "b"); b.setProperty("birthYear", 1960); Entity c = new Entity("Person", "c"); c.setProperty("birthYear", 1990); datastore.put(ImmutableList.<Entity>of(a, b, c)); // Act long minBirthYear = 1940; long maxBirthYear = 1980; // [START gae_java8_datastore_inequality_filters_one_property_valid_1] Filter birthYearMinFilter = new FilterPredicate("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYear); Filter birthYearMaxFilter = new FilterPredicate("birthYear", FilterOperator.LESS_THAN_OR_EQUAL, maxBirthYear); Filter birthYearRangeFilter = CompositeFilterOperator.and(birthYearMinFilter, birthYearMaxFilter); Query q = new Query("Person").setFilter(birthYearRangeFilter); // [END gae_java8_datastore_inequality_filters_one_property_valid_1] // Assert List<Entity> results = datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults()); assertWithMessage("query results").that(results).containsExactly(b); }
Example 3
Source File: DatastoreUtil.java From appengine-tck with Apache License 2.0 | 5 votes |
public Entity getMarker(String marker) { DatastoreService service = DatastoreServiceFactory.getDatastoreService(); FilterPredicate testRunFilter = new FilterPredicate(TEST_RUN_ID, FilterOperator.EQUAL, testRunId); FilterPredicate markerFilter = new FilterPredicate(MARKER, FilterOperator.EQUAL, marker); CompositeFilter filter = CompositeFilterOperator.and(testRunFilter, markerFilter); Query query = new Query(entityName).setFilter(filter); return service.prepare(query).asSingleEntity(); }
Example 4
Source File: QueriesTest.java From java-docs-samples with Apache License 2.0 | 4 votes |
@Test public void queryRestrictions_compositeEqualFilter_returnsMatchedEntities() throws Exception { // Arrange Entity a = new Entity("Person", "a"); a.setProperty("birthYear", 1930); a.setProperty("city", "Somewhere"); a.setProperty("lastName", "Someone"); Entity b = new Entity("Person", "b"); b.setProperty("birthYear", 1960); b.setProperty("city", "Somewhere"); b.setProperty("lastName", "Someone"); Entity c = new Entity("Person", "c"); c.setProperty("birthYear", 1990); c.setProperty("city", "Somewhere"); c.setProperty("lastName", "Someone"); Entity d = new Entity("Person", "d"); d.setProperty("birthYear", 1960); d.setProperty("city", "Nowhere"); d.setProperty("lastName", "Someone"); Entity e = new Entity("Person", "e"); e.setProperty("birthYear", 1960); e.setProperty("city", "Somewhere"); e.setProperty("lastName", "Noone"); datastore.put(ImmutableList.<Entity>of(a, b, c, d, e)); long minBirthYear = 1940; long maxBirthYear = 1980; String targetCity = "Somewhere"; String targetLastName = "Someone"; // [START gae_java8_datastore_inequality_filters_one_property_valid_2] Filter lastNameFilter = new FilterPredicate("lastName", FilterOperator.EQUAL, targetLastName); Filter cityFilter = new FilterPredicate("city", FilterOperator.EQUAL, targetCity); Filter birthYearMinFilter = new FilterPredicate("birthYear", FilterOperator.GREATER_THAN_OR_EQUAL, minBirthYear); Filter birthYearMaxFilter = new FilterPredicate("birthYear", FilterOperator.LESS_THAN_OR_EQUAL, maxBirthYear); Filter validFilter = CompositeFilterOperator.and( lastNameFilter, cityFilter, birthYearMinFilter, birthYearMaxFilter); Query q = new Query("Person").setFilter(validFilter); // [END gae_java8_datastore_inequality_filters_one_property_valid_2] // Assert List<Entity> results = datastore.prepare(q.setKeysOnly()).asList(FetchOptions.Builder.withDefaults()); assertWithMessage("query results").that(results).containsExactly(b); }
Example 5
Source File: DatastoreUtil.java From appengine-tck with Apache License 2.0 | 4 votes |
private CompositeFilter getTestMethodFilter(String testMethodTag) { FilterPredicate testRunFilter = new FilterPredicate(TEST_RUN_ID, FilterOperator.EQUAL, testRunId); FilterPredicate method = new FilterPredicate(TEST_METHOD_TAG, FilterOperator.EQUAL, testMethodTag); return CompositeFilterOperator.and(testRunFilter, method); }