Adapted newly introduced Property abstraction.
Altered JpaQueryCreator to correctly add property traversals and joins based on Property. Added integration tests to verify property traversal on collections and simple properties.
This commit is contained in:
@@ -25,6 +25,7 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQuery;
|
||||
|
||||
|
||||
@@ -56,6 +57,9 @@ public class User {
|
||||
@ManyToMany
|
||||
private Set<Role> roles;
|
||||
|
||||
@ManyToOne
|
||||
private User manager;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new empty instance of {@code User}.
|
||||
@@ -241,6 +245,24 @@ public class User {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the manager
|
||||
*/
|
||||
public User getManager() {
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param manager the manager to set
|
||||
*/
|
||||
public void setManager(User manager) {
|
||||
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
||||
@@ -352,7 +352,7 @@ public class UserRepositoryTests {
|
||||
// Persist
|
||||
flushTestUsers();
|
||||
|
||||
// Fetches first user from .. bdatabase
|
||||
// Fetches first user from database
|
||||
User firstReferenceUser = repository.findById(firstUser.getId());
|
||||
assertEquals(firstUser, firstReferenceUser);
|
||||
|
||||
@@ -686,6 +686,48 @@ public class UserRepositoryTests {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void executesQueryMethodWithDeepTraversalCorrectly()
|
||||
throws Exception {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
firstUser.setManager(secondUser);
|
||||
thirdUser.setManager(firstUser);
|
||||
repository.save(Arrays.asList(firstUser, thirdUser));
|
||||
|
||||
List<User> result = repository.findByManagerLastname("Arrasz");
|
||||
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result, hasItem(firstUser));
|
||||
|
||||
result = repository.findByManagerLastname("Gierke");
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result, hasItem(thirdUser));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void executesFindByColleaguesLastnameCorrectly() throws Exception {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
firstUser.addColleague(secondUser);
|
||||
thirdUser.addColleague(firstUser);
|
||||
repository.save(Arrays.asList(firstUser, thirdUser));
|
||||
|
||||
List<User> result =
|
||||
repository.findByColleaguesLastname(secondUser.getLastname());
|
||||
|
||||
assertThat(result.size(), is(1));
|
||||
assertThat(result, hasItem(firstUser));
|
||||
|
||||
result = repository.findByColleaguesLastname("Gierke");
|
||||
assertThat(result.size(), is(2));
|
||||
assertThat(result, hasItems(thirdUser, secondUser));
|
||||
}
|
||||
|
||||
|
||||
private Page<User> executeSpecWithSort(Sort sort) {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
@@ -184,4 +184,10 @@ public interface UserRepository extends JpaRepository<User, Integer>,
|
||||
|
||||
|
||||
List<User> findByLastnameNot(String lastname);
|
||||
|
||||
|
||||
List<User> findByManagerLastname(String name);
|
||||
|
||||
|
||||
List<User> findByColleaguesLastname(String lastname);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user