source: ether_megapoli/trunk/service/implementation/com/medias/megapoli/trade/ListePlateformesAdapter.java @ 152

Last change on this file since 152 was 152, checked in by vmipsl, 13 years ago

Import medias files and cleanup

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1/*
2 * Created on 3 mai 2005
3 */
4package com.medias.megapoli.trade;
5
6import java.util.ArrayList;
7import java.util.List;
8
9import org.apache.struts.action.ActionForm;
10import org.hibernate.HibernateException;
11import com.medias.database.objects.Plateforme;
12import com.medias.database.objects.TypePlateforme;
13import com.medias.megapoli.struts.forms.DatasForm;
14import com.medias.megapoli.struts.forms.PlateformesForm;
15import com.medias.utils.hibernate.CommunicationBD;
16
17
18/**
19 * @author pignot
20 *
21 * Classe permettant, au moyen de requêtes sur la base de données,
22 * de charger la liste des plateformes
23 */
24public class ListePlateformesAdapter {
25        private ArrayList<Plateforme> plateformes;
26       
27//      private int min, max;
28       
29//      public ListePlateformesAdapter() {
30//          plateformes = new ArrayList<Plateforme>();
31//      }
32
33        public void loadPlateformesFromDatabase(ActionForm form) {
34                try {
35                        CommunicationBD.open();
36                        List<?> plats = CommunicationBD.getList("from Plateforme order by typePlateforme.typePlateformeNom, plateformeNom");
37                        plateformes = new ArrayList<Plateforme>();
38                        Plateforme plateforme, plat;
39                        TypePlateforme typePlateforme;
40                        for (int numPlat=0; numPlat<plats.size(); numPlat++) {
41                                plat = (Plateforme)plats.get(numPlat);
42                                plateforme = new Plateforme();
43                                plateforme.setPlateformeId(plat.getPlateformeId());
44                                plateforme.setPlateformeNom(plat.getPlateformeNom());
45                                typePlateforme = new TypePlateforme();
46                                typePlateforme.setTypePlateformeId(plat.getTypePlateforme().getTypePlateformeId());
47                                typePlateforme.setTypePlateformeNom(plat.getTypePlateforme().getTypePlateformeNom());
48                                plateforme.setTypePlateforme(typePlateforme);
49                                plateformes.add(plateforme);
50                        }
51                        CommunicationBD.close();
52                        if (form instanceof PlateformesForm)
53                                ((PlateformesForm)form).setPlateformes(plateformes);
54                        else
55                                ((DatasForm)form).setPlateformes(plateformes);
56                }
57                catch (HibernateException e) {
58                    System.out.println ("exception_ListePlateformesAdapter");
59                        // Libération de la connection à la base de données
60                        try {
61                                CommunicationBD.close();
62                        } catch (HibernateException ex) {
63                               
64                        }
65                }
66        }
67
68    /**
69     * En cours ...
70     */
71//    private void trouverMinMax(ArrayList locs, String attribut) {
72//        Method appelGet;
73//        Class[] cl = {};
74//        Object[] arg = {};
75//        Localisation loc;
76//        Integer val;
77//        for (int num = 0; num<locs.size(); num++) {
78//            loc = ((Localisation)locs.get(num));
79//                      try {
80//                // Création de la méthode correspondant au type trouvé
81//                appelGet = Localisation.class.getMethod("get" + attribut,cl);
82//                // Invocation de la méthode sur la donnée
83//                val =  (Integer) appelGet.invoke(loc,arg);
84//                      } catch (NoSuchMethodException e2) {
85//                e2.printStackTrace();
86//            } catch (SecurityException e) {
87//                e.printStackTrace();
88//            } catch (IllegalArgumentException e1) {
89//                e1.printStackTrace();
90//            } catch (IllegalAccessException e1) {
91//                e1.printStackTrace();
92//            } catch (InvocationTargetException e1) {
93//                e1.printStackTrace();
94//            }
95//           
96//         
97//        }
98//       
99//    }
100}
Note: See TracBrowser for help on using the repository browser.