1 | /* |
---|
2 | * Created on 3 mai 2005 |
---|
3 | */ |
---|
4 | package com.medias.megapoli.trade; |
---|
5 | |
---|
6 | import com.medias.database.objects.Categorie; |
---|
7 | import com.medias.database.objects.Fichier; |
---|
8 | import com.medias.database.objects.Jeu; |
---|
9 | import com.medias.megapoli.struts.forms.DatasForm; |
---|
10 | import com.medias.utils.hibernate.CommunicationBD; |
---|
11 | import org.apache.struts.action.ActionForm; |
---|
12 | import org.hibernate.HibernateException; |
---|
13 | import com.medias.megapoli.struts.forms.JeuxForm; |
---|
14 | |
---|
15 | import java.util.ArrayList; |
---|
16 | import java.util.HashSet; |
---|
17 | import java.util.List; |
---|
18 | import java.util.Set; |
---|
19 | |
---|
20 | |
---|
21 | /** |
---|
22 | * @author pignot |
---|
23 | * |
---|
24 | * Classe permettant, au moyen de requêtes sur la base de données, |
---|
25 | * de charger la liste des jeux |
---|
26 | */ |
---|
27 | public class ListeJeuxAdapter { |
---|
28 | private ArrayList<Jeu> jeux; |
---|
29 | |
---|
30 | // private int min, max; |
---|
31 | |
---|
32 | // public ListePlateformesAdapter() { |
---|
33 | // plateformes = new ArrayList<Plateforme>(); |
---|
34 | // } |
---|
35 | |
---|
36 | public void loadJeuxFromDatabase (ActionForm form) { |
---|
37 | try { |
---|
38 | CommunicationBD.open(); |
---|
39 | List<?> jeuxList = CommunicationBD.get2OrderedList(Jeu.class, "categorie","jeuNom"); |
---|
40 | /* Plateforme plat; |
---|
41 | for (int numPlat=0; numPlat<plateformes.size(); numPlat++) { |
---|
42 | plat = (Plateforme) plateformes.get(numPlat); |
---|
43 | |
---|
44 | System.out.println ("------------ Nom plateforme="+plat.getPlateformeNom()); |
---|
45 | System.out.println ("------------ Type plateforme="+plat.getTypePlateforme().getTypePlateformeNom()); |
---|
46 | if (plat.getCommentaire() != null) { |
---|
47 | System.out.println ("------------ Description plateforme="+plat.getCommentaire().getCommentaireTxt()); |
---|
48 | } |
---|
49 | if (plat.getTypePlateforme().getCommentaire() != null) { |
---|
50 | System.out.println ("------------ Description type plateforme="+plat.getTypePlateforme().getCommentaire().getCommentaireTxt()); |
---|
51 | } |
---|
52 | System.out.println ("------------ ID plateforme="+plat.getPlateformeId().intValue()); |
---|
53 | System.out.println(); |
---|
54 | } |
---|
55 | */ |
---|
56 | jeux = new ArrayList<Jeu>(); |
---|
57 | Jeu jeu, j; |
---|
58 | Categorie categorie; |
---|
59 | Set<Fichier> fichiers; |
---|
60 | Fichier fichier; |
---|
61 | for (int numJeu=0; numJeu<jeuxList.size(); numJeu++) { |
---|
62 | j = (Jeu)jeuxList.get(numJeu); |
---|
63 | jeu = new Jeu(); |
---|
64 | categorie = new Categorie(); |
---|
65 | categorie.setCategorieId(j.getCategorie().getCategorieId()); |
---|
66 | categorie.setCategorieNom(j.getCategorie().getCategorieNom()); |
---|
67 | jeu.setCategorie(categorie); |
---|
68 | jeu.setJeuId(j.getJeuId()); |
---|
69 | jeu.setJeuNom(j.getJeuNom()); |
---|
70 | fichiers = new HashSet<Fichier>(); |
---|
71 | for (Fichier f : j.getFichiers()) { |
---|
72 | fichier = new Fichier(); |
---|
73 | fichier.setFichierId(f.getFichierId()); |
---|
74 | fichiers.add(fichier); |
---|
75 | } |
---|
76 | jeu.setFichiers(fichiers); |
---|
77 | jeux.add(jeu); |
---|
78 | } |
---|
79 | CommunicationBD.close(); |
---|
80 | if (form instanceof JeuxForm) |
---|
81 | ((JeuxForm)form).setJeux(jeux); |
---|
82 | else |
---|
83 | ((DatasForm)form).setJeux(jeux); |
---|
84 | } |
---|
85 | catch (HibernateException e) { |
---|
86 | System.out.println ("exception_ListeJeuxAdapter"); |
---|
87 | // Libération de la connection à la base de données |
---|
88 | try { |
---|
89 | CommunicationBD.close(); |
---|
90 | } catch (HibernateException ex) { |
---|
91 | ex.printStackTrace(); |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|