Author: tchemit Date: 2008-08-26 21:24:13 +0000 (Tue, 26 Aug 2008) New Revision: 1044 Modified: trunk/topia2/changelog trunk/topia2/src/java/org/codelutin/topia/TopiaContext.java trunk/topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java Log: ajout d'une methode find pour extraire uniquement une fenetre d'entite Modified: trunk/topia2/changelog =================================================================== --- trunk/topia2/changelog 2008-08-26 08:35:26 UTC (rev 1043) +++ trunk/topia2/changelog 2008-08-26 21:24:13 UTC (rev 1044) @@ -1,6 +1,6 @@ ver-2-0-26 ?? ??? - - * 20082907 [cheemit] Suppression des dependances en dur sur les implantations d'entites + * 20082608 [chemit] permettre de recuperer uniquement une fenetre de resultat en hql (TopiaContext#find(String hql,int startIndex,int endIndex, Object ... args) + * 20082907 [chemit] Suppression des dependances en dur sur les implantations d'entites * 20072012 [thimel] Support des index sur les attibuts * 20072012 [ruchaud] Récupération des classes persistées * 20072012 [ruchaud] Création d'un vetoable sur les finds Modified: trunk/topia2/src/java/org/codelutin/topia/TopiaContext.java =================================================================== --- trunk/topia2/src/java/org/codelutin/topia/TopiaContext.java 2008-08-26 08:35:26 UTC (rev 1043) +++ trunk/topia2/src/java/org/codelutin/topia/TopiaContext.java 2008-08-26 21:24:13 UTC (rev 1044) @@ -94,13 +94,13 @@ /** * Permet de créer le schema de la base de données - * @throws TopiaException + * @throws TopiaException if any exception */ public void createSchema() throws TopiaException; /** * Permet de mettre à jour le schema de la base de données - * @throws TopiaException + * @throws TopiaException if any exception */ public void updateSchema() throws TopiaException; @@ -108,20 +108,22 @@ /** * applique les modifications apporté a ce context sur la base de données. + * @throws TopiaException if any exception */ public void commitTransaction() throws TopiaException; /** * annule les modifications apporté a ce context + * @throws TopiaException if any exception */ public void rollbackTransaction() throws TopiaException; /** * Permet de rechercher un entite directement par son TopiaId * - * @param topiaId - * @return - * @throws TopiaException + * @param topiaId l'id de l'entite recherche + * @return l'entite trouvee (ou null si non trouve) + * @throws TopiaException if any exception */ public TopiaEntity findByTopiaId(String topiaId) throws TopiaException; @@ -133,21 +135,34 @@ * @throws TopiaException si une erreur survient durant la requete */ public List find(String hql, Object ... args) throws TopiaException; - + /** + * Permet de faire une requete HQL hibernate directement sur la base + * en precisant la fenetre des elements a remonter avec les parametres <code>startIndex</code> + * et <code>endIndex</code>. + * @param hql la requete a faire + * @param startIndex la position du premier element a remonter + * @param endIndex la position du dernier element a remonter + * @param args les arguments de la requete + * @return La liste des resultats + * @throws TopiaException si une erreur survient durant la requete + */ + public List find(String hql,int startIndex,int endIndex, Object ... args) throws TopiaException; + + /** * Execute HQL operation on data (Update, Delete) * @param hql la requete a faire * @param args les arguments de la requete * @return The number of entities updated or deleted. - * @throws TopiaException + * @throws TopiaException if any exception */ public int execute(String hql, Object ... args) throws TopiaException; /** * Permet d'ajouter dans le TopiaContext une TopiaEntity créé par un * autre context. - * @param e - * @throws TopiaException + * @param e l'entity a ajouter + * @throws TopiaException if any exception */ public void add(TopiaEntity e) throws TopiaException; @@ -178,7 +193,7 @@ * @param file le nom du fichier ou stocker les informations * @param compress si vrai compress le fichier avec gzip * - * @throws TopiaException + * @throws TopiaException if any exception */ public void backup(File file, boolean compress) throws TopiaException; @@ -188,27 +203,29 @@ * @param dropDatabase si vrai alors supprime aussi la base de données * si la base utilise des fichiers les fichiers seront supprimé (ex: h2) * ou sera fait sur la base (pastgresql) - * @throws TopiaException + * @throws TopiaException if any exception */ public void clear(boolean dropDatabase) throws TopiaException; /** - * l'inverse de la methode {@link #backup(File)} + * l'inverse de la methode {@link #backup(File,boolean)} * * @param file le fichier ou prendre les informations, il peut-etre * compressé avec gzip ou non. * - * @throws TopiaException + * @throws TopiaException if any exception */ public void restore(File file) throws TopiaException; /** * Ferme le contexte + * @throws TopiaException if any exception */ public void closeContext() throws TopiaException; /** * Indique si le contexte a ete ferme + * @return <code>true</code> si le context est ferme, <code>false</code> autrement */ public boolean isClosed(); Modified: trunk/topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java =================================================================== --- trunk/topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java 2008-08-26 08:35:26 UTC (rev 1043) +++ trunk/topia2/src/java/org/codelutin/topia/framework/TopiaContextImpl.java 2008-08-26 21:24:13 UTC (rev 1044) @@ -315,7 +315,6 @@ /** * Constructeur utilisé par le beginTransaction pour créer le context fils. * - * @param config la configuration du * @param parentContext * @throws HibernateException * @throws TopiaNotFoundException @@ -798,8 +797,8 @@ */ public TopiaEntity findByTopiaId(String topiaId) throws TopiaException { checkClosed("Ce contexte a ete ferme, impossible de faire une recherche"); - TopiaEntity result = null; - Class entityClass = TopiaId.getClassName(topiaId); + TopiaEntity result; + Class<?extends TopiaEntity> entityClass = TopiaId.getClassName(topiaId); TopiaDAO dao = getDAO(entityClass); result = dao.findByTopiaId(topiaId); return result; @@ -829,6 +828,30 @@ throw new TopiaException("Error during query execution: " + hql, eee); } } + + public List find(String hql,int startIndex,int endIndex, Object ... args) throws TopiaException { + checkClosed("Ce contexte a ete ferme, impossible de faire une recherche"); + try { + Query query = getHibernate().createQuery(hql); + for (int j = 0; j < args.length; j += 2) { + String name = (String)args[j]; + Object value = args[j + 1]; + if(value.getClass().isArray()) { + query.setParameterList(name, (Object[])value); + } else { + query.setParameter(name, value); + } + } + query.setFirstResult(startIndex); + query.setMaxResults(endIndex-startIndex+1); + List result = query.list(); + result = firesSupport.fireEntitiesLoad(this, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException("Error during query execution: " + hql, eee); + } + } + /** * Execute HQL operation on data (Update, Delete) @@ -867,7 +890,7 @@ */ public void importXML(Reader xml) throws TopiaException { checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'import"); - Document doc = null; + Document doc; SAXReader xmlReader = new SAXReader(); try { @@ -902,8 +925,8 @@ public void exportXML(Writer xml, Object... entityAndcondition) throws TopiaException { checkClosed("Ce contexte a ete ferme, impossible d'effectuer l'export"); try { - Class entityClass = null; - String condition = null; + Class entityClass; + String condition; // si entityAndcondition est vide alors il faut le remplir // avec toutes les entités du mapping (class, null) @@ -977,7 +1000,7 @@ * @param file file to write backup * @param compress if true then use gzip to compress file * - * @see org.codelutin.topia.TopiaContext#backup(java.io.File) + * @see TopiaContext#backup(java.io.File,boolean) */ public void backup(File file, boolean compress) throws TopiaException { checkClosed("Ce contexte a ete ferme, impossible d'effectuer le backup");