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();
}
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)));
}
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);
}
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);
}
Aggregations