4343import com .google .gcloud .datastore .Query ;
4444import com .google .gcloud .datastore .Query .ResultType ;
4545import com .google .gcloud .datastore .QueryResults ;
46+ import com .google .gcloud .datastore .ReadOption ;
4647import com .google .gcloud .datastore .StringValue ;
4748import com .google .gcloud .datastore .StructuredQuery ;
4849import com .google .gcloud .datastore .StructuredQuery .CompositeFilter ;
4950import com .google .gcloud .datastore .StructuredQuery .OrderBy ;
50- import com .google .gcloud .datastore .StructuredQuery .Projection ;
5151import com .google .gcloud .datastore .StructuredQuery .PropertyFilter ;
5252import com .google .gcloud .datastore .Transaction ;
5353import com .google .gcloud .datastore .testing .LocalGcdHelper ;
@@ -373,7 +373,8 @@ private void setUpQueryTests() {
373373 .set ("priority" , 4 )
374374 .set ("created" , includedDate )
375375 .set ("percent_complete" , 10.0 )
376- .set ("description" , StringValue .builder ("Learn Cloud Datastore" ).indexed (false ).build ())
376+ .set ("description" ,
377+ StringValue .builder ("Learn Cloud Datastore" ).excludeFromIndexes (true ).build ())
377378 .set ("tag" , "fun" , "l" , "programming" )
378379 .build ());
379380 }
@@ -512,7 +513,7 @@ public void testProjectionQuery() {
512513 // [START projection_query]
513514 Query <ProjectionEntity > query = Query .projectionEntityQueryBuilder ()
514515 .kind ("Task" )
515- .projection (Projection . property ( "priority" ), Projection . property ( "percent_complete" ) )
516+ .projection ("priority" , "percent_complete" )
516517 .build ();
517518 // [END projection_query]
518519 assertValidQuery (query );
@@ -523,7 +524,7 @@ public void testRunProjectionQuery() {
523524 setUpQueryTests ();
524525 Query <ProjectionEntity > query = Query .projectionEntityQueryBuilder ()
525526 .kind ("Task" )
526- .projection (Projection . property ( "priority" ), Projection . property ( "percent_complete" ) )
527+ .projection ("priority" , "percent_complete" )
527528 .build ();
528529 // [START run_query_projection]
529530 List <Long > priorities = new LinkedList <>();
@@ -565,8 +566,8 @@ public void testDistinctQuery() {
565566 // [START distinct_query]
566567 Query <ProjectionEntity > query = Query .projectionEntityQueryBuilder ()
567568 .kind ("Task" )
568- .projection (Projection . property ( "type" ), Projection . property ( "priority" ) )
569- .groupBy ("type" , "priority" )
569+ .projection ("type" , "priority" )
570+ .distinctOn ("type" , "priority" )
570571 .orderBy (OrderBy .asc ("type" ), OrderBy .asc ("priority" ))
571572 .build ();
572573 // [END distinct_query]
@@ -579,8 +580,8 @@ public void testDistinctOnQuery() {
579580 // [START distinct_on_query]
580581 Query <ProjectionEntity > query = Query .projectionEntityQueryBuilder ()
581582 .kind ("Task" )
582- .projection (Projection . property ( "type" ), Projection . first ( "priority" ) )
583- .groupBy ("type" )
583+ .projection ("type" , "priority" )
584+ .distinctOn ("type" )
584585 .orderBy (OrderBy .asc ("type" ), OrderBy .asc ("priority" ))
585586 .build ();
586587 // [END distinct_on_query]
@@ -726,9 +727,16 @@ private Cursor cursorPaging(int pageSize, Cursor pageCursor) {
726727
727728 @ Test
728729 public void testEventualConsistentQuery () {
730+ setUpQueryTests ();
729731 // [START eventual_consistent_query]
730- // Read consistency cannot be specified in gcloud-java.
732+ Query <Entity > query = Query .entityQueryBuilder ()
733+ .kind ("Task" )
734+ .filter (PropertyFilter .hasAncestor (
735+ datastore .newKeyFactory ().kind ("TaskList" ).newKey ("default" )))
736+ .build ();
737+ datastore .run (query , ReadOption .eventualConsistency ());
731738 // [END eventual_consistent_query]
739+ assertValidQuery (query );
732740 }
733741
734742 @ Test
0 commit comments