From ff51b134f9208e386c9b7c3df10552d72b052a7b Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 3 May 2011 15:12:22 +0200 Subject: [PATCH] DATADOC-43 Added Near and Within as part types to support spatial repository queries. --- spring-data-commons-core/.classpath | 6 +++++- .../data/repository/query/parser/Part.java | 8 ++++++-- .../query/parser/PartTreeUnitTests.java | 20 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/spring-data-commons-core/.classpath b/spring-data-commons-core/.classpath index 16f01e2ee..000cda07e 100644 --- a/spring-data-commons-core/.classpath +++ b/spring-data-commons-core/.classpath @@ -2,6 +2,10 @@ - + + + + + diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java index 85eb537d8..8363b75d7 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/parser/Part.java @@ -158,16 +158,20 @@ public class Part { NOT_IN("NotIn"), IN("In"), + + NEAR("Near"), + + WITHIN("Within"), NEGATING_SIMPLE_PROPERTY("Not"), - + SIMPLE_PROPERTY; // Need to list them again explicitly as the order is important // (esp. for IS_NULL, IS_NOT_NULL) private static final List ALL = Arrays.asList(IS_NOT_NULL, IS_NULL, BETWEEN, LESS_THAN, GREATER_THAN, NOT_LIKE, LIKE, - NOT_IN, IN, NEGATING_SIMPLE_PROPERTY, SIMPLE_PROPERTY); + NOT_IN, IN, NEAR, WITHIN, NEGATING_SIMPLE_PROPERTY, SIMPLE_PROPERTY); private List keywords; private int numberOfArguments; diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java index 1f1f9c2f2..2bcadd453 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java @@ -23,6 +23,7 @@ import java.util.Iterator; import org.junit.Test; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.repository.query.parser.Part.Type; import org.springframework.data.repository.query.parser.PartTree.OrPart; @@ -127,6 +128,24 @@ public class PartTreeUnitTests { assertThat(tree.getSort(), is(new Sort(Direction.DESC, "firstname"))); } + + @Test + public void parsesWithinCorrectly () { + PartTree tree = new PartTree("findByLocationWithin", User.class); + for (Part part : tree.getParts()) { + assertThat(part.getType(), is(Type.WITHIN)); + assertThat(part.getProperty(), is(new Property("location", User.class))); + } + } + + @Test + public void parsesNearCorrectly () { + PartTree tree = new PartTree("findByLocationNear", User.class); + for (Part part : tree.getParts()) { + assertThat(part.getType(), is(Type.NEAR)); + assertThat(part.getProperty(), is(new Property("location", User.class))); + } + } private void assertPart(PartTree tree, Part[]... parts) { @@ -151,5 +170,6 @@ public class PartTreeUnitTests { String firstname; String lastname; + double[] location; } }