1 | /* |
---|
2 | * Created on 25 avr. 2005 |
---|
3 | */ |
---|
4 | package com.medias.megapoli.trade; |
---|
5 | |
---|
6 | import com.medias.DateTime; |
---|
7 | import com.medias.Nombre; |
---|
8 | import com.medias.megapoli.struts.forms.DatasForm; |
---|
9 | import com.medias.utils.hibernate.CommunicationBD; |
---|
10 | import org.hibernate.HibernateException; |
---|
11 | |
---|
12 | import java.util.Date; |
---|
13 | import java.util.List; |
---|
14 | |
---|
15 | |
---|
16 | /** |
---|
17 | * @author pignot |
---|
18 | * |
---|
19 | * Classe permettant, au moyen de requêtes sur la base de données, |
---|
20 | * de charger la description d'une mesure |
---|
21 | */ |
---|
22 | public class MesureAdapter { |
---|
23 | |
---|
24 | public MesureAdapter () { |
---|
25 | } |
---|
26 | |
---|
27 | public void loadDatesFromDatabase(DatasForm dForm) { |
---|
28 | try { |
---|
29 | CommunicationBD.open(); |
---|
30 | List<?> dates = CommunicationBD.getList("select min(m.mesureDate), max(m.mesureDate) from Mesure m"); |
---|
31 | |
---|
32 | CommunicationBD.close(); |
---|
33 | Object[] resultats = (Object[])dates.get(0); |
---|
34 | dForm.setDateDeb( DateTime.dateToString( (Date) resultats[0], DateTime.formatDateStandard )); |
---|
35 | dForm.setDateFin(DateTime.dateToString((Date)resultats[1],DateTime.formatDateStandard)); |
---|
36 | } catch (HibernateException e) { |
---|
37 | System.out.println("exception_MesureAdapter"); |
---|
38 | // Libération de la connection à la base de données |
---|
39 | try { |
---|
40 | CommunicationBD.close(); |
---|
41 | } catch (HibernateException ex) { |
---|
42 | ex.printStackTrace(); |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | public void loadLocsFromDatabase(DatasForm dForm) { |
---|
48 | try { |
---|
49 | CommunicationBD.open(); |
---|
50 | List<?> locs = CommunicationBD.getList("select min(l.localisationLat), max(l.localisationLat), min(l.localisationLon), max(l.localisationLon) from Localisation l"); |
---|
51 | CommunicationBD.close(); |
---|
52 | Object[] resultats = (Object[])locs.get(0); |
---|
53 | dForm.setLatMin(Nombre.latIntToFloat((Integer)resultats[0]).toString()); |
---|
54 | dForm.setLatMax(Nombre.latIntToFloat((Integer)resultats[1]).toString()); |
---|
55 | dForm.setLonMin( Nombre.latIntToFloat( (Integer) resultats[2] ).toString()); |
---|
56 | dForm.setLonMax(Nombre.latIntToFloat((Integer)resultats[3]).toString()); |
---|
57 | dForm.setLatMinInit(dForm.getLatMin()); |
---|
58 | dForm.setLatMaxInit(dForm.getLatMax()); |
---|
59 | dForm.setLonMinInit(dForm.getLonMin()); |
---|
60 | dForm.setLonMaxInit(dForm.getLonMax()); |
---|
61 | dForm.setDateDebInit(dForm.getDateDeb()); |
---|
62 | dForm.setDateFinInit(dForm.getDateFin()); |
---|
63 | } catch (HibernateException e) { |
---|
64 | System.out.println("exception_MesureAdapter"); |
---|
65 | // Libération de la connection à la base de données |
---|
66 | try { |
---|
67 | CommunicationBD.close(); |
---|
68 | } catch (HibernateException ex) { |
---|
69 | ex.printStackTrace(); |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|