Search in sources :

Example 21 with JPAQuery

use of com.querydsl.jpa.impl.JPAQuery 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)

Example 22 with JPAQuery

use of com.querydsl.jpa.impl.JPAQuery in project tutorials by eugenp.

the class PersonDaoImpl method findMaxAgeByName.

@Override
public Map<String, Integer> findMaxAgeByName() {
    final JPAQuery<Person> query = new JPAQuery<>(em);
    final QPerson person = QPerson.person;
    return query.from(person).transform(GroupBy.groupBy(person.firstname).as(GroupBy.max(person.age)));
}
Also used : QPerson(org.baeldung.entity.QPerson) Person(org.baeldung.entity.Person) QPerson(org.baeldung.entity.QPerson) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 23 with JPAQuery

use of com.querydsl.jpa.impl.JPAQuery in project Settler by EmhyrVarEmreis.

the class TransactionService method getMostUsedUsers.

public ResponseEntity<List<UserListDTO>> getMostUsedUsers(Long count) {
    QUser user = QUser.user;
    QTransaction transaction = QTransaction.transaction;
    QRedistribution redistribution = QRedistribution.redistribution;
    List<User> userList = new JPAQuery<>(entityManager).from(user).select(user).where(user.id.in(JPAExpressions.selectFrom(transaction).select(redistribution.id.user.id).leftJoin(redistribution).on(redistribution.id.parent.id.eq(transaction.id)).where(transaction.creator.id.eq(Security.currentUser().getId())).groupBy(redistribution.id.user.id).orderBy(redistribution.id.user.id.count().desc()).limit(count))).fetch();
    Type listType = new TypeToken<List<UserListDTO>>() {
    }.getType();
    List<UserListDTO> userListDTOList = getModelMapper().map(userList, listType);
    return new ResponseEntity<>(userListDTOList, HttpStatus.OK);
}
Also used : TransactionType(pl.morecraft.dev.settler.domain.dictionaries.TransactionType) OperationType(pl.morecraft.dev.settler.domain.dictionaries.OperationType) RedistributionType(pl.morecraft.dev.settler.domain.dictionaries.RedistributionType) Type(java.lang.reflect.Type) ResponseEntity(org.springframework.http.ResponseEntity) UserListDTO(pl.morecraft.dev.settler.web.dto.UserListDTO) ArrayList(java.util.ArrayList) List(java.util.List) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 24 with JPAQuery

use of com.querydsl.jpa.impl.JPAQuery in project Settler by EmhyrVarEmreis.

the class UserService method getUsersWithValue.

public ResponseEntity<List<UserWithValueDTO>> getUsersWithValue(Long userId) {
    getPermissionManager().authorizeGlobalAdmin();
    if (Objects.isNull(userId) || userId < 0) {
        userId = Security.currentUser().getId();
    }
    QUser user = QUser.user;
    QTransaction transaction = QTransaction.transaction;
    List<Tuple> fetch = new JPAQuery<>(entityManager).from(user, transaction).select(user, transaction.value.sum()).where(transaction.creator.id.eq(userId)).where(user.id.ne(userId)).where(transaction.owners.any().id.user.eq(user).or(transaction.contractors.any().id.user.eq(user))).groupBy(user.id, user.firstName, user.lastName, user.email, user.created, user.avatar, user.login, user.accountExpireDate).orderBy(transaction.value.sum().desc()).fetch();
    ModelMapper preparedModelMapper = getModelMapper();
    List<UserWithValueDTO> userWithValueDTOList = new ArrayList<>(fetch.size());
    for (Tuple tuple : fetch) {
        User u = tuple.get(user);
        Double d = tuple.get(transaction.value.sum());
        if (Objects.nonNull(u)) {
            userWithValueDTOList.add(new UserWithValueDTO(userId, preparedModelMapper.map(u, String.class), d));
        }
    }
    return new ResponseEntity<>(userWithValueDTOList, HttpStatus.OK);
}
Also used : QUser(pl.morecraft.dev.settler.domain.QUser) QTransaction(pl.morecraft.dev.settler.domain.QTransaction) ResponseEntity(org.springframework.http.ResponseEntity) User(pl.morecraft.dev.settler.domain.User) QUser(pl.morecraft.dev.settler.domain.QUser) ArrayList(java.util.ArrayList) JPAQuery(com.querydsl.jpa.impl.JPAQuery) Tuple(com.querydsl.core.Tuple) ModelMapper(org.modelmapper.ModelMapper)

Aggregations

JPAQuery (com.querydsl.jpa.impl.JPAQuery)24 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)9 List (java.util.List)9 BooleanBuilder (com.querydsl.core.BooleanBuilder)7 ArrayList (java.util.ArrayList)6 Person (org.baeldung.entity.Person)5 QPerson (org.baeldung.entity.QPerson)5 Predicate (com.querydsl.core.types.Predicate)4 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)4 JPQLQuery (com.querydsl.jpa.JPQLQuery)3 Stopwatch (com.google.common.base.Stopwatch)2 ConstructorExpression (com.querydsl.core.types.ConstructorExpression)2 Expression (com.querydsl.core.types.Expression)2 Projections (com.querydsl.core.types.Projections)2 JPAExpressions (com.querydsl.jpa.JPAExpressions)2 DateTimeUtil (com.thinkbiganalytics.DateTimeUtil)2 Alert (com.thinkbiganalytics.alerts.api.Alert)2 AlertProvider (com.thinkbiganalytics.alerts.api.AlertProvider)2 AlertManager (com.thinkbiganalytics.alerts.spi.AlertManager)2 DefaultAlertChangeEventContent (com.thinkbiganalytics.alerts.spi.DefaultAlertChangeEventContent)2