source: ether_eccad/trunk/ECCAD_INTERFACE/WEB-INF/src/org/medias/eccad/persistance/jdbc/ParametreDAOjdbc.java @ 68

Last change on this file since 68 was 68, checked in by cbipsl, 14 years ago

commit v1 eccad

  • Property svn:executable set to *
File size: 7.3 KB
Line 
1package org.medias.eccad.persistance.jdbc;
2
3import java.io.UnsupportedEncodingException;
4import java.sql.Connection;
5import java.sql.ResultSet;
6import java.sql.SQLException;
7import java.sql.Statement;
8import java.util.LinkedList;
9import java.util.List;
10
11
12import org.medias.eccad.helpers.LoggerPerso;
13import org.medias.eccad.modele.Parametre;
14import org.medias.eccad.persistance.jdbc.SGBD_jdbc;
15import org.medias.eccad.persistance.dao.ParametreDAO;
16import org.medias.eccad.persistance.exception.PersistanceException;
17
18/**
19 *
20 * @author pinaud
21 *
22 */
23public class ParametreDAOjdbc extends GeneriqueDAOjdbc implements ParametreDAO {
24
25        public ParametreDAOjdbc(SGBD_jdbc sgbd) {
26                super (sgbd);
27        }
28       
29        public ParametreDAOjdbc() {
30                super();
31        }
32       
33        /**
34         * Retourne l'ensemble des paramÚtres en base de données
35         * @return la liste des parametres
36         */
37        public List<Parametre> getListParametre() throws PersistanceException{
38                Connection conn = null;
39                Statement requete;
40                String sql;
41                List<Parametre> liste_param = new LinkedList<Parametre>();
42                ResultSet resultat = null;
43               
44                conn = getConnection();
45               
46                try {
47                        requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
48                        sql = "select distinct id_param, fullname_param, shortname_param, order_param from parametre join grille using (id_param) join produit using (id_produit) join typeproduit using (id_typeproduit) where name_typeproduit not ilike 'array' order by order_param;";
49                       
50                        resultat = requete.executeQuery(sql);
51               
52                       
53                        while (resultat.next()) {
54                                liste_param.add(new Parametre(resultat.getInt("id_param"), resultat.getString("fullname_param"),resultat.getString("shortname_param"),resultat.getString("order_param") ));
55                        }
56                }
57                catch (SQLException sqle){
58                        throw new PersistanceException(sqle, "erreur lors de la requete :: ParametreDAOjdbc.getListParametre");
59                }
60                finally {
61                        closeConnection();
62                }
63               
64                LoggerPerso.log(SGBD_jdbc.class, LoggerPerso.DEBUG, "getListParametre::taille::"+liste_param.size());
65
66                return liste_param;
67        }
68       
69       
70       
71        /**
72         * Retourne l'ensemble des paramÚtres en base de données d'une categorie
73         * @return la liste des parametres
74         */
75        public List<Parametre> getListParamtByCatParam(int id_CatParam) throws PersistanceException{
76                Connection conn = null;
77                Statement requete;
78                String sql;
79                List<Parametre> liste_param = new LinkedList<Parametre>();
80                ResultSet resultat = null;
81               
82                conn = getConnection();
83               
84                try {
85                        requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
86                        sql = "select distinct id_param, fullname_param, shortname_param, order_param from parametre join grille using (id_param) join produit using (id_produit) join typeproduit using (id_typeproduit) where id_categorieparametre= "+id_CatParam+" and name_typeproduit not ilike 'array' order by order_param;";
87                       
88                        resultat = requete.executeQuery(sql);
89               
90                       
91                        while (resultat.next()) {
92                                if (resultat.getString("shortname_param").equals("NULL"))
93                                        liste_param.add(new Parametre(resultat.getInt("id_param"), resultat.getString("fullname_param")));
94                                else
95                                        liste_param.add(new Parametre(resultat.getInt("id_param"), resultat.getString("fullname_param")+" ("+resultat.getString("shortname_param")+") "));
96                        }
97                }
98                catch (SQLException sqle){
99                        throw new PersistanceException(sqle, "erreur lors de la requete :: ParametreDAOjdbc.getListParametre");
100                }
101                finally {
102                        closeConnection();
103                }
104               
105                LoggerPerso.log(SGBD_jdbc.class, LoggerPerso.DEBUG, "getListParametre::taille::"+liste_param.size());
106
107                return liste_param;
108        }
109       
110       
111       
112       
113        /**
114         * Retourne le parametre ayant l'identifiant transmis
115         * @param id_param identifiant du parametre
116         * @return le parametre
117         */
118        public Parametre getParametreById(int id_param) throws PersistanceException{
119                Statement requete;
120                String sql;
121                Parametre param = null;
122                Connection conn;
123               
124                conn = getConnection();
125               
126                try {
127                        requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
128                        sql = "select distinct id_param, fullname_param, shortname_param, order_param, shortName_unite from parametre join unite using (id_unite) where id_param = " + id_param + " order by order_param;";
129                        LoggerPerso.log(SGBD_jdbc.class, LoggerPerso.DEBUG, "sql getParametreById="+sql);
130                       
131                        ResultSet resultat = requete.executeQuery(sql);
132                       
133                        if (resultat.next()) {
134                                param = new Parametre(resultat.getInt("id_param"), resultat.getString("fullname_param"), resultat.getString("shortname_param"),resultat.getString("order_param"));
135                                param.setUnite(resultat.getString("shortName_unite"));
136                        }
137                }
138                catch (SQLException sqle) {
139                        throw new PersistanceException(sqle, "erreur lors de la requete :: ParametreDAOjdbc.getParametreById");
140                }
141                finally {
142                        closeConnection();
143                }
144                       
145                LoggerPerso.log(SGBD_jdbc.class, LoggerPerso.DEBUG, "getParametreById::nom::"+ param.getNom());
146
147                return param;
148        }
149       
150
151        public Parametre getParametreByGrille(long id_grille) throws PersistanceException {
152                Statement requete;
153                String sql;
154                Parametre param = null;
155                Connection conn;
156               
157                conn = getConnection();
158               
159                try {
160                        requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
161                        sql = "select distinct id_param, fullname_param, shortname_param, order_param, shortName_unite from parametre join grille using (id_param) join unite using (id_unite) where id_grille = " + id_grille + " order by order_param;";
162                       
163                        ResultSet resultat = requete.executeQuery(sql);
164                                               
165                        if (resultat.next()) {
166                                param = new Parametre(resultat.getInt("id_param"), resultat.getString("fullname_param"),resultat.getString("shortname_param"),resultat.getString("order_param"));
167                                byte[] temp = null;
168                                String unite = null;
169                                try {
170                                         temp = resultat.getString("shortName_unite").getBytes("ISO-8859-1");
171                                } catch (UnsupportedEncodingException e) {      }
172                               
173                                if (temp != null)
174                                        unite = new String(temp); 
175                                param.setUnite(unite);
176                        }
177                }
178                catch (SQLException sqle) {
179                        throw new PersistanceException(sqle, "erreur lors de la requete :: ParametreDAOjdbc.getParametreById");
180                }
181                finally {
182                        closeConnection();
183                }
184                       
185                LoggerPerso.log(SGBD_jdbc.class, LoggerPerso.DEBUG, "getParametreById::nom::"+ param.getNom());
186
187                return param;
188        }
189
190        public Parametre getParametreByName(String nom) throws PersistanceException {
191                Statement requete;
192                String sql;
193                Parametre param = null;
194                Connection conn;
195               
196                conn = getConnection();
197               
198                try {
199                        requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
200                        sql = "select distinct id_param, fullname_param, shortname_param, order_param, shortName_unite from parametre join unite using (id_unite) where fullname_param ilike '%" + nom + "%' order by order_param;";
201                       
202                        ResultSet resultat = requete.executeQuery(sql);
203                       
204                        if (resultat.next()) {
205                                param = new Parametre(resultat.getInt("id_param"), resultat.getString("fullname_param"),resultat.getString("shortname_param"),resultat.getString("order_param")     );
206                                param.setUnite(resultat.getString("shortName_unite"));
207                        }
208                }
209                catch (SQLException sqle) {
210                        throw new PersistanceException(sqle, "erreur lors de la requete :: ParametreDAOjdbc.getParametreById");
211                }
212                finally {
213                        closeConnection();
214                }
215                       
216                LoggerPerso.log(SGBD_jdbc.class, LoggerPerso.DEBUG, "getParametreById::nom::"+ param.getNom());
217
218                return param;
219        }
220
221}
Note: See TracBrowser for help on using the repository browser.