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

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

maj eccad V3.2

  • Property svn:executable set to *
File size: 8.2 KB
RevLine 
[68]1package org.medias.eccad.persistance.jdbc;
2
3import java.awt.Color;
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
11import org.medias.eccad.modele.ColorMap;
12import org.medias.eccad.modele.ColorTab;
13import org.medias.eccad.persistance.dao.ColorTabDAO;
14import org.medias.eccad.persistance.exception.PersistanceException;
15
16public class ColorTabDAOjdbc extends GeneriqueDAOjdbc implements ColorTabDAO {
17       
[70]18        public ColorTab getColorMapByGrille() throws PersistanceException {
[68]19                ColorTab colortab = new ColorTab();
[70]20                colortab = getTableDefault(colortab);
[68]21                //colortab = getMinMax(oid, colortab);
22               
23                return colortab;
24        }
25       
[70]26        public List<ColorMap> getListClassMap() throws PersistanceException {
27                String sql = " select clm_id, clm_name, num_order from class_map order by clm_id";             
[68]28               
29                Statement requete = null;
30                ResultSet resultat = null;
31                Connection conn = getConnection();
32               
[70]33//              LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, " récupération liste de colortab " + sql);
[68]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()) {
[70]47                                liste_colormap.add(new ColorMap(resultat.getLong("clm_id"), resultat.getString("clm_name"), resultat.getInt("num_order")));
[68]48                        }
49                }
50                catch (Exception e) {
51                        throw new PersistanceException(e);
52                }
53                finally {
54                        closeConnection();
55                }
56               
57                return liste_colormap;
58        }
59       
[70]60        public List<ColorMap> getListColorTabByGrille() throws PersistanceException {
61                /*String sql = " select distinct cm_id, cm_name, pc_defaut"
[68]62                           + " from colormap join param_color using (cm_id) "
63                           + " join grille using (id_param) "
[70]64                           + " where id_grille = " + id_grille + " order by pc_defaut desc;";*/
[68]65               
[70]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]68                Statement requete = null;
69                ResultSet resultat = null;
70                Connection conn = getConnection();
71               
[70]72//              LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, " récupération liste de colortab " + sql);
[68]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       
[70]99        private ColorTab getTableDefault(ColorTab colortab) throws PersistanceException {
[68]100                Statement requete = null;
[70]101                /*String sql = " select distinct col_r, col_g, col_b, ci_min, ci_max"
[68]102                                   + " from color join color_index using (col_id)"
103                                   + " join param_color using (cm_id) "
104                                   + " join grille   using (id_param) "
[70]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;";
[68]111                Connection conn = getConnection();
112               
113                ResultSet resultat = null;
114               
[70]115//              LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, "*************************************REQUETE = " + sql);
[68]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
[70]128                float ci_min=-1;
129                float ci_max=0;
[68]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")));
[70]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;
[68]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
[70]172        public ColorTab getColorMapByID(long id, long idClass) throws PersistanceException {
[68]173                Statement requete = null;
174                ColorTab colortab = new ColorTab();
175               
[70]176                /*String sql = " select distinct col_r, col_g, col_b, ci_min, ci_max, cm_name"
[68]177                                   + " from color join color_index using (col_id) join colormap using (cm_id)"
[70]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;";
[68]184                Connection conn = getConnection();
185               
186                ResultSet resultat = null;
[70]187
188//              LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, "REQUETE = " + sql);
[68]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")));
[70]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"));
[68]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
[70]231/*      public List<ColorMap> getListColorMapDynamique() throws PersistanceException {
[68]232                String sql = " select distinct clm_id, clm_name"
[70]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;";
[68]235               
236               
237                Statement requete = null;
238                ResultSet resultat = null;
239                Connection conn = getConnection();
240               
[70]241//              LoggerPerso.log(ColorTabDAOjdbc.class, LoggerPerso.DEBUG, " récupération liste de colortab " + sql);
[68]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()) {
[70]255                                liste_colormap.add(new ColorMap(resultat.getLong("clm_id"), resultat.getString("clm_name"), 0));
[68]256                        }
257                }
258                catch (Exception e) {
259                        throw new PersistanceException(e);
260                }
261                finally {
262                        closeConnection();
263                }
264               
265                return liste_colormap;
[70]266        }*/
[68]267
268}
Note: See TracBrowser for help on using the repository browser.