@@ -108,8 +108,10 @@ static Filter fromPb(com.google.datastore.v1beta3.Filter filterPb) {
108108 switch (filterPb .getFilterTypeCase ()) {
109109 case COMPOSITE_FILTER :
110110 return CompositeFilter .fromPb (filterPb .getCompositeFilter ());
111- default :
111+ case PROPERTY_FILTER :
112112 return PropertyFilter .fromPb (filterPb .getPropertyFilter ());
113+ default :
114+ throw new AssertionError ("Unexpected enum value " + filterPb .getFilterTypeCase ());
113115 }
114116 }
115117 }
@@ -530,7 +532,7 @@ static class BaseBuilder<V, B extends BaseBuilder<V, B>> {
530532 private String kind ;
531533 private final List <String > projection = new LinkedList <>();
532534 private Filter filter ;
533- private boolean distinctOnAll = false ;
535+ private boolean distinct = false ;
534536 private final List <String > distinctOn = new LinkedList <>();
535537 private final List <OrderBy > orderBy = new LinkedList <>();
536538 private Cursor startCursor ;
@@ -620,14 +622,16 @@ B addProjection(String projection, String... others) {
620622
621623 B clearDistinct () {
622624 distinctOn .clear ();
623- distinctOnAll = false ;
625+ distinct = false ;
624626 return self ();
625627 }
626628
627629 B distinct (String ... properties ) {
628630 clearDistinct ();
629631 if (properties .length == 0 ) {
630- this .distinctOnAll = true ;
632+ clearDistinct ();
633+ this .distinct = true ;
634+ this .distinctOn .addAll (this .projection );
631635 } else if (properties .length == 1 ) {
632636 addDistinct (properties [0 ]);
633637 } else {
@@ -637,6 +641,9 @@ B distinct(String... properties) {
637641 }
638642
639643 B addDistinct (String property , String ... others ) {
644+ if (this .distinct ) {
645+ throw new IllegalStateException ("\" distinct()\" is currently set." );
646+ }
640647 this .distinctOn .add (property );
641648 Collections .addAll (this .distinctOn , others );
642649 return self ();
@@ -672,15 +679,10 @@ B mergeFrom(com.google.datastore.v1beta3.Query queryPb) {
672679 for (com .google .datastore .v1beta3 .PropertyReference distinctOnPb : queryPb .getDistinctOnList ()) {
673680 addDistinct (distinctOnPb .getName ());
674681 }
675- distinctOnAll = false ;
676682 return self ();
677683 }
678684
679685 public StructuredQuery <V > build () {
680- if (distinctOnAll ) {
681- clearDistinct ();
682- this .distinctOn .addAll (this .projection );
683- }
684686 return new StructuredQuery <>(this );
685687 }
686688 }
0 commit comments