@SuppressWarnings({"rawtypes", "unchecked"}) public int compare(Object o1, Object o2) { Comparable value1 = getComparable(o1); Comparable value2 = getComparable(o2); if (value1 == null) { if (value2 == null) { return 0; } else { return isAsc() ? -1 : 1; } } else if (value2 == null) { return isAsc() ? 1 : -1; } int compare = value1.compareTo(value2); if (isDesc()) { compare *= -1; } return compare; }
@Override public int compare(Object o1, Object o2) { for (QueryOrder order : postOrders) { int compare = order.compare(o1, o2); if (compare == 0) { continue; } return compare; } return 0; } });
public QueryBuilder<T> order(String property, String direction) { preOrders.add(new QueryOrder(null, property, direction)); return this; }
private String order() { if (CollectionUtils.isEmpty(builder.getPreOrders())) { return ""; } Class<?> clazz = builder.getModel().getClazz(); boolean first = true; StringBuilder sb = new StringBuilder(); sb.append(" order by "); for (QueryOrder order : builder.getPreOrders()) { if (!first) { sb.append(", "); } else { first = false; } sb.append(String.format("properties->>'%s'", getActualFieldName(order.getProperty(), clazz))); if (order.isDesc()) { sb.append(" desc"); } } return sb.toString(); }
private void assertOrderEquals(String property, String direction, QueryOrder order) { assertEquals(property, order.getProperty()); assertEquals(direction, order.getDirection()); } }
private void prepareQueryOrder(QueryBuilder<?> builder, Query q) { if (builder.getPreOrders().isEmpty()) { return; } for (QueryOrder order : builder.getPreOrders()) { String string = getActualFieldName(order.getProperty(), builder.getModel().getClazz()); q.addSort(string, getSortDirection(order)); } }
@Override public int compare(Object o1, Object o2) { for (QueryOrder order : preOrders) { int compare = order.compare(o1, o2); if (compare == 0) { continue; } return compare; } return 0; } });
public QueryBuilder<T> sort(String entity, String property, String direction) { postOrders.add(new QueryOrder(entity, property, direction)); return this; }
private List<QueryOrder> parseOrders(JsonArray jsonArray) { if (jsonArray == null) { return null; } List<QueryOrder> orders = new ArrayList<>(); for (JsonElement jsonElement : jsonArray) { String entity = getJsonStringValue(jsonElement, "e"); String property = getJsonStringValue(jsonElement, "p"); String direction = getJsonStringValue(jsonElement, "d"); orders.add(new QueryOrder(entity, property, direction)); } return orders; }