private void addSort(final Criteria criteria, final ISearch search) { final List<Sort> sorts = search.getSorts(); for (final Sort sort : sorts) { criteria.addOrder(getOrder(sort)); } }
/** * Return a hash code value for the given search. */ public static int hashCode(ISearch search) { int hash = 1; hash = hash * 31 + (search.getSearchClass() == null ? 0 : search.getSearchClass().hashCode()); hash = hash * 31 + (search.getFields() == null ? 0 : search.getFields().hashCode()); hash = hash * 31 + (search.getFilters() == null ? 0 : search.getFilters().hashCode()); hash = hash * 31 + (search.getSorts() == null ? 0 : search.getSorts().hashCode()); hash = hash * 31 + (search.isDisjunction() ? 1 : 0); hash = hash * 31 + (new Integer(search.getResultMode()).hashCode()); hash = hash * 31 + (new Integer(search.getFirstResult()).hashCode()); hash = hash * 31 + (new Integer(search.getPage()).hashCode()); hash = hash * 31 + (new Integer(search.getMaxResults()).hashCode()); return hash; }
/** * Copy the contents of the source search object to the destination search * object, overriding any contents previously found in the destination. All * collections are copied into new collections, but the items in those * collections are not duplicated; they still point to the same objects. */ public static <T extends IMutableSearch> T copy(ISearch source, T destination) { shallowCopy(source, destination); ArrayList<String> fetches = new ArrayList<String>(); fetches.addAll(source.getFetches()); destination.setFetches(fetches); ArrayList<Field> fields = new ArrayList<Field>(); fields.addAll(source.getFields()); destination.setFields(fields); ArrayList<Filter> filters = new ArrayList<Filter>(); filters.addAll(source.getFilters()); destination.setFilters(filters); ArrayList<Sort> sorts = new ArrayList<Sort>(); sorts.addAll(source.getSorts()); destination.setSorts(sorts); return destination; }
appendList(sb, search.getFilters(), ",\n "); sb.append("\n },\n sorts: { "); appendList(sb, search.getSorts(), ", "); sb.append(" }\n}");
/** * 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; }
/** * Return true if the search objects have equivalent contents. */ public static boolean equals(ISearch search, Object obj) { if (search == obj) return true; if (!(obj instanceof ISearch)) return false; ISearch s = (ISearch) obj; if (search.getSearchClass() == null ? s.getSearchClass() != null : !search.getSearchClass().equals( s.getSearchClass())) return false; if (search.isDisjunction() != s.isDisjunction() || search.getResultMode() != s.getResultMode() || search.getFirstResult() != s.getFirstResult() || search.getPage() != s.getPage() || search.getMaxResults() != s.getMaxResults()) return false; if (search.getFetches() == null ? s.getFetches() != null : !search.getFetches().equals(s.getFetches())) return false; if (search.getFields() == null ? s.getFields() != null : !search.getFields().equals(s.getFields())) return false; if (search.getFilters() == null ? s.getFilters() != null : !search.getFilters().equals(s.getFilters())) return false; if (search.getSorts() == null ? s.getSorts() != null : !search.getSorts().equals(s.getSorts())) return false; return true; }
/** * 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; }