Browse Source

DATACMNS-1007 - Polishing.

Moved the enum declaration to a more appropriate position. Moved the author addition to the part of the codebase that was actually changed. Expanded copyright year.

Moved unit tests to more appropriate position. Added another one to make sure a reference to a boolean property "empty" can still be supported by adding an explicit Is to make sure we detect a simple property reference.

Original pull request: #203.
pull/194/head
Oliver Gierke 9 years ago
parent
commit
d98c0df40b
  1. 16
      src/main/java/org/springframework/data/repository/query/parser/Part.java
  2. 28
      src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

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

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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 { @@ -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)

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

@ -222,16 +222,6 @@ public class PartTreeUnitTests { @@ -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 { @@ -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 { @@ -663,6 +670,7 @@ public class PartTreeUnitTests {
boolean active;
Date birthday;
List<User> friends;
boolean empty;
}
class Organization {

Loading…
Cancel
Save