These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problème de Critères
PostPosted: Thu Jun 29, 2006 7:44 am 
Newbie

Joined: Thu Jun 29, 2006 7:32 am
Posts: 2
Bonjour,

J'ai une application qui tourne sur tomcat, je me connecte à une base de données MySQL et j'utilise le framwork Hibernate.
Je définis pas mal de critères sur mes requetes et ça marche bien (j'utilise la classe Criteria) sauf quand je veux limiter mes résultats j'arrive à afficher plus rien!

j'ai ajouté cette méthode

Code:
protected void addCritereLimit() throws Exception {
       criteres.setMaxResults(50);
    }



Code:
public abstract class ListManager extends BaseManager {
    protected Criteria criteres;

    protected DataUserChoices paramUtilisateur;

    protected static String CRITERE_EQ = "eg";

    protected static String CRITERE_SUP = "sup";

    protected static String CRITERE_INF = "inf";

    protected static String CRITERE_DIF = "dif";

    protected static String CRITERE_IN = "in";

    protected static String CRITERE_lik = "lik";

    protected String NOM_ALIAS_TABLE_BASE;

    protected String NOM_PROPRIETE_TABLE_SSA;

    protected static String NOM_ALIAS_TABLE_RESERVATION = "infosReservation";

    protected void initialize(DataUserChoices paramUtilisateur)
            throws Exception {
        super.initialize(paramUtilisateur.getClientSegment());
        this.paramUtilisateur = paramUtilisateur;
        this.initialize();
    }

    protected abstract void initialize() throws Exception;

    protected void addCritereSSA() throws Exception {
        List<String> ssasDansCritere = new ArrayList<String>();
        Iterator iSsa = paramUtilisateur.getListSsa().iterator();
        while (iSsa.hasNext()) {
            com.capgemini.orcis.web.model.Ssa currentSsa = (com.capgemini.orcis.web.model.Ssa) iSsa
                    .next();
            if (currentSsa.getCriterChecked().equals("true")) {
                ssasDansCritere.add(currentSsa.getLibelle());
            }

        }
        if (!ssasDansCritere.isEmpty()) {

            criteres = criteres.createAlias(NOM_PROPRIETE_TABLE_SSA,
                    "ssapresent");
            criteres.add(Restrictions.in("ssapresent.nomssa", ssasDansCritere
                    .toArray()));
        }

    }

    protected void addCritereSegment() throws Exception {
        criteres.add(Restrictions.eq(this.NOM_ALIAS_TABLE_BASE + ".nscsnum",this.paramUtilisateur.getClientSegment()));
    }
   
    protected void addCritereLimit() throws Exception {
       criteres.setMaxResults(50);
    }

    protected void addCritereInfosReservation() throws Exception {
        Iterator iInfoReservation = this.paramUtilisateur
                .getListReservationFields().iterator();
        while (iInfoReservation.hasNext()) {
            Field champsSelectionne = (Field) iInfoReservation.next();
            Iterator icritereRes = champsSelectionne.getListCriteresValues()
                    .iterator();
            while (icritereRes.hasNext()) {
                CritereValue critereRes = (CritereValue) icritereRes.next();
                if (!critereRes.getValue().equals("")) {
                    this.criteres.add(Restrictions.eq(
                            NOM_ALIAS_TABLE_RESERVATION + "."
                                    + champsSelectionne.getAttributeName(),
                            critereRes.getValue()));
                }
            }
            // if(critereRes.getCritere())
        }
    }

    protected void addCritereInfosDonnes() throws Exception {
        Iterator iInfoDonnes = this.paramUtilisateur.getListDataFields()
                .iterator();
        // Pour chaque critere sur une info de donnée
        // On ajoute le critere SQL associé
        while (iInfoDonnes.hasNext()) {
            Field champsSelectionne = (Field) iInfoDonnes.next();
            Iterator icritereInfo = champsSelectionne.getListCriteresValues()
                    .iterator();
            // Si le critère est l'égalité
            while (icritereInfo.hasNext()) {
                CritereValue critereInfo = (CritereValue) icritereInfo.next();
                if (critereInfo.getCritere().equals(CRITERE_EQ)) {
                    this.criteres.add(Restrictions.eq(NOM_ALIAS_TABLE_BASE
                            + "." + champsSelectionne.getAttributeName(),
                            critereInfo.getValue()));
                }
                // Si le critère est la supériorité
                else if (critereInfo.getCritere().equals(CRITERE_SUP)) {
                    this.criteres.add(Restrictions.gt(NOM_ALIAS_TABLE_BASE
                            + "." + champsSelectionne.getAttributeName(),
                            critereInfo.getValue()));
                }
                // Si le critère est l'infériorité
                else if (critereInfo.getCritere().equals(CRITERE_INF)) {
                    this.criteres.add(Restrictions.lt(NOM_ALIAS_TABLE_BASE
                            + "." + champsSelectionne.getAttributeName(),
                            critereInfo.getValue()));
                }
                // Si le critère est la différence
                else if (critereInfo.getCritere().equals(CRITERE_DIF)) {
                    this.criteres.add(Restrictions.not(Restrictions.eq(
                            NOM_ALIAS_TABLE_BASE + "."
                                    + champsSelectionne.getAttributeName(),
                            critereInfo.getValue())));
                }
            }
        }
    }

    /**
     * ajout des critères et renvoie la liste des critères
     * @return List
     * @throws Exception
     */
   
    public List getListDonnees() throws Exception {

        //this.addCritereSegment();
       this.addCritereLimit();
        if (this.paramUtilisateur.getListSsa().size() > 0) {
            this.addCritereSSA();
        }
        this.addCritereInfosDonnes();
        this.addCritereInfosReservation();

        return this.criteres.list();
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.