Search in sources :

Example 6 with ForumMessage

use of fi.otavanopisto.muikku.plugins.forum.model.ForumMessage in project muikku by otavanopisto.

the class ForumMessageDAO method listByWorkspace.

public List<ForumMessage> listByWorkspace(WorkspaceEntity workspace) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<ForumMessage> criteria = criteriaBuilder.createQuery(ForumMessage.class);
    Root<ForumMessage> root = criteria.from(ForumMessage.class);
    Root<WorkspaceForumArea> root2 = criteria.from(WorkspaceForumArea.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root2.get(WorkspaceForumArea_.workspace), workspace.getId()), criteriaBuilder.equal(root2.get(WorkspaceForumArea_.id), root.get(ForumMessage_.forumArea)), criteriaBuilder.equal(root.get(ForumMessage_.archived), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) EntityManager(javax.persistence.EntityManager) ForumMessage(fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)

Example 7 with ForumMessage

use of fi.otavanopisto.muikku.plugins.forum.model.ForumMessage in project muikku by otavanopisto.

the class ForumMessageDAO method countByWorkspaceEntityAndCreator.

public Long countByWorkspaceEntityAndCreator(Long workspaceEntityId, Long creatorId) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
    Root<ForumMessage> root = criteria.from(ForumMessage.class);
    Root<WorkspaceForumArea> workspaceAreaJoin = criteria.from(WorkspaceForumArea.class);
    criteria.select(criteriaBuilder.count(root));
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(workspaceAreaJoin.get(WorkspaceForumArea_.workspace), workspaceEntityId), criteriaBuilder.equal(workspaceAreaJoin.get(WorkspaceForumArea_.id), root.get(ForumMessage_.forumArea)), criteriaBuilder.equal(root.get(ForumMessage_.creator), creatorId), criteriaBuilder.equal(root.get(ForumMessage_.archived), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getSingleResult();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) EntityManager(javax.persistence.EntityManager) ForumMessage(fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)

Aggregations

ForumMessage (fi.otavanopisto.muikku.plugins.forum.model.ForumMessage)7 EntityManager (javax.persistence.EntityManager)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)3 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)1 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)1 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1