Search in sources :

Example 1 with Person

use of org.baeldung.entity.Person in project tutorials by eugenp.

the class PersonDaoImpl method findPersonsByFirstnameAndSurnameQueryDSL.

@Override
public List<Person> findPersonsByFirstnameAndSurnameQueryDSL(final String firstname, final String surname) {
    final JPAQuery<Person> query = new JPAQuery<>(em);
    final QPerson person = QPerson.person;
    return query.from(person).where(person.firstname.eq(firstname).and(person.surname.eq(surname))).fetch();
}
Also used : QPerson(org.baeldung.entity.QPerson) Person(org.baeldung.entity.Person) QPerson(org.baeldung.entity.QPerson) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 2 with Person

use of org.baeldung.entity.Person in project tutorials by eugenp.

the class PersonDaoImpl method findPersonsByFirstnameInDescendingOrderQueryDSL.

@Override
public List<Person> findPersonsByFirstnameInDescendingOrderQueryDSL(final String firstname) {
    final JPAQuery<Person> query = new JPAQuery<>(em);
    final QPerson person = QPerson.person;
    return query.from(person).where(person.firstname.eq(firstname)).orderBy(person.surname.desc()).fetch();
}
Also used : QPerson(org.baeldung.entity.QPerson) Person(org.baeldung.entity.Person) QPerson(org.baeldung.entity.QPerson) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 3 with Person

use of org.baeldung.entity.Person in project tutorials by eugenp.

the class PersonDaoIntegrationTest method testMaxAge.

@Test
public void testMaxAge() {
    personDao.save(new Person("Kent", "Gamma", 20));
    personDao.save(new Person("Ralph", "Johnson", 35));
    personDao.save(new Person("Kent", "Zivago", 30));
    final int maxAge = personDao.findMaxAge();
    Assert.assertTrue(maxAge == 35);
}
Also used : Person(org.baeldung.entity.Person) Test(org.junit.Test)

Example 4 with Person

use of org.baeldung.entity.Person in project tutorials by eugenp.

the class PersonDaoImpl method findMaxAge.

@Override
public int findMaxAge() {
    final JPAQuery<Person> query = new JPAQuery<>(em);
    final QPerson person = QPerson.person;
    return query.from(person).select(person.age.max()).fetchFirst();
}
Also used : QPerson(org.baeldung.entity.QPerson) Person(org.baeldung.entity.Person) QPerson(org.baeldung.entity.QPerson) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 5 with Person

use of org.baeldung.entity.Person in project tutorials by eugenp.

the class PersonDaoImpl method findPersonsByFirstnameQueryDSL.

@Override
public List<Person> findPersonsByFirstnameQueryDSL(final String firstname) {
    final JPAQuery<Person> query = new JPAQuery<>(em);
    final QPerson person = QPerson.person;
    return query.from(person).where(person.firstname.eq(firstname)).fetch();
}
Also used : QPerson(org.baeldung.entity.QPerson) Person(org.baeldung.entity.Person) QPerson(org.baeldung.entity.QPerson) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Aggregations

Person (org.baeldung.entity.Person)10 JPAQuery (com.querydsl.jpa.impl.JPAQuery)5 QPerson (org.baeldung.entity.QPerson)5 Test (org.junit.Test)5