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