Rev 1333 | Rev 1378 | 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; |
||
1333 | jmachado | 5 | import pt.estgp.estgweb.domain.QuestionarioPedagogicoCursoAfeto; |
6 | |||
7 | import java.util.List; |
||
8 | |||
9 | import static org.hibernate.criterion.Restrictions.eq; |
||
10 | |||
1332 | jmachado | 11 | /** |
12 | * Created by jorgemachado on 24/03/16. |
||
13 | */ |
||
14 | public class QuestionarioPedagogicoCursoAfetoDaoImpl extends QuestionarioPedagogicoCursoAfetoDao{ |
||
15 | |||
16 | public static QuestionarioPedagogicoCursoAfetoDaoImpl getInstance() { |
||
17 | if (myInstance == null) |
||
18 | myInstance = new QuestionarioPedagogicoCursoAfetoDaoImpl(); |
||
19 | return (QuestionarioPedagogicoCursoAfetoDaoImpl) myInstance; |
||
20 | } |
||
1333 | jmachado | 21 | |
22 | public List<QuestionarioPedagogicoCursoAfeto> find(long questionarioId,1.5.0/docs/api/java/lang/String.html">String cursoCode) |
||
23 | { |
||
24 | return createCriteria() |
||
25 | .add(eq("questionario.id", questionarioId)) |
||
26 | .add(eq("codigoCurso", cursoCode)) |
||
27 | .list(); |
||
28 | } |
||
29 | public List<QuestionarioPedagogicoCursoAfeto> find(long questionarioId) |
||
30 | { |
||
31 | return createCriteria() |
||
32 | .add(eq("questionario.id", questionarioId)) |
||
33 | .list(); |
||
34 | } |
||
1338 | jmachado | 35 | |
36 | |||
37 | |||
38 | |||
39 | public static class CourseStatsVars |
||
40 | { |
||
41 | public long unidades; |
||
42 | public long marcadas; |
||
43 | public long observadas; |
||
44 | public long porVer; |
||
45 | public long naoUsadas; |
||
46 | } |
||
47 | |||
48 | public CourseStatsVars loadStats(long cursoAfetoId) |
||
49 | { |
||
50 | CourseStatsVars courseStatsVars = new CourseStatsVars(); |
||
51 | 1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("SELECT " + |
||
52 | " sum (case when u.vista = false then 1 else 0 end) AS porVer " + |
||
53 | ",sum (case when u.usar = false then 1 else 0 end) AS naoUsadas " + |
||
54 | ",sum (case when u.marked = true then 1 else 0 end) AS marked " + |
||
55 | ",sum (case when u.obs is not NULL and u.obs != '' then 1 else 0 end) AS observadas " + |
||
56 | ",count(distinct u.id) AS unidades " + |
||
57 | "from " + QuestionarioPedagogicoCursoAfeto.class.getName() + " c " + |
||
58 | "JOIN c.unidadesAfetas u " + |
||
59 | "WHERE c.id = :id " + |
||
60 | "GROUP BY c.id"); |
||
61 | |||
62 | q.setLong("id",cursoAfetoId); |
||
63 | 5+0%2Fdocs%2Fapi+Object">Object[] results = (5+0%2Fdocs%2Fapi+Object">Object[]) q.uniqueResult(); |
||
64 | courseStatsVars.porVer = (1.5.0/docs/api/java/lang/Long.html">Long) results[0]; |
||
65 | courseStatsVars.naoUsadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[1]; |
||
66 | courseStatsVars.marcadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[2]; |
||
67 | courseStatsVars.observadas = (1.5.0/docs/api/java/lang/Long.html">Long) results[3]; |
||
68 | courseStatsVars.unidades = (1.5.0/docs/api/java/lang/Long.html">Long) results[4]; |
||
69 | |||
70 | return courseStatsVars; |
||
71 | } |
||
1332 | jmachado | 72 | } |