r1911 - in trunk/topia-persistence/src: main/java/org/nuiton/topia/framework site/rst
Author: fdesbois Date: 2010-04-27 18:26:36 +0200 (Tue, 27 Apr 2010) New Revision: 1911 Log: [TopiaQuery] - correct documentation for null case - add method addInElements + ignore problematic orderBy in executeCount Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java trunk/topia-persistence/src/site/rst/TopiaQuery.rst 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-04-23 14:35:05 UTC (rev 1910) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-04-27 16:26:36 UTC (rev 1911) @@ -798,6 +798,26 @@ } /** + * Add link constraint between two properties. {@code propertyA} is in + * elements of {@code propertyB} which is a collection with same type than + * {@code propertyA}. (HQL : A IN elements (B)) + * + * @param propertyA contains in propertyB collection + * @param propertyB collection which contains propertyA + * @return the TopiaQuery + */ + public TopiaQuery addInElements(String propertyA, String propertyB) { + StringBuilder builder = new StringBuilder(propertyA). + append("IN elements ("). + append(propertyB). + append(')'); + parentheses = false; + add(builder.toString()); + parentheses = true; + return this; + } + + /** * Add an element to the select in the query. Depends on the result wanted * in execute methods. The main entity will be automatically added only if * an alias is initialize from constructor. If you want only this select @@ -1257,14 +1277,18 @@ /** * Execute a simple count on the query, i.e. the number of results get from - * the query. + * the query. The order is not considered to count the elements. * * @param transaction the TopiaContext to use for execution * @return an int corresponding to the number of result in the query * @throws TopiaException */ public int executeCount(TopiaContext transaction) throws TopiaException { - return executeToInteger(transaction, "COUNT(*)"); + StringBuilder oldOrder = orderBy; + orderBy = null; + int result = executeToInteger(transaction, "COUNT(*)"); + orderBy = oldOrder; + return result; } /** Modified: trunk/topia-persistence/src/site/rst/TopiaQuery.rst =================================================================== --- trunk/topia-persistence/src/site/rst/TopiaQuery.rst 2010-04-23 14:35:05 UTC (rev 1910) +++ trunk/topia-persistence/src/site/rst/TopiaQuery.rst 2010-04-27 16:26:36 UTC (rev 1911) @@ -104,10 +104,10 @@ query.addNotNull("name"); // Recherche des navires n'ayant pas de nom - query.add("name", null); + query.add("name", Op.EQ, null); // Recherche des navires ayant une date de construction 2003, 2004 ou 2006 - query.add("buildYear", Arrays.asList(new Object[] {2003, 2004, 2006})); + query.add("buildYear", 2003, 2004, 2006); Il est fortement conseillé d'utiliser les constantes des entités pour les noms de leurs propriétés ::
participants (1)
-
fdesbois@users.nuiton.org