1
2
3
4 package ecar.dao;
5
6 import java.util.ArrayList;
7 import java.util.Iterator;
8 import java.util.List;
9
10 import javax.servlet.http.HttpServletRequest;
11
12 import org.hibernate.HibernateException;
13 import org.hibernate.Query;
14
15 import comum.database.Dao;
16 import ecar.exception.ECARException;
17 import ecar.pojo.PoderPeriodoExercicioPodPerExe;
18 import ecar.pojo.PoderPod;
19
20
21
22
23 public class PoderDao extends Dao {
24
25
26
27
28 public PoderDao(HttpServletRequest request) {
29 super();
30 this.request = request;
31 }
32
33
34
35
36
37
38 public List getPoderes() throws ECARException {
39 try {
40 StringBuilder qry = new StringBuilder("from PoderPod as poder").append(" order by poder.nomePod");
41
42 Query q = this.session.createQuery(qry.toString());
43
44 return q.list();
45
46 } catch (HibernateException e) {
47 this.logger.error(e);
48 throw new ECARException("erro.hibernateException");
49 }
50 }
51
52
53
54
55
56
57 public ArrayList<PoderPod> getPoderesByPeriodicidade(Long codPerExe, Character indAtivoPodPerExe) throws ECARException {
58
59 try {
60 StringBuilder qry = new StringBuilder("from PoderPeriodoExercicioPodPerExe as poder").append(" where poder.periodoExercicioPerExe.codPerExe = :codigo").append(" and poder.indAtivoPodPerExe = :indAtivo").append(" order by poder.poderPod.codPod");
61
62 Query q = this.session.createQuery(qry.toString());
63 q.setLong("codigo", codPerExe.longValue());
64 q.setCharacter("indAtivo", indAtivoPodPerExe);
65
66 List poderPerexe = q.list();
67 ArrayList<PoderPod> listPoder = new ArrayList<PoderPod>();
68
69
70 for (Iterator iter = poderPerexe.iterator(); iter.hasNext();) {
71 PoderPeriodoExercicioPodPerExe podTmp = (PoderPeriodoExercicioPodPerExe) iter.next();
72
73 listPoder.add(podTmp.getPoderPod());
74
75
76
77
78
79
80
81
82
83
84
85
86 }
87
88
89
90
91
92 return listPoder;
93
94 } catch (HibernateException e) {
95 this.logger.error(e);
96 throw new ECARException("erro.hibernateException");
97 }
98
99 }
100
101 }