Skip to content

Commit cc1aa71

Browse files
committed
DATACMNS-750 - Fixed part creation in query methods that have keywords in property paths.
If a keyword was contained in a complex property path (like In in SomeInfo), the property path was invalidly cut of in the middle. We now simply use the length of the keyword to extract the actual property from the candidate. This should be faster anyway as it doesn't require another lookup of the pattern in the source candidate. Related pull request: #136.
1 parent 6775d11 commit cc1aa71

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public String extractProperty(String part) {
298298

299299
for (String keyword : keywords) {
300300
if (candidate.endsWith(keyword)) {
301-
return candidate.substring(0, candidate.indexOf(keyword));
301+
return candidate.substring(0, candidate.length() - keyword.length());
302302
}
303303
}
304304

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Iterator;
2828
import java.util.List;
2929

30+
import org.hamcrest.Matchers;
3031
import org.junit.Test;
3132
import org.springframework.data.domain.Sort;
3233
import org.springframework.data.domain.Sort.Direction;
@@ -670,6 +671,24 @@ public void buildsPartTreeForNotContainingCorrectly() throws Exception {
670671
assertPart(tree, new Part[] { new Part("legalNameNotContaining", Organization.class) });
671672
}
672673

674+
/**
675+
* @see DATACMNS-750
676+
*/
677+
@Test
678+
public void doesNotFailOnPropertiesContainingAKeyword() {
679+
680+
PartTree partTree = new PartTree("findBySomeInfoIn", Category.class);
681+
682+
Iterable<Part> parts = partTree.getParts();
683+
684+
assertThat(parts, is(Matchers.<Part> iterableWithSize(1)));
685+
686+
Part part = parts.iterator().next();
687+
688+
assertThat(part.getType(), is(Type.IN));
689+
assertThat(part.getProperty(), is(PropertyPath.from("someInfo", Category.class)));
690+
}
691+
673692
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
674693
assertLimiting(methodName, entityType, limiting, maxResults, false);
675694
}
@@ -791,6 +810,8 @@ interface Product {
791810
interface Category {
792811

793812
Long getId();
813+
814+
String getSomeInfo();
794815
}
795816

796817
interface Order {

0 commit comments

Comments
 (0)