Author: fdesbois Date: 2010-05-26 11:15:19 +0200 (Wed, 26 May 2010) New Revision: 1974 Url: http://nuiton.org/repositories/revision/topia/1974 Log: Evo #637 : add count() method in DAO, deprecate size() in TopiaDAO and executeCount() in TopiaQuery Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-05-26 09:12:03 UTC (rev 1973) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-05-26 09:15:19 UTC (rev 1974) @@ -1128,6 +1128,19 @@ } /** + * DAO must be defined to use this method. + * + * @param select part of the query redefined temporarly for execution. + * @return an Object + * @throws TopiaException for error on query execution + * @see #executeToObject(TopiaContext, String) + */ + public Object executeToObject(String select) throws TopiaException { + validateDAO(); + return executeToObject(dao.getContext(), select); + } + + /** * Execute the query and get an Integer for result. Used only for query with * aggration select which return a Long : COUNT, SUM ... The select is * overriden to get only the right value for return. @@ -1185,19 +1198,6 @@ } /** - * DAO must be defined to use this method. - * - * @param select part of the query redefined temporarly for execution. - * @return an Object - * @throws TopiaException for error on query execution - * @see #executeToObject(TopiaContext, String) - */ - public Object executeToObject(String select) throws TopiaException { - validateDAO(); - return executeToObject(dao.getContext(), select); - } - - /** * Execute a simple count on the query, i.e. the number of results get from * the query. The order is not considered to count the elements and will be * temporarly disabled. The distinct constraint will be manage if necessary @@ -1235,7 +1235,9 @@ * @return an int corresponding to the number of result in the query * @throws TopiaException for error on query execution * @see #executeCount(TopiaContext) + * @deprecated since 2.4, use {@link TopiaDAO#countByQuery(TopiaQuery)} */ + @Deprecated public int executeCount() throws TopiaException { validateDAO(); return executeCount(dao.getContext()); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-26 09:12:03 UTC (rev 1973) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2010-05-26 09:15:19 UTC (rev 1974) @@ -403,10 +403,30 @@ * * @return le nombre total d'entites existantes * @throws TopiaException if any pb while getting datas + * @deprecated since 2.4 ambiguous name, use {@link #count()} instead. */ + @Deprecated long size() throws TopiaException; /** + * Count the number of existing entities. + * + * @return number of total entities + * @throws TopiaException if any pb while getting datas + * @since 2.4 + */ + int count() throws TopiaException; + + /** + * Count the number of entities based on {@code query}. + * + * @return number of entities filtered by the query + * @throws TopiaException if any pb while getting datas + * @since 2.4 + */ + int countByQuery(TopiaQuery query) throws TopiaException; + + /** * Recherche la classe en utilisant la cle naturelle, chaque champs de la * cle naturelle est une entre de la map passe en argument. * Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-26 09:12:03 UTC (rev 1973) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2010-05-26 09:15:19 UTC (rev 1974) @@ -624,12 +624,24 @@ * Count number of existing entities using {@link TopiaQuery#executeCount(TopiaContext)} * * @return a long for the number of entities in database + * @deprecated since 2.4 ambiguous name, use {@link #count()} instead. */ @Override + @Deprecated public long size() throws TopiaException { - return createQuery().executeCount(context); + return count(); } + @Override + public int count() throws TopiaException { + return countByQuery(createQuery()); + } + + @Override + public int countByQuery(TopiaQuery query) throws TopiaException { + return query.executeCount(context); + } + /** * Convert a properties array to a proper map used to find entities in * methods {@link #findByProperties(String, Object, Object...)} and {@link