r1977 - trunk/topia-persistence/src/main/java/org/nuiton/topia/framework
Author: fdesbois Date: 2010-05-26 13:39:47 +0200 (Wed, 26 May 2010) New Revision: 1977 Url: http://nuiton.org/repositories/revision/topia/1977 Log: setFrom with String not necessary, use addFrom with separator argument for join support Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.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 10:08:58 UTC (rev 1976) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2010-05-26 11:39:47 UTC (rev 1977) @@ -234,6 +234,8 @@ private static final Log log = LogFactory.getLog(TopiaQuery.class); + public static final String DEFAULT_FROM_SEPARATOR = ", "; + /** Params for HQL query * */ protected List<Object> params; @@ -400,13 +402,33 @@ /** * Add an element to the from in the query. Used to add some other data in - * the query or for join. + * the query. The default separator used is the ", ". * * @param str the element to add * @return the TopiaQuery + * @see #addFrom(String, String) + * @deprecated since 2.4 use {@link #addFrom(String, String)} */ + @Deprecated public TopiaQuery addFrom(String str) { - from.append(", ").append(str); + return addFrom(str, null); + } + + /** + * Add an element to the from in the query. Used to add some other data in + * the query or for join as specific {@code separator}. + * + * @param str the element to add + * @param separator The separator to use before adding the element (if null + * the {@link #DEFAULT_FROM_SEPARATOR} will be used). + * @return the TopiaQuery + * @since 2.4 + */ + public TopiaQuery addFrom(String str, String separator) { + if (separator == null) { + separator = DEFAULT_FROM_SEPARATOR; + } + from.append(separator).append(str); return this; } @@ -417,7 +439,7 @@ * @return the TopiaQuery */ public TopiaQuery addFrom(Class<? extends TopiaEntity> entityClass) { - return addFrom(entityClass.getName()); + return addFrom(entityClass.getName(), null); } /** @@ -429,7 +451,7 @@ */ public TopiaQuery addFrom(Class<? extends TopiaEntity> entityClass, String alias) { - return addFrom(entityClass.getName() + " " + alias); + return addFrom(entityClass.getName() + " " + alias, null); } /** @@ -497,10 +519,10 @@ /** * Method used to add a subquery in an existing query. The params will be * automatically checked and copied from the subquery to the current one. - * This method is used to inject {@code subquery} in WHERE part of the query. - * The {@code queryPart} is the element in the query to bind with the {@code - * subquery}. The ? character is used to inject the subquery - * into the {@code queryPart}. Ex : + * This method is used to inject {@code subquery} in WHERE part of the + * query. The {@code queryPart} is the element in the query to bind with the + * {@code subquery}. The ? character is used to inject the subquery into the + * {@code queryPart}. Ex : * <pre> * // Add a SUB_ELMT = (subquery) into the query * query.addSubQuery("SUB_ELMT = (?)", subquery, false);
participants (1)
-
fdesbois@users.nuiton.org