Search in sources :

Example 6 with UserSpecification

use of org.baeldung.persistence.dao.UserSpecification in project tutorials by eugenp.

the class UserController method resolveSpecificationFromInfixExpr.

protected Specification<User> resolveSpecificationFromInfixExpr(String searchParameters) {
    CriteriaParser parser = new CriteriaParser();
    GenericSpecificationsBuilder<User> specBuilder = new GenericSpecificationsBuilder<>();
    return specBuilder.build(parser.parse(searchParameters), UserSpecification::new);
}
Also used : CriteriaParser(org.baeldung.web.util.CriteriaParser) User(org.baeldung.persistence.model.User) MyUser(org.baeldung.persistence.model.MyUser) UserSpecification(org.baeldung.persistence.dao.UserSpecification) GenericSpecificationsBuilder(org.baeldung.persistence.dao.GenericSpecificationsBuilder)

Example 7 with UserSpecification

use of org.baeldung.persistence.dao.UserSpecification in project tutorials by eugenp.

the class JPASpecificationIntegrationTest method givenMinAge_whenGettingListOfUsers_thenCorrect.

@Test
public void givenMinAge_whenGettingListOfUsers_thenCorrect() {
    final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("age", SearchOperation.GREATER_THAN, "25"));
    final List<User> results = repository.findAll(Specifications.where(spec));
    assertThat(userTom, isIn(results));
    assertThat(userJohn, not(isIn(results)));
}
Also used : UserSpecification(org.baeldung.persistence.dao.UserSpecification) User(org.baeldung.persistence.model.User) SpecSearchCriteria(org.baeldung.web.util.SpecSearchCriteria) Test(org.junit.Test)

Example 8 with UserSpecification

use of org.baeldung.persistence.dao.UserSpecification in project tutorials by eugenp.

the class JPASpecificationIntegrationTest method givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect.

@Test
public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() {
    final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.ENDS_WITH, "n"));
    final List<User> results = repository.findAll(spec);
    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
Also used : UserSpecification(org.baeldung.persistence.dao.UserSpecification) User(org.baeldung.persistence.model.User) SpecSearchCriteria(org.baeldung.web.util.SpecSearchCriteria) Test(org.junit.Test)

Example 9 with UserSpecification

use of org.baeldung.persistence.dao.UserSpecification in project tutorials by eugenp.

the class JPASpecificationIntegrationTest method givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect.

@Test
public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() {
    final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.STARTS_WITH, "jo"));
    final List<User> results = repository.findAll(spec);
    assertThat(userJohn, isIn(results));
    assertThat(userTom, not(isIn(results)));
}
Also used : UserSpecification(org.baeldung.persistence.dao.UserSpecification) User(org.baeldung.persistence.model.User) SpecSearchCriteria(org.baeldung.web.util.SpecSearchCriteria) Test(org.junit.Test)

Aggregations

UserSpecification (org.baeldung.persistence.dao.UserSpecification)9 User (org.baeldung.persistence.model.User)9 SpecSearchCriteria (org.baeldung.web.util.SpecSearchCriteria)8 Test (org.junit.Test)8 GenericSpecificationsBuilder (org.baeldung.persistence.dao.GenericSpecificationsBuilder)2 CriteriaParser (org.baeldung.web.util.CriteriaParser)2 MyUser (org.baeldung.persistence.model.MyUser)1 Specification (org.springframework.data.jpa.domain.Specification)1