Search in sources :

Example 6 with WorkspaceVisit

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.

the class WorkspaceVisitDAO method listByUserEntityAndMinVisitsOrderByLastVisit.

public List<WorkspaceVisit> listByUserEntityAndMinVisitsOrderByLastVisit(UserEntity userEntity, Long numVisits, Integer firstResult, Integer maxResults) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<WorkspaceVisit> criteria = criteriaBuilder.createQuery(WorkspaceVisit.class);
    Root<WorkspaceVisit> root = criteria.from(WorkspaceVisit.class);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(WorkspaceVisit_.userEntityId), userEntity.getId()), criteriaBuilder.greaterThanOrEqualTo(root.get(WorkspaceVisit_.numVisits), numVisits)));
    criteria.orderBy(criteriaBuilder.desc(root.get(WorkspaceVisit_.lastVisit)));
    TypedQuery<WorkspaceVisit> query = entityManager.createQuery(criteria);
    if (firstResult != null) {
        query.setFirstResult(firstResult);
    }
    if (maxResults != null) {
        query.setMaxResults(maxResults);
    }
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceVisit(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit)

Example 7 with WorkspaceVisit

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.

the class WorkspaceVisitDAO method create.

public WorkspaceVisit create(UserEntity userEntity, WorkspaceEntity workspaceEntity, Date lastVisit) {
    WorkspaceVisit visit = new WorkspaceVisit();
    visit.setUserEntityId(userEntity.getId());
    visit.setWorkspaceEntityId(workspaceEntity.getId());
    visit.setNumVisits(0l);
    visit.setLastVisit(lastVisit);
    persist(visit);
    return visit;
}
Also used : WorkspaceVisit(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit)

Example 8 with WorkspaceVisit

use of fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit in project muikku by otavanopisto.

the class WorkspaceVisitDAO method listByWorkspaceEntityIdsAndUserEntityAndMinVisitsOrderByLastVisit.

public List<WorkspaceVisit> listByWorkspaceEntityIdsAndUserEntityAndMinVisitsOrderByLastVisit(Collection<Long> workspaceEntityIds, UserEntity userEntity, Long numVisits, Integer firstResult, Integer maxResults) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<WorkspaceVisit> criteria = criteriaBuilder.createQuery(WorkspaceVisit.class);
    Root<WorkspaceVisit> root = criteria.from(WorkspaceVisit.class);
    criteria.select(root);
    if (workspaceEntityIds == null || workspaceEntityIds.isEmpty()) {
        return Collections.emptyList();
    } else {
        criteria.where(criteriaBuilder.and(root.get(WorkspaceVisit_.workspaceEntityId).in(workspaceEntityIds), criteriaBuilder.equal(root.get(WorkspaceVisit_.userEntityId), userEntity.getId()), criteriaBuilder.greaterThanOrEqualTo(root.get(WorkspaceVisit_.numVisits), numVisits)));
    }
    criteria.orderBy(criteriaBuilder.desc(root.get(WorkspaceVisit_.lastVisit)));
    TypedQuery<WorkspaceVisit> query = entityManager.createQuery(criteria);
    if (firstResult != null) {
        query.setFirstResult(firstResult);
    }
    if (maxResults != null) {
        query.setMaxResults(maxResults);
    }
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) WorkspaceVisit(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit)

Aggregations

WorkspaceVisit (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceVisit)8 EntityManager (javax.persistence.EntityManager)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 ArrayList (java.util.ArrayList)2 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1