DATAJPA-92 - Added support for IgnoreCase keyword.

The query creation subsystem now supports using IgnoreCase when referencing String parameters, e.g.:

  findByUsernameIgnoreCase(String username);

Both 'IgnoreCase' and 'IgnoringCase' are supported. If you'd like to entirely ignore cases for all String property references add 'AllIgnoreCase' or 'AllIgnoringCase' to the query method.
This commit is contained in:
Phil Webb
2011-08-24 17:19:15 +01:00
committed by Oliver Gierke
parent b6b386893e
commit 5b9e959b3e
3 changed files with 137 additions and 42 deletions

View File

@@ -155,4 +155,26 @@ public class UserRepositoryFinderTests {
assertThat(result.size(), is(1));
assertThat(result.get(0), is(oliver));
}
@Test
public void findsByLastnameIgnoringCase() throws Exception {
List<User> result = userRepository.findByLastnameIgnoringCase("BeAUfoRd");
assertThat(result.size(), is(1));
assertThat(result.get(0), is(carter));
}
@Test
public void findsByLastnameIgnoringCaseLike() throws Exception {
List<User> result = userRepository.findByLastnameIgnoringCaseLike("BeAUfo%");
assertThat(result.size(), is(1));
assertThat(result.get(0), is(carter));
}
@Test
public void findByLastnameAndFirstnameAllIgnoringCase() throws Exception {
List<User> result = userRepository.findByLastnameAndFirstnameAllIgnoringCase("MaTTheWs","DaVe");
assertThat(result.size(), is(1));
assertThat(result.get(0), is(dave));
}
}

View File

@@ -215,4 +215,15 @@ public interface UserRepository extends JpaRepository<User, Integer>,
List<User> findBySpringDataNamedQuery(String lastname);
List<User> findByLastnameIgnoringCase(String lastname);
List<User> findByLastnameIgnoringCaseLike(String lastname);
List<User> findByLastnameAndFirstnameAllIgnoringCase(String lastname,
String firstname);
}