Package dao

Source Code of dao.DetailEpreuveDAO

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import model.Epreuve;
import model.Sportif;

/**
*
* @author Linda
*/
public class DetailEpreuveDAO extends AbstractDataBaseDao {

    public DetailEpreuveDAO(DataSource ds) {
        super(ds);
    }
    /**
     * les requêtes pour construire les listes d'épreuves d'une discipline par genre (genre)
     */
    private static final String reqSportifsEpreuveIndPourDisc =
            "select IdSp, NomSp, PrenomSp, nomP from InscriptionInd Natural Join LesSportifs where IdEp= %d order by nomP,nomSp ";

    private static final String reqSportifsEpreuveEqPourDisc =
            "select IdEq, IdSp, nomSp, prenomSp, nomP from (InscriptionEq Natural Join CompoEq)"
            + " natural join LesSportifs where IdEp= %d order by nomP,nomSp";

    private static final String reqIdEpreuveParEquipe =
            "select distinct IdEp from ((InscriptionEq Natural Join CompoEq) natural join epreuveeq)";

//    private static final String reqEpreuveIndPourDisc =
//            "select nomEp , genre, IdEp from EpreuveInd where nomDisc ='%s' ORDER BY GENRE, NOMEP";
//    private static final String reqEpreuveEqPourDisc =
//            "select nomEp , genre, IdEp from EpreuveEq where nomDisc ='%s' ORDER BY GENRE, NOMEP";
    private static final String reqNomCatEpreuveEq =
            "select distinct IdEp, nomEp,genre from ((InscriptionEq Natural Join CompoEq) natural join epreuveeq) where IdEp =%d ";

     private static final String reqNomCatEpreuveInd =
             "select distinct IdEp,nomEP, genre from (InscriptionInd  natural join epreuveInd) where IdEP =%d";
   private static Map<DataSource, DetailEpreuveDAO> daoInstances =
            new HashMap<DataSource, DetailEpreuveDAO>();

    public synchronized static DetailEpreuveDAO getInstance(DataSource ds) {
        DetailEpreuveDAO inst = daoInstances.get(ds);
        if (inst == null) {
            inst = new DetailEpreuveDAO(ds);
            daoInstances.put(ds, inst);
        }
        return inst;
    }

    /**
     * récupérer la liste des sportifs participant à une épreuve individuelle donnée
     * @param IdEp
     * @return
     * @throws DAOException
     */
    public List<Sportif> getSportifsEpreuveInd(int IdEp) throws DAOException {
        String req = String.format(reqSportifsEpreuveIndPourDisc, IdEp);

        Connection conn = null;
        Statement stmt = null;
        ResultSet result = null;
//        int i=0;
//        int[]tabIdEp = new int[20];

        List<Sportif> sportifs = new ArrayList<Sportif>();

        try {
            synchronized (dataSource) {
                conn = dataSource.getConnection();
            }
            stmt = conn.createStatement();
            System.out.println(req);
            result = stmt.executeQuery(req);

            while (result.next()) {
                sportifs.add(new Sportif(result.getInt(1), result.getString(2), result.getString(3), result.getString(4)));
           }
            result.close();
            stmt.close();
            return sportifs;
        } catch (SQLException ex) {
            throw new DAOException("problème récupération liste des SportifsEpreuveInd", ex);
        } finally {
            closeConnection(conn);
        }
    }

    /**
     * récupérer la liste des sportifs participant à une épreuve par équipe donnée
     * @param IdEp
     * @return
     * @throws DAOException
     */
    public List<Sportif> getSportifsEpreuveEq(int IdEp) throws DAOException {
        String req = String.format(reqSportifsEpreuveEqPourDisc, IdEp);

        Connection conn = null;
        Statement stmt = null;
        ResultSet result = null;
        List<Sportif> sportifsEq = new ArrayList<Sportif>();

        try {
            synchronized (dataSource) {
                conn = dataSource.getConnection();
            }
            stmt = conn.createStatement();
            System.out.println(req);
            result = stmt.executeQuery(req);

            while (result.next()) {
                sportifsEq.add(new Sportif(result.getInt(2), result.getString(3), result.getString(4), result.getString(5)));
                }
            result.close();
            stmt.close();
            return sportifsEq;
        } catch (SQLException ex) {
            throw new DAOException("problème récupération liste des épreuves", ex);
        } finally {
            closeConnection(conn);
        }
    }

    public int[]getTableauIdEpEq(int IdEp) throws DAOException {
        String req = String.format(reqIdEpreuveParEquipe, IdEp);
        Connection conn = null;
        Statement stmt = null;
        ResultSet result = null;


        int tabIdEp[] = new int[20];
        int i=0;
        try {
            synchronized (dataSource) {
                conn = dataSource.getConnection();
            }
            stmt = conn.createStatement();
            System.out.println(req);
            result = stmt.executeQuery(req);


                while (result.next()) {
                tabIdEp[i] = result.getInt(1);
                i++;
            }
            result.close();
            stmt.close();
            return tabIdEp;
              } catch (SQLException ex) {
            throw new DAOException("problème récupération liste des épreuves du tableau", ex);
        } finally {
            closeConnection(conn);

        }
    }
/**
* récuperation du nom  et la catégorie de l'epreuve par Individuelle
* correspondant à un IdEp donné
* @param IdEp
* @param IdEp
* @return
* @throws DAOException
*/
      public Epreuve getNomCatEpreuveInd(int IdEp) throws DAOException {
        String req = String.format(reqNomCatEpreuveInd, IdEp);
        Connection conn = null;
        Statement stmt = null;
        ResultSet result = null;
        Epreuve nomCatEpreuveInd =new Epreuve();
        try {
            synchronized (dataSource) {
                conn = dataSource.getConnection();
            }
            stmt = conn.createStatement();
            System.out.println(req);
            result = stmt.executeQuery(req);

            while (result.next()) {
             nomCatEpreuveInd.setNomEtCategorie(result.getString(2), result.getString(3));
        }
            result.close();
            stmt.close();
           return nomCatEpreuveInd;
              } catch (SQLException ex) {
            throw new DAOException("problème récupération nom et categorie epreuve", ex);
        } finally {
            closeConnection(conn);

        }
    }
    /**
     * récuperation du nom  et la catégorie de l'epreuve par equipe
     * correspondant à un IdEp donné
     * @param IdEp
     * @return
     * @throws DAOException
     */
    public Epreuve getNomCatEpreuveEq(int IdEp) throws DAOException {
        String req = String.format(reqNomCatEpreuveEq, IdEp);
        Connection conn = null;
        Statement stmt = null;
        ResultSet result = null;
        Epreuve nomCatEpreuveEq =new Epreuve();
        try {
            synchronized (dataSource) {
                conn = dataSource.getConnection();
            }
            stmt = conn.createStatement();
            System.out.println(req);
            result = stmt.executeQuery(req);
          
            while (result.next()) {
             nomCatEpreuveEq.setNomEtCategorie(result.getString(2), result.getString(3));

                       // nomCatEpreuveEq = new Epreuve(result.getString(1), result.getString(1));
//                nomCatEpreuveEq.getNom()= result.getString(2);
//                nomCatEpreuveEq.getCategorie();
            //nomCatEpreuveEq.add(new Epreuve(result.getString(2), result.getString(3)));
            }
            result.close();
            stmt.close();
           return nomCatEpreuveEq;
              } catch (SQLException ex) {
            throw new DAOException("problème récupération nom et categorie epreuve", ex);
        } finally {
            closeConnection(conn);

        }
    }
}
TOP

Related Classes of dao.DetailEpreuveDAO

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.