Search in sources :

Example 1 with PropertyProjection

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);
}
Also used : Entity(com.google.appengine.api.datastore.Entity) Query(com.google.appengine.api.datastore.Query) PropertyProjection(com.google.appengine.api.datastore.PropertyProjection) Test(org.junit.Test)

Example 2 with PropertyProjection

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));
}
Also used : PropertyProjection(com.google.appengine.api.datastore.PropertyProjection) Date(java.util.Date)

Aggregations

PropertyProjection (com.google.appengine.api.datastore.PropertyProjection)2 Entity (com.google.appengine.api.datastore.Entity)1 Query (com.google.appengine.api.datastore.Query)1 Date (java.util.Date)1 Test (org.junit.Test)1