DATAJPA-30 - Added support for 'NotIn' keyword.

This commit is contained in:
Oliver Gierke
2011-02-23 10:25:18 +01:00
parent e48ec42be6
commit 44979ac246
4 changed files with 26 additions and 3 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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<User> page =
userRepository
@@ -124,7 +125,7 @@ public class UserRepositoryFinderTests {
@Test
public void executesPagingMethodToListCorrectly() throws Exception {
public void executesPagingMethodToListCorrectly() {
List<User> 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<User> 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<User> result =
userRepository.findByFirstnameNotIn(Arrays.asList("Dave",
"Carter"));
assertThat(result.size(), is(1));
assertThat(result.get(0), is(oliver));
}
}

View File

@@ -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<User, Integer>,
Page<User> findByFirstnameIn(Pageable pageable, String... firstnames);
List<User> findByFirstnameNotIn(Collection<String> firstnames);
/**
* Manipulating query to set all {@link User}'s names to the given one.
*