diff --git a/src/main/java/org/springframework/data/repository/query/parser/Part.java b/src/main/java/org/springframework/data/repository/query/parser/Part.java index 3127aacdb..0fba7e8bb 100644 --- a/src/main/java/org/springframework/data/repository/query/parser/Part.java +++ b/src/main/java/org/springframework/data/repository/query/parser/Part.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,6 @@ import org.springframework.util.StringUtils; * * @author Oliver Gierke * @author Martin Baumgartner - * @author Michael Cramer */ public class Part { @@ -178,6 +177,7 @@ public class Part { * * @author Oliver Gierke * @author Thomas Darimont + * @author Michael Cramer */ public static enum Type { @@ -185,12 +185,12 @@ public class Part { "IsLessThan", "LessThan"), LESS_THAN_EQUAL("IsLessThanEqual", "LessThanEqual"), GREATER_THAN("IsGreaterThan", "GreaterThan"), GREATER_THAN_EQUAL("IsGreaterThanEqual", "GreaterThanEqual"), BEFORE("IsBefore", "Before"), AFTER( "IsAfter", "After"), NOT_LIKE("IsNotLike", "NotLike"), LIKE("IsLike", "Like"), STARTING_WITH("IsStartingWith", - "StartingWith", "StartsWith"), ENDING_WITH("IsEndingWith", "EndingWith", "EndsWith"), NOT_CONTAINING( - "IsNotContaining", "NotContaining", "NotContains"), CONTAINING("IsContaining", "Containing", "Contains"), NOT_IN( - "IsNotIn", "NotIn"), IN("IsIn", "In"), NEAR("IsNear", "Near"), WITHIN("IsWithin", "Within"), REGEX( - "MatchesRegex", "Matches", "Regex"), EXISTS(0, "Exists"), TRUE(0, "IsTrue", "True"), FALSE(0, "IsFalse", - "False"), NEGATING_SIMPLE_PROPERTY("IsNot", "Not"), SIMPLE_PROPERTY("Is", "Equals"), IS_NOT_EMPTY(0, "IsNotEmpty", - "NotEmpty"), IS_EMPTY(0, "IsEmpty", "Empty"); + "StartingWith", "StartsWith"), ENDING_WITH("IsEndingWith", "EndingWith", "EndsWith"), IS_NOT_EMPTY(0, "IsNotEmpty", + "NotEmpty"), IS_EMPTY(0, "IsEmpty", "Empty"), NOT_CONTAINING("IsNotContaining", "NotContaining", "NotContains"), + CONTAINING("IsContaining", "Containing", "Contains"), NOT_IN("IsNotIn", "NotIn"), IN("IsIn", "In"), NEAR("IsNear", + "Near"), WITHIN("IsWithin", "Within"), REGEX("MatchesRegex", "Matches", "Regex"), EXISTS(0, "Exists"), TRUE(0, + "IsTrue", "True"), FALSE(0, "IsFalse", "False"), NEGATING_SIMPLE_PROPERTY("IsNot", "Not"), SIMPLE_PROPERTY("Is", + "Equals"); // Need to list them again explicitly as the order is important // (esp. for IS_NULL, IS_NOT_NULL) diff --git a/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java b/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java index d374ebfd9..2e327fc89 100644 --- a/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java +++ b/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java @@ -222,16 +222,6 @@ public class PartTreeUnitTests { assertThat(parts, is(hasSize(1))); } - @Test // DATACMNS-1007 - public void parsesEmptyKeywordCorrectly() { - assertType(asList("friendsIsEmpty", "friendsEmpty"), IS_EMPTY, "friends", 0, false); - } - - @Test // DATACMNS-1007 - public void parsesNotEmptyKeywordCorrectly() { - assertType(asList("friendsIsNotEmpty", "friendsNotEmpty"), IS_NOT_EMPTY, "friends", 0, false); - } - @Test // DATACMNS-94 public void parsesExistsKeywordCorrectly() { assertType(asList("lastnameExists"), EXISTS, "lastname", 0, false); @@ -577,6 +567,23 @@ public class PartTreeUnitTests { assertThat(part.getProperty(), is(PropertyPath.from("someInfo", Category.class))); } + @Test // DATACMNS-1007 + public void parsesEmptyKeywordCorrectly() { + assertType(asList("friendsIsEmpty", "friendsEmpty"), IS_EMPTY, "friends", 0, false); + } + + @Test // DATACMNS-1007 + public void parsesNotEmptyKeywordCorrectly() { + assertType(asList("friendsIsNotEmpty", "friendsNotEmpty"), IS_NOT_EMPTY, "friends", 0, false); + } + + @Test // DATACMNS-1007 + public void parsesEmptyAsPropertyIfDifferentKeywordIsUsed() { + + assertType(asList("emptyIsTrue"), TRUE, "empty", 0, false); + assertType(asList("emptyIs"), SIMPLE_PROPERTY, "empty", 1, true); + } + private static void assertLimiting(String methodName, Class entityType, boolean limiting, Integer maxResults) { assertLimiting(methodName, entityType, limiting, maxResults, false); } @@ -663,6 +670,7 @@ public class PartTreeUnitTests { boolean active; Date birthday; List friends; + boolean empty; } class Organization {