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();
}