Rev 1395 | Rev 1399 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1332 | jmachado | 1 | package pt.estgp.estgweb.domain.dao.impl; |
2 | |||
1338 | jmachado | 3 | import jomm.dao.impl.AbstractDao; |
4 | import org.hibernate.Query; |
||
1380 | jmachado | 5 | import org.hibernate.criterion.Projections; |
1333 | jmachado | 6 | import pt.estgp.estgweb.domain.QuestionarioPedagogicoCursoAfeto; |
7 | |||
8 | import java.util.List; |
||
9 | |||
10 | import static org.hibernate.criterion.Restrictions.eq; |
||
11 | |||
1332 | jmachado | 12 | /** |
13 | * Created by jorgemachado on 24/03/16. |
||
14 | */ |
||
15 | public class QuestionarioPedagogicoCursoAfetoDaoImpl extends QuestionarioPedagogicoCursoAfetoDao{ |
||
16 | |||
17 | public static QuestionarioPedagogicoCursoAfetoDaoImpl getInstance() { |
||
18 | if (myInstance == null) |
||
19 | myInstance = new QuestionarioPedagogicoCursoAfetoDaoImpl(); |
||
20 | return (QuestionarioPedagogicoCursoAfetoDaoImpl) myInstance; |
||
21 | } |
||
1333 | jmachado | 22 | |
23 | public List<QuestionarioPedagogicoCursoAfeto> find(long questionarioId,1.5.0/docs/api/java/lang/String.html">String cursoCode) |
||
24 | { |
||
25 | return createCriteria() |
||
26 | .add(eq("questionario.id", questionarioId)) |
||
27 | .add(eq("codigoCurso", cursoCode)) |
||
28 | .list(); |
||
29 | } |
||
30 | public List<QuestionarioPedagogicoCursoAfeto> find(long questionarioId) |
||
31 | { |
||
32 | return createCriteria() |
||
33 | .add(eq("questionario.id", questionarioId)) |
||
34 | .list(); |
||
35 | } |
||
1338 | jmachado | 36 | |
1380 | jmachado | 37 | public List<Long> findCursosAfetosIds(long questionarioId) |
38 | { |
||
39 | return createCriteria() |
||
40 | .setProjection(Projections.distinct(Projections.property("id"))) |
||
41 | .add(eq("questionario.id", questionarioId)) |
||
42 | .list(); |
||
43 | } |
||
1338 | jmachado | 44 | |
45 | |||
46 | |||
1380 | jmachado | 47 | |
1338 | jmachado | 48 | public static class CourseStatsVars |
49 | { |
||
50 | public long unidades; |
||
51 | public long marcadas; |
||
52 | public long observadas; |
||
1378 | jmachado | 53 | public long porVerProfs; |
1338 | jmachado | 54 | public long porVer; |
55 | public long naoUsadas; |
||
56 | } |
||
57 | |||
58 | public CourseStatsVars loadStats(long cursoAfetoId) |
||
59 | { |
||
60 | CourseStatsVars courseStatsVars = new CourseStatsVars(); |
||
61 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
||
62 | " sum (case when u.vista = false then 1 else 0 end) AS porVer " + |
||
1378 | jmachado | 63 | ",sum (case when u.vistaProfs = false then 1 else 0 end) AS porVerProfs " + |
1338 | jmachado | 64 | ",sum (case when u.usar = false then 1 else 0 end) AS naoUsadas " + |
65 | ",sum (case when u.marked = true then 1 else 0 end) AS marked " + |
||
66 | ",sum (case when u.obs is not NULL and u.obs != '' then 1 else 0 end) AS observadas " + |
||
67 | ",count(distinct u.id) AS unidades " + |
||
68 | "from " + QuestionarioPedagogicoCursoAfeto.class.getName() + " c " + |
||
69 | "JOIN c.unidadesAfetas u " + |
||
70 | "WHERE c.id = :id " + |
||
71 | "GROUP BY c.id"); |
||
72 | |||
73 | q.setLong("id",cursoAfetoId); |
||
74 | 5+0%2Fdocs%2Fapi+Object">Object[] results = (5+0%2Fdocs%2Fapi+Object">Object[]) q.uniqueResult(); |
||
75 | |||
1396 | jmachado | 76 | if(results != null && results[0] != null) |
1395 | jmachado | 77 | { |
78 | courseStatsVars.porVer = (1.5.0/docs/api/java/lang/Long.html">Long) results[0]; |
||
79 | courseStatsVars.porVerProfs = (1.5.0/docs/api/java/lang/Long.html">Long) results[1]; |
||
80 | courseStatsVars.naoUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[2]; |
||
81 | courseStatsVars.marcadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[3]; |
||
82 | courseStatsVars.observadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[4]; |
||
83 | courseStatsVars.unidades = (1.5.0/docs/api/java/lang/Long.html">Long) results[5]; |
||
84 | } |
||
85 | |||
1338 | jmachado | 86 | return courseStatsVars; |
87 | } |
||
1332 | jmachado | 88 | } |