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