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