1 | package org.medias.eccad.persistance.jdbc; |
---|
2 | |
---|
3 | import java.awt.Color; |
---|
4 | import java.sql.Connection; |
---|
5 | import java.sql.ResultSet; |
---|
6 | import java.sql.SQLException; |
---|
7 | import java.sql.Statement; |
---|
8 | import java.util.LinkedList; |
---|
9 | import java.util.List; |
---|
10 | |
---|
11 | |
---|
12 | import org.medias.eccad.helpers.LoggerPerso; |
---|
13 | import org.medias.eccad.modele.ColorMap; |
---|
14 | import org.medias.eccad.modele.ColorTab; |
---|
15 | import org.medias.eccad.persistance.dao.ColorTabDAO; |
---|
16 | import org.medias.eccad.persistance.exception.PersistanceException; |
---|
17 | |
---|
18 | public class ColorTabDAOjdbc extends GeneriqueDAOjdbc implements ColorTabDAO { |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | public ColorTab getColorMapByGrille(long id_grille) throws PersistanceException { |
---|
24 | ColorTab colortab = new ColorTab(); |
---|
25 | colortab = getTableDefault(id_grille, colortab); |
---|
26 | //colortab = getMinMax(oid, colortab); |
---|
27 | |
---|
28 | return colortab; |
---|
29 | } |
---|
30 | |
---|
31 | public List<ColorMap> getListColorTab() throws PersistanceException { |
---|
32 | String sql = " select cm_name, " |
---|
33 | + " from colormap " |
---|
34 | + " order by cm_id;"; |
---|
35 | //+ " join grille using (id_param) " |
---|
36 | |
---|
37 | |
---|
38 | Statement requete = null; |
---|
39 | ResultSet resultat = null; |
---|
40 | Connection conn = getConnection(); |
---|
41 | |
---|
42 | LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, " récupération liste de colortab " + sql); |
---|
43 | |
---|
44 | try { |
---|
45 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
46 | resultat = requete.executeQuery(sql); |
---|
47 | } catch (SQLException e) { |
---|
48 | closeConnection(); |
---|
49 | throw new PersistanceException(e); |
---|
50 | } |
---|
51 | |
---|
52 | List<ColorMap> liste_colormap = new LinkedList<ColorMap>(); |
---|
53 | |
---|
54 | try { |
---|
55 | while (resultat.next()) { |
---|
56 | liste_colormap.add(new ColorMap(resultat.getLong("cm_id"), resultat.getString("cm_name"), resultat.getInt("pc_defaut"))); |
---|
57 | } |
---|
58 | } |
---|
59 | catch (Exception e) { |
---|
60 | throw new PersistanceException(e); |
---|
61 | } |
---|
62 | finally { |
---|
63 | closeConnection(); |
---|
64 | } |
---|
65 | |
---|
66 | return liste_colormap; |
---|
67 | } |
---|
68 | |
---|
69 | public List<ColorMap> getListColorTabByGrille(long id_grille) throws PersistanceException { |
---|
70 | String sql = " select distinct cm_id, cm_name, pc_defaut" |
---|
71 | + " from colormap join param_color using (cm_id) " |
---|
72 | + " join grille using (id_param) " |
---|
73 | + " where id_grille = " + id_grille + " order by pc_defaut desc;"; |
---|
74 | |
---|
75 | Statement requete = null; |
---|
76 | ResultSet resultat = null; |
---|
77 | Connection conn = getConnection(); |
---|
78 | |
---|
79 | LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, " récupération liste de colortab " + sql); |
---|
80 | |
---|
81 | try { |
---|
82 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
83 | resultat = requete.executeQuery(sql); |
---|
84 | } catch (SQLException e) { |
---|
85 | closeConnection(); |
---|
86 | throw new PersistanceException(e); |
---|
87 | } |
---|
88 | |
---|
89 | List<ColorMap> liste_colormap = new LinkedList<ColorMap>(); |
---|
90 | |
---|
91 | try { |
---|
92 | while (resultat.next()) { |
---|
93 | liste_colormap.add(new ColorMap(resultat.getLong("cm_id"), resultat.getString("cm_name"), resultat.getInt("pc_defaut"))); |
---|
94 | } |
---|
95 | } |
---|
96 | catch (Exception e) { |
---|
97 | throw new PersistanceException(e); |
---|
98 | } |
---|
99 | finally { |
---|
100 | closeConnection(); |
---|
101 | } |
---|
102 | |
---|
103 | return liste_colormap; |
---|
104 | } |
---|
105 | |
---|
106 | private ColorTab getTableDefault(long id_grille, ColorTab colortab) throws PersistanceException { |
---|
107 | Statement requete = null; |
---|
108 | String sql = " select distinct col_r, col_g, col_b, ci_min, ci_max" |
---|
109 | + " from color join color_index using (col_id)" |
---|
110 | + " join param_color using (cm_id) " |
---|
111 | + " join grille using (id_param) " |
---|
112 | + " where id_grille = " + id_grille +" and pc_defaut = 1 order by ci_max;"; |
---|
113 | Connection conn = getConnection(); |
---|
114 | |
---|
115 | ResultSet resultat = null; |
---|
116 | |
---|
117 | |
---|
118 | LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, "*************************************REQUETE = " + sql); |
---|
119 | try { |
---|
120 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
121 | resultat = requete.executeQuery(sql); |
---|
122 | } catch (SQLException e) { |
---|
123 | closeConnection(); |
---|
124 | throw new PersistanceException(e); |
---|
125 | } |
---|
126 | |
---|
127 | List<Color> liste_couleur = new LinkedList<Color>(); |
---|
128 | List<Float> liste_min = new LinkedList<Float>(); |
---|
129 | int i=0; |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | try { |
---|
134 | while (resultat.next()) { |
---|
135 | liste_couleur.add(new Color(resultat.getInt("col_r"), resultat.getInt("col_g"), resultat.getInt("col_b"))); |
---|
136 | liste_min.add(resultat.getFloat("ci_min")); |
---|
137 | colortab.setMax(resultat.getFloat("ci_max")); |
---|
138 | i++; |
---|
139 | } |
---|
140 | } |
---|
141 | catch (SQLException sqle) { |
---|
142 | throw new PersistanceException(sqle); |
---|
143 | } |
---|
144 | finally { |
---|
145 | closeConnection(); |
---|
146 | } |
---|
147 | Color[] color_tab = new Color[i]; |
---|
148 | float[] tab_min = new float[i]; |
---|
149 | |
---|
150 | |
---|
151 | for (i=0; i<liste_min.size(); i++) { |
---|
152 | tab_min[i] = liste_min.get(i); |
---|
153 | color_tab[i] = liste_couleur.get(i); |
---|
154 | } |
---|
155 | colortab.setTab_min(tab_min); |
---|
156 | colortab.setTab_couleur(color_tab); |
---|
157 | |
---|
158 | return colortab; |
---|
159 | } |
---|
160 | |
---|
161 | public ColorTab getColorMapByParam(int id_param) { |
---|
162 | // TODO Auto-generated method stub |
---|
163 | return null; |
---|
164 | } |
---|
165 | |
---|
166 | public ColorTab getColorMapByID(long id) throws PersistanceException { |
---|
167 | Statement requete = null; |
---|
168 | ColorTab colortab = new ColorTab(); |
---|
169 | |
---|
170 | String sql = " select distinct col_r, col_g, col_b, ci_min, ci_max, cm_name" |
---|
171 | + " from color join color_index using (col_id) join colormap using (cm_id)" |
---|
172 | + " where cm_id = " + id +" order by ci_min;"; |
---|
173 | Connection conn = getConnection(); |
---|
174 | |
---|
175 | ResultSet resultat = null; |
---|
176 | |
---|
177 | |
---|
178 | LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, "REQUETE = " + sql); |
---|
179 | try { |
---|
180 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
181 | resultat = requete.executeQuery(sql); |
---|
182 | } catch (SQLException e) { |
---|
183 | closeConnection(); |
---|
184 | throw new PersistanceException(e); |
---|
185 | } |
---|
186 | |
---|
187 | List<Color> liste_couleur = new LinkedList<Color>(); |
---|
188 | List<Float> liste_min = new LinkedList<Float>(); |
---|
189 | int i=0; |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | try { |
---|
194 | |
---|
195 | while (resultat.next()) { |
---|
196 | colortab.setName(resultat.getString("cm_name")); |
---|
197 | liste_couleur.add(new Color(resultat.getInt("col_r"), resultat.getInt("col_g"), resultat.getInt("col_b"))); |
---|
198 | liste_min.add(resultat.getFloat("ci_min")); |
---|
199 | colortab.setMax(resultat.getFloat("ci_max")); |
---|
200 | i++; |
---|
201 | } |
---|
202 | } |
---|
203 | catch (SQLException sqle) { |
---|
204 | throw new PersistanceException(sqle); |
---|
205 | } |
---|
206 | finally { |
---|
207 | closeConnection(); |
---|
208 | } |
---|
209 | Color[] color_tab = new Color[i]; |
---|
210 | float[] tab_min = new float[i]; |
---|
211 | |
---|
212 | |
---|
213 | for (i=0; i<liste_min.size(); i++) { |
---|
214 | tab_min[i] = liste_min.get(i); |
---|
215 | color_tab[i] = liste_couleur.get(i); |
---|
216 | } |
---|
217 | colortab.setTab_min(tab_min); |
---|
218 | colortab.setTab_couleur(color_tab); |
---|
219 | |
---|
220 | return colortab; |
---|
221 | } |
---|
222 | |
---|
223 | public List<ColorMap> getListColorMapDynamique() throws PersistanceException { |
---|
224 | String sql = " select distinct clm_id, clm_name" |
---|
225 | + " from class_map " |
---|
226 | + " where clm_name ilike '%exponential%' or clm_name ilike '%linear%' or clm_name ilike '%logarithm%' order by clm_name;"; |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | Statement requete = null; |
---|
231 | ResultSet resultat = null; |
---|
232 | Connection conn = getConnection(); |
---|
233 | |
---|
234 | LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, " récupération liste de colortab " + sql); |
---|
235 | |
---|
236 | try { |
---|
237 | requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
---|
238 | resultat = requete.executeQuery(sql); |
---|
239 | } catch (SQLException e) { |
---|
240 | closeConnection(); |
---|
241 | throw new PersistanceException(e); |
---|
242 | } |
---|
243 | |
---|
244 | List<ColorMap> liste_colormap = new LinkedList<ColorMap>(); |
---|
245 | |
---|
246 | try { |
---|
247 | while (resultat.next()) { |
---|
248 | liste_colormap.add(new ColorMap(resultat.getLong("cm_id"), resultat.getString("cm_name"), 0)); |
---|
249 | } |
---|
250 | } |
---|
251 | catch (Exception e) { |
---|
252 | throw new PersistanceException(e); |
---|
253 | } |
---|
254 | finally { |
---|
255 | closeConnection(); |
---|
256 | } |
---|
257 | |
---|
258 | return liste_colormap; |
---|
259 | } |
---|
260 | |
---|
261 | } |
---|