use of org.baeldung.persistence.dao.MyUserPredicatesBuilder in project tutorials by eugenp.
the class UserController method findAllByQuerydsl.
@RequestMapping(method = RequestMethod.GET, value = "/myusers")
@ResponseBody
public Iterable<MyUser> findAllByQuerydsl(@RequestParam(value = "search") String search) {
MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder();
if (search != null) {
Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),");
Matcher matcher = pattern.matcher(search + ",");
while (matcher.find()) {
builder.with(matcher.group(1), matcher.group(2), matcher.group(3));
}
}
BooleanExpression exp = builder.build();
return myUserRepository.findAll(exp);
}
use of org.baeldung.persistence.dao.MyUserPredicatesBuilder in project tutorials by eugenp.
the class JPAQuerydslIntegrationTest method givenLastAndAge_whenGettingListOfUsers_thenCorrect.
@Test
public void givenLastAndAge_whenGettingListOfUsers_thenCorrect() {
final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("lastName", ":", "doe").with("age", ">", "25");
final Iterable<MyUser> results = repo.findAll(builder.build());
assertThat(results, contains(userTom));
assertThat(results, not(contains(userJohn)));
}
use of org.baeldung.persistence.dao.MyUserPredicatesBuilder in project tutorials by eugenp.
the class JPAQuerydslIntegrationTest method givenPartialFirst_whenGettingListOfUsers_thenCorrect.
@Test
public void givenPartialFirst_whenGettingListOfUsers_thenCorrect() {
final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "jo");
final Iterable<MyUser> results = repo.findAll(builder.build());
assertThat(results, contains(userJohn));
assertThat(results, not(contains(userTom)));
}
use of org.baeldung.persistence.dao.MyUserPredicatesBuilder in project tutorials by eugenp.
the class JPAQuerydslIntegrationTest method givenWrongFirstAndLast_whenGettingListOfUsers_thenCorrect.
@Test
public void givenWrongFirstAndLast_whenGettingListOfUsers_thenCorrect() {
final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "adam").with("lastName", ":", "fox");
final Iterable<MyUser> results = repo.findAll(builder.build());
assertThat(results, emptyIterable());
}
use of org.baeldung.persistence.dao.MyUserPredicatesBuilder in project tutorials by eugenp.
the class JPAQuerydslIntegrationTest method givenFirstAndLastName_whenGettingListOfUsers_thenCorrect.
@Test
public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() {
final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "john").with("lastName", ":", "doe");
final Iterable<MyUser> results = repo.findAll(builder.build());
assertThat(results, contains(userJohn));
assertThat(results, not(contains(userTom)));
}
Aggregations