Author: fdesbois Date: 2010-01-13 19:33:02 +0100 (Wed, 13 Jan 2010) New Revision: 1757 Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java Log: Add management for multiple values for a single param 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-01-10 23:16:09 UTC (rev 1756) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-01-13 18:33:02 UTC (rev 1757) @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -369,12 +370,12 @@ * Add a HQL parameter to the Query. * * @param id identification of the param in the query - * @param e value of the param + * @param paramValue value of the param * @return the TopiaQuery */ - public TopiaQuery<E> addParam(String id, Object e) { + public TopiaQuery<E> addParam(String id, Object paramValue) { getParams().add(id); - getParams().add(e); + getParams().add(paramValue); return this; } @@ -442,6 +443,7 @@ /** * Add an element to the query. The parameter will be automatically added. * The constraint is needed to determine what type of operation it is. + * Ex : add("boat", Op.EQ, boat) means -> boat = :boat. * * @param paramName the name of the parameter in the query (attribute of the entity) * @param constraint the operation concerned @@ -460,6 +462,9 @@ if (dot != -1) { valueName = paramName.substring(dot+1); } + if (getParams().contains(valueName)) { + valueName = valueName + "_" + RandomStringUtils.randomAlphanumeric(4); + } return valueName; } @@ -520,7 +525,7 @@ queryIn += paramName + " IN ("; int count = 1; for (Object value : values) { - String valueName = getValueName(paramName) + count; + String valueName = getValueName(paramName + count); if (count != 1) { queryIn += ", "; }