1 package ecar.dao;
2
3 import java.util.List;
4
5 import javax.servlet.http.HttpServletRequest;
6
7 import org.hibernate.HibernateException;
8 import org.hibernate.ObjectNotFoundException;
9 import org.hibernate.Query;
10
11 import comum.database.Dao;
12
13 import ecar.exception.ECARException;
14 import ecar.pojo.Cor;
15 import ecar.pojo.PontoCriticoPtc;
16 import ecar.pojo.PontocriticoCorPtccor;
17
18
19
20
21
22
23
24 public class PontocriticoCorPtccorDAO extends Dao {
25
26
27
28
29
30 public PontocriticoCorPtccorDAO(HttpServletRequest request) {
31 super();
32 this.request = request;
33 }
34
35
36
37
38
39
40
41 public PontocriticoCorPtccor buscar(Cor cor, PontoCriticoPtc ptc) throws ECARException {
42
43 PontocriticoCorPtccor ptcCor = new PontocriticoCorPtccor();
44 try {
45 if (ptc.getCodPtc() != null) {
46 Query q = session.createQuery("from PontocriticoCorPtccor ptcCor where " + " ptcCor.id.codCor = :cor" + " and ptcCor.id.codPtc = :codPtc");
47 q.setLong("cor", cor.getCodCor().longValue());
48 q.setLong("codPtc", ptc.getCodPtc().longValue());
49
50 List lista = q.list();
51
52 if (lista.size() != 0)
53 ptcCor = (PontocriticoCorPtccor) lista.iterator().next();
54 }
55 } catch (ObjectNotFoundException e) {
56 this.logger.error(e);
57 throw new ECARException("erro.objectNotFound");
58 } catch (HibernateException e) {
59 this.logger.error(e);
60 throw new ECARException("erro.hibernateException");
61 } catch (Exception e) {
62 this.logger.error(e);
63 throw new ECARException("erro.exception");
64 }
65
66 return ptcCor;
67 }
68 }