Search in sources :

Example 1 with WorkspaceJournalEntry_

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();
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Date(java.util.Date) WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) Collection(java.util.Collection) Set(java.util.Set) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) TypedQuery(javax.persistence.TypedQuery) List(java.util.List) WorkspaceJournalEntry_(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry_) CorePluginsDAO(fi.otavanopisto.muikku.plugins.CorePluginsDAO) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceJournalEntry(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry) EntityManager(javax.persistence.EntityManager)

Aggregations

UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 CorePluginsDAO (fi.otavanopisto.muikku.plugins.CorePluginsDAO)1 WorkspaceJournalEntry (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry)1 WorkspaceJournalEntry_ (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceJournalEntry_)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 EntityManager (javax.persistence.EntityManager)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Root (javax.persistence.criteria.Root)1