/** * Instead of a property for this Sort, use a free-form JPQL/HQL order-by * expression. Reference properties by wrapping them with curly braces ({}). * * <p>Here are some examples: * <pre> * Sort.customExpressionAsc("cast({employeeno} as integer)"); * Sort.customExpressionAsc("abs({prop1} - {prop2})"); * </pre> */ public static Sort customExpressionAsc(String expression) { return new Sort(true, expression); }
sb.append(", "); if (sort.isCustomExpression()) { appendCustomExpression(sb, ctx, sort.getProperty()); } else if (sort.isIgnoreCase() && metadataUtil.get(ctx.rootClass, sort.getProperty()).isString()) { sb.append("lower("); sb.append(getPathRef(ctx, sort.getProperty())); sb.append(")"); } else { sb.append(getPathRef(ctx, sort.getProperty())); sb.append(sort.isDesc() ? " desc" : " asc");
private Order getOrder(final Sort sort) { if (sort.isDesc()) { return Order.desc(sort.getProperty()); } else { return Order.asc(sort.getProperty()); } }
public static void removeSort(IMutableSearch search, String property) { if (property == null || search.getSorts() == null) return; Iterator<Sort> itr = search.getSorts().iterator(); while (itr.hasNext()) { if (property.equals(itr.next().getProperty())) itr.remove(); } }
/** * Modify the search by adding the given sorts after the current sorts in * the search. */ public static void mergeSortsAfter(IMutableSearch search, List<Sort> sorts) { List<Sort> list = search.getSorts(); if (list == null) { list = new ArrayList<Sort>(); search.setSorts(list); } int origLen = list.size(); if (origLen > 0) { // don't add sorts that are already in the list for (Sort sort : sorts) { if (sort.getProperty() != null) { boolean found = false; for (int i = 0; i < origLen; i++) { if (sort.getProperty().equals(list.get(i).getProperty())) { found = true; break; } } if (!found) list.add(sort); } } } else { list.addAll(sorts); } }
/** * Modify the search by adding the given sorts before the current sorts in * the search. */ public static void mergeSortsBefore(IMutableSearch search, List<Sort> sorts) { List<Sort> list = search.getSorts(); if (list == null) { list = new ArrayList<Sort>(); search.setSorts(list); } if (list.size() > 0) { // remove any sorts from the search that already sort on the same // property as one of the new sorts Iterator<Sort> itr = list.iterator(); while (itr.hasNext()) { String property = itr.next().getProperty(); if (property == null) { itr.remove(); } else { for (Sort sort : sorts) { if (property.equals(sort.getProperty())) { itr.remove(); break; } } } } } list.addAll(0, sorts); }
/** * Instead of a property for this Sort, use a free-form JPQL/HQL order-by * expression. Reference properties by wrapping them with curly braces ({}). * * <p>Here are some examples: * <pre> * Sort.customExpressionDesc("cast({employeeno} as integer)"); * Sort.customExpressionDesc("abs({prop1} - {prop2})"); * </pre> */ public static Sort customExpressionDesc(String expression) { return new Sort(true, expression, true); }
public static Sort asc(String property) { return new Sort(property); }
public static Sort desc(String property) { return new Sort(property, true); }
public static Sort asc(String property, boolean ignoreCase) { return new Sort(property, ignoreCase); }
public static Sort desc(String property, boolean ignoreCase) { return new Sort(property, true, ignoreCase); }
/** * Add sort by property. Ascending if <code>desc == false</code>, descending * if <code>desc == true</code>. */ public static void addSort(IMutableSearch search, String property, boolean desc, boolean ignoreCase) { if (property == null) return; // null properties do nothing, don't bother to add them. addSort(search, new Sort(property, desc, ignoreCase)); }