Skip to content

Commit 760f09a

Browse files
BigMichi1odrotbohm
authored andcommitted
DATACMNS-1007 - Added IsEmpty and IsNotEmpty keywords to query parser.
The query derivation mechanism now detects IsEmpty and NotIsEmpty as keywords and exposes them in the PartTree. Original pull request: #203.
1 parent be44986 commit 760f09a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/main/asciidoc/repository-query-keywords-reference.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The following table lists the keywords generally supported by the Spring Data re
2222
|`GREATER_THAN_EQUALS`|`GreaterThanEqual`, `IsGreaterThanEqual`
2323
|`IN`|`In`, `IsIn`
2424
|`IS`|`Is`, `Equals`, (or no keyword)
25+
|`IS_EMPTY`|`IsEmpty`, `Empty`
26+
|`IS_NOT_EMPTY`|`IsNotEmpty`, `NotEmpty`
2527
|`IS_NOT_NULL`|`NotNull`, `IsNotNull`
2628
|`IS_NULL`|`Null`, `IsNull`
2729
|`LESS_THAN`|`LessThan`, `IsLessThan`

src/main/java/org/springframework/data/repository/query/parser/Part.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*
3535
* @author Oliver Gierke
3636
* @author Martin Baumgartner
37+
* @author Michael Cramer
3738
*/
3839
public class Part {
3940

@@ -188,13 +189,15 @@ public static enum Type {
188189
"IsNotContaining", "NotContaining", "NotContains"), CONTAINING("IsContaining", "Containing", "Contains"), NOT_IN(
189190
"IsNotIn", "NotIn"), IN("IsIn", "In"), NEAR("IsNear", "Near"), WITHIN("IsWithin", "Within"), REGEX(
190191
"MatchesRegex", "Matches", "Regex"), EXISTS(0, "Exists"), TRUE(0, "IsTrue", "True"), FALSE(0, "IsFalse",
191-
"False"), NEGATING_SIMPLE_PROPERTY("IsNot", "Not"), SIMPLE_PROPERTY("Is", "Equals");
192+
"False"), NEGATING_SIMPLE_PROPERTY("IsNot", "Not"), SIMPLE_PROPERTY("Is", "Equals"), IS_NOT_EMPTY(0, "IsNotEmpty",
193+
"NotEmpty"), IS_EMPTY(0, "IsEmpty", "Empty");
192194

193195
// Need to list them again explicitly as the order is important
194196
// (esp. for IS_NULL, IS_NOT_NULL)
195197
private static final List<Part.Type> ALL = Arrays.asList(IS_NOT_NULL, IS_NULL, BETWEEN, LESS_THAN, LESS_THAN_EQUAL,
196-
GREATER_THAN, GREATER_THAN_EQUAL, BEFORE, AFTER, NOT_LIKE, LIKE, STARTING_WITH, ENDING_WITH, NOT_CONTAINING,
197-
CONTAINING, NOT_IN, IN, NEAR, WITHIN, REGEX, EXISTS, TRUE, FALSE, NEGATING_SIMPLE_PROPERTY, SIMPLE_PROPERTY);
198+
GREATER_THAN, GREATER_THAN_EQUAL, BEFORE, AFTER, NOT_LIKE, LIKE, STARTING_WITH, ENDING_WITH, IS_NOT_EMPTY,
199+
IS_EMPTY, NOT_CONTAINING, CONTAINING, NOT_IN, IN, NEAR, WITHIN, REGEX, EXISTS, TRUE, FALSE,
200+
NEGATING_SIMPLE_PROPERTY, SIMPLE_PROPERTY);
198201

199202
public static final Collection<String> ALL_KEYWORDS;
200203

src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
* @author Martin Baumgartner
4646
* @author Christoph Strobl
4747
* @author Mark Paluch
48+
* @author Michael Cramer
4849
*/
4950
public class PartTreeUnitTests {
5051

@@ -221,6 +222,16 @@ public void returnsAllPartsOfType() {
221222
assertThat(parts, is(hasSize(1)));
222223
}
223224

225+
@Test // DATACMNS-1007
226+
public void parsesEmptyKeywordCorrectly() {
227+
assertType(asList("friendsIsEmpty", "friendsEmpty"), IS_EMPTY, "friends", 0, false);
228+
}
229+
230+
@Test // DATACMNS-1007
231+
public void parsesNotEmptyKeywordCorrectly() {
232+
assertType(asList("friendsIsNotEmpty", "friendsNotEmpty"), IS_NOT_EMPTY, "friends", 0, false);
233+
}
234+
224235
@Test // DATACMNS-94
225236
public void parsesExistsKeywordCorrectly() {
226237
assertType(asList("lastnameExists"), EXISTS, "lastname", 0, false);
@@ -651,6 +662,7 @@ class User {
651662
double[] location;
652663
boolean active;
653664
Date birthday;
665+
List<User> friends;
654666
}
655667

656668
class Organization {

0 commit comments

Comments
 (0)