Author: fdesbois Date: 2010-02-25 14:58:22 +0100 (Thu, 25 Feb 2010) New Revision: 1814 Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java Log: [TopiaQuery] add method : addNullOr to manage an element that is null or depends on some value 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-02-23 18:11:49 UTC (rev 1813) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-02-25 13:58:22 UTC (rev 1814) @@ -641,7 +641,8 @@ * @param paramName the name of the parameter in the query (attribute of * the entity) * @param constraint the operation concerned - * @param paramValue the value of the parameter (an other entity, a String, ...) + * @param paramValue the value of the parameter (an other entity, a String, + * ...) * @return the TopiaQuery */ public TopiaQuery add(String paramName, Op constraint, Object paramValue) { @@ -657,6 +658,28 @@ return add(result.toString()); } + /** + * Add an element to the query. The nullity is tested or a constraint is + * added for that element. Ex : addNullOr("begin", Op.GT, new Date()) means + * begin IS NULL OR begin > :begin (where :begin = new Date()). + * + * @param paramName the name of the parameter in the query (attribute of + * the entity) + * @param constraint the operation concerned by the or + * @param paramValue the value of the parameter (an other entity, a String, + * ...) + * @return the TopiaQuery + */ + public TopiaQuery addNullOr(String paramName, Op constraint, Object paramValue) { + String valueName = getValueName(paramName); + StringBuilder result = + new StringBuilder(paramName).append(' ').append(Op.NULL). + append(" OR ").append(paramName).append(constraint). + append(" :").append(valueName); + addParam(valueName, paramValue); + return add(result.toString()); + } + protected String getValueName(String paramName) { int dot = paramName.lastIndexOf('.'); String valueName = paramName;