From 44979ac2464ed2d758df66c3af104adfd4c7a86c Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 23 Feb 2011 10:25:18 +0100 Subject: [PATCH] DATAJPA-30 - Added support for 'NotIn' keyword. --- .../jpa/repository/query/JpaQueryCreator.java | 2 ++ src/main/resources/changelog.txt | 5 +++++ .../repository/UserRepositoryFinderTests.java | 18 +++++++++++++++--- .../jpa/repository/sample/UserRepository.java | 4 ++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java index d3962bc15..f4b4c3670 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java @@ -178,6 +178,8 @@ public class JpaQueryCreator extends return path.isNull(); case IS_NOT_NULL: return path.isNotNull(); + case NOT_IN: + return builder.not(path.in(nextAsCollection(iterator))); case IN: return path.in(nextAsCollection(iterator)); case LIKE: diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index b110c4f66..3dc007164 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -1,6 +1,11 @@ Spring Data JPA Changelog ============================================= +Changes in version 1.0.0.M2 +---------------------------------------- +* Added support for 'Distinct' (DATACMNS-15) +* Added support for 'In' and 'NotIn' (DATAJPA-30) + Changes in version 1.0.0.M1 (2011-02-10) - https://jira.springsource.org/browse/DATAJPA/fixforversion/11786 ---------------------------------------- * Moved JPA sepcific code from Hades into Spring Data JPA (functional equivalent of Hades 2.0.2) building on common functionality in Spring Data Commons \ No newline at end of file diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java index 1a997e095..f9373fb73 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryFinderTests.java @@ -18,6 +18,7 @@ package org.springframework.data.jpa.repository; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; +import java.util.Arrays; import java.util.List; import org.junit.Before; @@ -112,7 +113,7 @@ public class UserRepositoryFinderTests { @Test - public void executesPagingMethodToPageCorrectly() throws Exception { + public void executesPagingMethodToPageCorrectly() { Page page = userRepository @@ -124,7 +125,7 @@ public class UserRepositoryFinderTests { @Test - public void executesPagingMethodToListCorrectly() throws Exception { + public void executesPagingMethodToListCorrectly() { List list = userRepository.findByFirstname("Carter", new PageRequest(0, 1)); @@ -133,7 +134,7 @@ public class UserRepositoryFinderTests { @Test - public void testname() throws Exception { + public void executesInKeywordForPageCorrectly() { Page page = userRepository.findByFirstnameIn(new PageRequest(0, 1), "Dave", @@ -143,4 +144,15 @@ public class UserRepositoryFinderTests { assertThat(page.getTotalElements(), is(2L)); assertThat(page.getTotalPages(), is(2)); } + + + @Test + public void executesNotInQueryCorrectly() throws Exception { + + List result = + userRepository.findByFirstnameNotIn(Arrays.asList("Dave", + "Carter")); + assertThat(result.size(), is(1)); + assertThat(result.get(0), is(oliver)); + } } diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java index e8aacf9f3..d1baa48d2 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java @@ -15,6 +15,7 @@ */ package org.springframework.data.jpa.repository.sample; +import java.util.Collection; import java.util.List; import javax.persistence.QueryHint; @@ -136,6 +137,9 @@ public interface UserRepository extends JpaRepository, Page findByFirstnameIn(Pageable pageable, String... firstnames); + List findByFirstnameNotIn(Collection firstnames); + + /** * Manipulating query to set all {@link User}'s names to the given one. *