Search in sources :

Example 1 with BooleanPredicate

use of fi.otavanopisto.muikku.model.base.BooleanPredicate in project muikku by otavanopisto.

the class WorkspaceFolderDAO method listByHiddenAndParentAndFolderType.

public List<WorkspaceFolder> listByHiddenAndParentAndFolderType(BooleanPredicate hidden, WorkspaceNode parent, WorkspaceFolderType folderType) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<WorkspaceFolder> criteria = criteriaBuilder.createQuery(WorkspaceFolder.class);
    Root<WorkspaceFolder> root = criteria.from(WorkspaceFolder.class);
    criteria.select(root);
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(criteriaBuilder.equal(root.get(WorkspaceFolder_.parent), parent));
    predicates.add(criteriaBuilder.equal(root.get(WorkspaceFolder_.folderType), folderType));
    if (hidden != BooleanPredicate.IGNORE) {
        predicates.add(criteriaBuilder.equal(root.get(WorkspaceFolder_.hidden), hidden.asBoolean()));
    }
    criteria.where(criteriaBuilder.and(predicates.toArray(new Predicate[0])));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) WorkspaceFolder(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder) BooleanPredicate(fi.otavanopisto.muikku.model.base.BooleanPredicate) Predicate(javax.persistence.criteria.Predicate)

Example 2 with BooleanPredicate

use of fi.otavanopisto.muikku.model.base.BooleanPredicate in project muikku by otavanopisto.

the class WorkspaceMaterialDAO method listByHiddenAndAssignmentTypeAndParents.

public List<WorkspaceMaterial> listByHiddenAndAssignmentTypeAndParents(BooleanPredicate hidden, WorkspaceMaterialAssignmentType assignmentType, List<WorkspaceNode> parents) {
    if (parents == null || parents.isEmpty()) {
        return Collections.emptyList();
    }
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<WorkspaceMaterial> criteria = criteriaBuilder.createQuery(WorkspaceMaterial.class);
    Root<WorkspaceMaterial> root = criteria.from(WorkspaceMaterial.class);
    criteria.select(root);
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(criteriaBuilder.equal(root.get(WorkspaceMaterial_.assignmentType), assignmentType));
    predicates.add(root.get(WorkspaceMaterial_.parent).in(parents));
    if (hidden != BooleanPredicate.IGNORE) {
        predicates.add(criteriaBuilder.equal(root.get(WorkspaceMaterial_.hidden), hidden.asBoolean()));
    }
    criteria.where(criteriaBuilder.and(predicates.toArray(new Predicate[0])));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) WorkspaceMaterial(fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial) BooleanPredicate(fi.otavanopisto.muikku.model.base.BooleanPredicate) Predicate(javax.persistence.criteria.Predicate)

Aggregations

BooleanPredicate (fi.otavanopisto.muikku.model.base.BooleanPredicate)2 ArrayList (java.util.ArrayList)2 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Predicate (javax.persistence.criteria.Predicate)2 WorkspaceFolder (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceFolder)1 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)1