44
44
45
45
import java .io .PrintWriter ;
46
46
import java .io .StringWriter ;
47
- import java .util .ArrayList ;
48
47
import java .util .Arrays ;
49
48
import java .util .List ;
50
49
@@ -685,9 +684,7 @@ public void queryRestrictions_sortWrongOrderOnInequality_isInvalid() throws Exce
685
684
public void queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEntities ()
686
685
throws Exception {
687
686
Entity a = new Entity ("Widget" , "a" );
688
- ArrayList <Long > xs = new ArrayList <>();
689
- xs .add (1L );
690
- xs .add (2L );
687
+ List <Long > xs = Arrays .asList (1L , 2L );
691
688
a .setProperty ("x" , xs );
692
689
datastore .put (a );
693
690
@@ -701,6 +698,8 @@ public void queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEnti
701
698
// [END surprising_behavior_example_1]
702
699
703
700
// Entity "a" will not match because no individual value matches all filters.
701
+ // See the documentation for more details:
702
+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
704
703
List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
705
704
assertThat (results ).named ("query results" ).isEmpty ();
706
705
}
@@ -729,6 +728,9 @@ public void queryRestrictions_surprisingMultipleValuesEquals_returnsMatchedEntit
729
728
new FilterPredicate ("x" , FilterOperator .EQUAL , 2 )));
730
729
// [END surprising_behavior_example_2]
731
730
731
+ // Only "a" and "e" have both 1 and 2 in the "x" array-valued property.
732
+ // See the documentation for more details:
733
+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
732
734
List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
733
735
assertThat (getKeys (results )).named ("query result keys" ).containsExactly (a .getKey (), e .getKey ());
734
736
}
@@ -752,6 +754,9 @@ public void queryRestrictions_surprisingMultipleValuesNotEquals_returnsMatchedEn
752
754
Query q = new Query ("Widget" ).setFilter (new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 1 ));
753
755
// [END surprising_behavior_example_3]
754
756
757
+ // The query matches any entity that has a some value other than 1. Only
758
+ // entity "e" is not matched. See the documentation for more details:
759
+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
755
760
List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
756
761
assertThat (getKeys (results ))
757
762
.named ("query result keys" )
@@ -776,6 +781,13 @@ public void queryRestrictions_surprisingMultipleValuesTwoNotEquals_returnsMatche
776
781
new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 2 )));
777
782
// [END surprising_behavior_example_4]
778
783
784
+ // The two NOT_EQUAL filters in the query become like the combination of queries:
785
+ // x < 1 OR (x > 1 AND x < 2) OR x > 2
786
+ //
787
+ // Only "b" has some value which matches the "x > 2" portion of this query.
788
+ //
789
+ // See the documentation for more details:
790
+ // https://cloud.google.com/appengine/docs/java/datastore/query-restrictions#properties_with_multiple_values_can_behave_in_surprising_ways
779
791
List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
780
792
assertThat (getKeys (results )).named ("query result keys" ).containsExactly (b .getKey ());
781
793
}
0 commit comments