DATAJPA-180 - Added support for StartingWith, EndingWith, Containing to query creator.
The query derivation mechanism now supports StartingWith, EndingWith and Containing as keywords using the Criteria API's like predicate and massaging the given parameters accordingly. Refactored parameter binding for CriteriaQuery instances to encapsulate the knowledge of how to massage a parameter based on the type.
This commit is contained in:
@@ -779,6 +779,42 @@ public class UserRepositoryTests {
|
||||
assertThat(result, hasItems(firstUser, secondUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-180
|
||||
*/
|
||||
@Test
|
||||
public void executesFinderWithStartingWithCorrectly() {
|
||||
|
||||
flushTestUsers();
|
||||
List<User> result = repository.findByFirstnameStartingWith("Oli");
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result, hasItem(firstUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-180
|
||||
*/
|
||||
@Test
|
||||
public void executesFinderWithEndingWithCorrectly() {
|
||||
|
||||
flushTestUsers();
|
||||
List<User> result = repository.findByFirstnameEndingWith("er");
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result, hasItem(firstUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-180
|
||||
*/
|
||||
@Test
|
||||
public void executesFinderWithContainingCorrectly() {
|
||||
|
||||
flushTestUsers();
|
||||
List<User> result = repository.findByFirstnameContaining("a");
|
||||
assertThat(result.size(), is(2));
|
||||
assertThat(result, hasItems(secondUser, thirdUser));
|
||||
}
|
||||
|
||||
protected void flushTestUsers() {
|
||||
|
||||
firstUser = repository.save(firstUser);
|
||||
|
||||
@@ -224,4 +224,20 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
|
||||
* @see DATAJPA-188
|
||||
*/
|
||||
List<User> findByCreatedAtAfter(Date date);
|
||||
|
||||
/**
|
||||
* @see DATAJPA-180
|
||||
*/
|
||||
List<User> findByFirstnameStartingWith(String firstname);
|
||||
|
||||
/**
|
||||
* @see DATAJPA-180
|
||||
*/
|
||||
List<User> findByFirstnameEndingWith(String firstname);
|
||||
|
||||
/**
|
||||
* @see DATAJPA-180
|
||||
*/
|
||||
List<User> findByFirstnameContaining(String firstname);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user