use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry_ in project muikku by otavanopisto.
the class WorkspaceJournalEntryDAO method listByWorkspaceEntityAndUserEntities.
public List<WorkspaceJournalEntry> listByWorkspaceEntityAndUserEntities(WorkspaceEntity workspaceEntity, Collection<UserEntity> userEntities, int firstResult, int maxResults) {
EntityManager entityManager = getEntityManager();
Set<Long> userEntityIds = userEntities.stream().map(userEntity -> userEntity.getId()).collect(Collectors.toSet());
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<WorkspaceJournalEntry> criteria = criteriaBuilder.createQuery(WorkspaceJournalEntry.class);
Root<WorkspaceJournalEntry> root = criteria.from(WorkspaceJournalEntry.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.workspaceEntityId), workspaceEntity.getId()), root.get(WorkspaceJournalEntry_.userEntityId).in(userEntityIds), criteriaBuilder.equal(root.get(WorkspaceJournalEntry_.archived), Boolean.FALSE)));
criteria.orderBy(criteriaBuilder.desc(root.get(WorkspaceJournalEntry_.created)));
TypedQuery<WorkspaceJournalEntry> query = entityManager.createQuery(criteria);
query.setFirstResult(firstResult);
query.setMaxResults(maxResults);
return query.getResultList();
}
Aggregations