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