DATAJPA-132 - Implemented handling of True and False keywords on query creation.
Query derivation mechanism now supports True and False as keywords in finder methods:
class User {
boolean active;
}
interface UserRepository<User, Long> {
List<User> findByActiveTrue() ;
}
This commit is contained in:
@@ -46,6 +46,7 @@ public class User {
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private int age;
|
||||
private boolean active;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
private String emailAddress;
|
||||
@@ -81,6 +82,7 @@ public class User {
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.emailAddress = emailAddress;
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,6 +175,20 @@ public class User {
|
||||
this.emailAddress = emailAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param active the active to set
|
||||
*/
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the active
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user's roles.
|
||||
*
|
||||
|
||||
@@ -694,6 +694,36 @@ public class UserRepositoryTests {
|
||||
assertThat(result.size(), is(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-132
|
||||
*/
|
||||
@Test
|
||||
public void executesFinderWithTrueKeywordCorrectly() {
|
||||
|
||||
flushTestUsers();
|
||||
firstUser.setActive(false);
|
||||
repository.save(firstUser);
|
||||
|
||||
List<User> result = repository.findByActiveTrue();
|
||||
assertThat(result.size(), is(2));
|
||||
assertThat(result, hasItems(secondUser, thirdUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-132
|
||||
*/
|
||||
@Test
|
||||
public void executesFinderWithFalseKeywordCorrectly() {
|
||||
|
||||
flushTestUsers();
|
||||
firstUser.setActive(false);
|
||||
repository.save(firstUser);
|
||||
|
||||
List<User> result = repository.findByActiveFalse();
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result, hasItem(firstUser));
|
||||
}
|
||||
|
||||
private void flushTestUsers() {
|
||||
|
||||
firstUser = repository.save(firstUser);
|
||||
|
||||
@@ -197,4 +197,14 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
|
||||
*/
|
||||
@Query(value = "SELECT * FROM User WHERE lastname = ?1", nativeQuery = true)
|
||||
List<User> findNativeByLastname(String lastname);
|
||||
|
||||
/**
|
||||
* @see DATAJPA-132
|
||||
*/
|
||||
List<User> findByActiveTrue();
|
||||
|
||||
/**
|
||||
* @see DATAJPA-132
|
||||
*/
|
||||
List<User> findByActiveFalse();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user