use of com.google.appengine.api.datastore.PropertyProjection in project java-docs-samples by GoogleCloudPlatform.
the class ProjectionTest method projectionQuery_grouping_filtersDuplicates.
@Test
public void projectionQuery_grouping_filtersDuplicates() {
putTestData("some duplicate", 0L);
putTestData("some duplicate", 0L);
putTestData("too big", 1L);
// [START grouping]
Query q = new Query("TestKind");
q.addProjection(new PropertyProjection("A", String.class));
q.addProjection(new PropertyProjection("B", Long.class));
q.setDistinct(true);
q.setFilter(Query.FilterOperator.LESS_THAN.of("B", 1L));
q.addSort("B", Query.SortDirection.DESCENDING);
q.addSort("A");
// [END grouping]
List<Entity> entities = datastore.prepare(q).asList(FetchOptions.Builder.withLimit(5));
assertThat(entities).hasSize(1);
Entity entity = entities.get(0);
assertThat((String) entity.getProperty("A")).named("entity.A").isEqualTo("some duplicate");
assertThat((long) entity.getProperty("B")).named("entity.B").isEqualTo(0L);
}
use of com.google.appengine.api.datastore.PropertyProjection in project java-docs-samples by GoogleCloudPlatform.
the class ProjectionServlet method addGuestbookProjections.
private void addGuestbookProjections(Query query) {
query.addProjection(new PropertyProjection("content", String.class));
query.addProjection(new PropertyProjection("date", Date.class));
}
Aggregations