Author: fdesbois Date: 2009-11-27 18:01:06 +0100 (Fri, 27 Nov 2009) New Revision: 1673 Modified: branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java Log: Evol #135 : Use of count(*) for counting entities from the DAO method size() Modified: branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java =================================================================== --- branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2009-11-26 09:24:50 UTC (rev 1672) +++ branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2009-11-27 17:01:06 UTC (rev 1673) @@ -134,12 +134,12 @@ throws TopiaException; /** - * TODO modifier l'implantation pour faire un simple count sur la base + * Compte le nombre d'entites en base * - * @return la taille de ? + * @return le nombre total d'entites existantes * @throws TopiaException */ - int size() throws TopiaException; + long size() throws TopiaException; /** * Recherche la classe en utilisant la cle naturelle, chaque champs de la Modified: branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java =================================================================== --- branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2009-11-26 09:24:50 UTC (rev 1672) +++ branches/from2.2.2-eugene2-beta/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2009-11-27 17:01:06 UTC (rev 1673) @@ -752,15 +752,15 @@ } /** - * TODO implanter une facon plus rapide de recupere la size (count direct - * sur la base) ? - * - * Si la methode doit charger les objets, on faut le dire :) + * Utilisation du count(*) en HQL pour recuperer le nombre d'entites du type lie au DAO + * @return un long correspondant au nombre d'entités existantes en base */ @Override - public int size() throws TopiaException { - int result = findAll().size(); - return result; + public long size() throws TopiaException { + //int result = findAll().size(); + + List result = this.getContext().find("SELECT count(*) FROM " + getEntityClass().getName() + "Impl"); + return (Long)result.get(0); } @Override
Le Fri, 27 Nov 2009 18:01:07 +0100 (CET), fdesbois@users.nuiton.org a écrit :
- int size() throws TopiaException; + long size() throws TopiaException;
un peu violent :) le passage de int à long -- Tony Chemit -------------------- tél: +33 (0) 2 40 50 29 28 email: chemit@codelutin.com http://www.codelutin.com
participants (2)
-
fdesbois@users.nuiton.org -
Tony Chemit