View Javadoc

1   package ecar.dao;
2   
3   import java.util.List;
4   
5   import javax.servlet.http.HttpServletRequest;
6   
7   import comum.database.Dao;
8   
9   import ecar.exception.ECARException;
10  import ecar.pojo.SitDemandaSitd;
11  import ecar.pojo.SituacaoSit;
12  
13  /**
14   * Classe de manipulação de objetos da classe AtributoAtt.
15   * @author CodeGenerator - Esta classe foi gerada automaticamente
16   * @since 1.0
17   * @version 1.0, Fri Jan 27 07:54:28 BRST 2006
18   */
19  public class SitDemandaDao extends Dao {
20    /**
21     * Construtor. Chama o Session factory do Hibernate
22     */
23    public SitDemandaDao(HttpServletRequest request) {
24      super();
25      this.request = request;
26    }
27  
28    /**
29     * Verifica depois exclui
30     * @param sitDemanda
31     * @throws ECARException
32     */
33    public void excluir(SitDemandaSitd sitDemanda) throws ECARException {
34      try {
35        boolean excluir = true;
36        if (contar(sitDemanda.getRegDemandaRegds()) > 0) {
37          excluir = false;
38          throw new ECARException("sitDemanda.exclusao.erro.regDemandaRegds");
39        }
40        if (excluir)
41          super.excluir(sitDemanda);
42      } catch (ECARException e) {
43        this.logger.error(e);
44        throw e;
45      }
46    }
47  
48    /**
49     * @return List
50     * @throws ECARException
51     */
52    public List buscar() throws ECARException {
53      return super.listar((new SitDemandaSitd()).getClass(), new String[] { "descricaoSitd", Dao.ORDEM_ASC });
54    }
55  
56    /**
57     * verifica duplicação de registro depois salva
58     * @param situacao
59     * @throws ECARException
60     */
61    public void salvar(SitDemandaSitd situacaoDemanda) throws ECARException {
62      if (pesquisarDuplos(situacaoDemanda, new String[] { "descricaoSitd" }, "codSitd").size() > 0)
63        throw new ECARException("situacao.validacao.registroDuplicado");
64  
65      // antes de salvar verifica se existe alguma situação já setada como
66      // primeira situação
67      if (jaTemPrimeiraSituacao(situacaoDemanda))
68        throw new ECARException("situacaoDemanda.validacao.indPrimeiraSituacaoSitd.duplicada");
69  
70      super.salvar(situacaoDemanda);
71    }
72  
73    /**
74     * verifica duplicação de registro depois Altera
75     * @param situacao
76     * @throws ECARException
77     */
78    public void alterar(SitDemandaSitd situacaoDemanda) throws ECARException {
79      if (pesquisarDuplos(situacaoDemanda, new String[] { "descricaoSitd" }, "codSitd").size() > 0)
80        throw new ECARException("situacao.validacao.registroDuplicado");
81  
82      // antes de salvar verifica se existe alguma situação já setada como
83      // primeira situação
84      if (jaTemPrimeiraSituacao(situacaoDemanda))
85        throw new ECARException("situacaoDemanda.validacao.indPrimeiraSituacaoSitd.duplicada");
86  
87      super.alterar(situacaoDemanda);
88    }
89  
90    private boolean jaTemPrimeiraSituacao(SitDemandaSitd situacaoDemanda) throws ECARException {
91  
92      boolean jaTemPrimeiraSituacao = false;
93  
94      if (situacaoDemanda.getIndPrimeiraSituacaoSitd().equals("S")) {
95  
96        List list = listar(SitDemandaSitd.class, new String[] { "descricaoSitd", Dao.ORDEM_ASC });
97        SitDemandaSitd situacao;
98  
99        for (Object situacaoObj : list) {
100 
101         situacao = (SitDemandaSitd) situacaoObj;
102 
103         if (!situacao.equals(situacaoDemanda) && situacao.getIndPrimeiraSituacaoSitd().equals("S")) {
104 
105           jaTemPrimeiraSituacao = true;
106           break;
107         }
108       }
109     }
110 
111     return jaTemPrimeiraSituacao;
112   }
113 
114 }