if (!search.isDistinct()) { sb.append("select count(").append(rootAlias).append(")"); } else if (fields.size() == 0) {
/** * Generate the QL string for a given search. Fill paramList with the values * to be used for the query. All parameters within the query string are * specified as named parameters ":pX", where X is the index of the * parameter value in paramList. */ public String generateQL(Class<?> entityClass, ISearch search, List<Object> paramList) { if (entityClass == null) throw new NullPointerException("The entity class for a search cannot be null"); SearchContext ctx = new SearchContext(entityClass, rootAlias, paramList); List<Field> fields = checkAndCleanFields(search.getFields()); applyFetches(ctx, checkAndCleanFetches(search.getFetches()), fields); String select = generateSelectClause(ctx, fields, search.isDistinct()); String where = generateWhereClause(ctx, checkAndCleanFilters(search.getFilters()), search.isDisjunction()); String orderBy = generateOrderByClause(ctx, checkAndCleanSorts(search.getSorts())); String from = generateFromClause(ctx, true); StringBuilder sb = new StringBuilder(); sb.append(select); sb.append(from); sb.append(where); sb.append(orderBy); String query = sb.toString(); if (logger.isDebugEnabled()) logger.debug("generateQL:\n " + query); return query; }
/** * Copy the contents of the source search object to the destination search * object, overriding any contents previously found in the destination. All * destination properties reference the same objects from the source * properties. */ public static IMutableSearch shallowCopy(ISearch source, IMutableSearch destination) { destination.setSearchClass(source.getSearchClass()); destination.setDistinct(source.isDistinct()); destination.setDisjunction(source.isDisjunction()); destination.setResultMode(source.getResultMode()); destination.setFirstResult(source.getFirstResult()); destination.setPage(source.getPage()); destination.setMaxResults(source.getMaxResults()); destination.setFetches(source.getFetches()); destination.setFields(source.getFields()); destination.setFilters(source.getFilters()); destination.setSorts(source.getSorts()); return destination; }