From dcb97a7f59c949d8e85c40ec5aaf66458f0dcb02 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Wed, 28 Mar 2018 20:36:34 +0200 Subject: [PATCH] [1.2.3a] oidaaaa... tag is vorbei :/ --- .../ass1/jpa/dao/impl/MaterialServerDAO.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java index d1ff753..036e520 100644 --- a/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java +++ b/ass1-jpa/src/main/java/dst/ass1/jpa/dao/impl/MaterialServerDAO.java @@ -3,10 +3,18 @@ package dst.ass1.jpa.dao.impl; import dst.ass1.jpa.dao.IMaterialServerDAO; import dst.ass1.jpa.model.ICourse; import dst.ass1.jpa.model.IMaterialServer; +import dst.ass1.jpa.model.impl.Lesson; +import dst.ass1.jpa.model.impl.Material; import dst.ass1.jpa.model.impl.MaterialServer; +import dst.ass1.jpa.util.Constants; import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.Root; import java.util.Collection; +import java.util.List; public class MaterialServerDAO extends GenericDAO implements IMaterialServerDAO { public MaterialServerDAO(EntityManager em) { @@ -15,7 +23,17 @@ public class MaterialServerDAO extends GenericDAO findMaterialServersForCourse(ICourse course) { - return null; - } + CriteriaBuilder b = em.getCriteriaBuilder(); + CriteriaQuery q = b.createQuery(IMaterialServer.class); + + Root root = q.from(MaterialServer.class); + Join materials = root.join(Constants.A_MATERIALS); + Join lessons = materials.join(Constants.M_MATERIAL_LESSON); + q.select(root).distinct(true); + if (course != null) q.where(lessons.in(course.getLessons())); + + List a = em.createQuery(q).getResultList(); + return a; + } } -- 2.43.0