use of com.google.appengine.api.datastore.Query.FilterPredicate 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.FilterPredicate in project java-docs-samples by GoogleCloudPlatform.
the class IndexesServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// [START exploding_index_example_1]
Query q = new Query("Widget").setFilter(CompositeFilterOperator.and(new FilterPredicate("x", FilterOperator.EQUAL, 1), new FilterPredicate("y", FilterOperator.EQUAL, 2))).addSort("date", Query.SortDirection.ASCENDING);
// [END exploding_index_example_1]
List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults());
PrintWriter out = resp.getWriter();
out.printf("Got %d widgets.\n", results.size());
}
use of com.google.appengine.api.datastore.Query.FilterPredicate in project iosched by google.
the class ServingUrlManagerTest method testGetServingUrl_withSourceUrl.
@Test
public void testGetServingUrl_withSourceUrl() throws Exception {
PreparedQuery mockPreparedQuery = mock(PreparedQuery.class);
when(mockDatastoreService.prepare(any(Query.class))).thenReturn(mockPreparedQuery);
when(mockPreparedQuery.asList(any(FetchOptions.class))).thenAnswer(new Answer<List<Entity>>() {
@Override
public List<Entity> answer(InvocationOnMock invocation) throws Throwable {
Key key = mock(Key.class);
when(key.getKind()).thenReturn(ServingUrlManager.ENTITY_KIND);
when(key.getName()).thenReturn(GCS_FULLPATH);
Entity entity = new Entity(key);
entity.setProperty(ServingUrlManager.SERVING_URL_PROPERTY, SERVING_URL);
return new ArrayList<>(Arrays.asList(entity));
}
});
assertEquals(SERVING_URL, ServingUrlManager.INSTANCE.getServingUrl(SOURCE_URL));
ArgumentCaptor<Query> queryCaptor = ArgumentCaptor.forClass(Query.class);
verify(mockDatastoreService).prepare(queryCaptor.capture());
Query query = queryCaptor.getValue();
assertEquals(ServingUrlManager.ENTITY_KIND, query.getKind());
assertEquals(new FilterPredicate(ServingUrlManager.SOURCE_URL_PROPERTY, FilterOperator.EQUAL, SOURCE_URL), query.getFilter());
}
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, 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.FilterPredicate 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