/** * Appends the Id property to the OrderBy clause if it is not believed * to be already contained in the order by. * <p> * This is primarily used for paging queries to ensure that an order by clause is provided and that the order by * provides unique ordering of the rows (so that the paging is predicable). * </p> */ public void appendOrderById(SpiQuery<T> query) { if (idProperty != null && !idProperty.isEmbedded() && !query.order().containsProperty(idProperty.getName())) { query.order().asc(idProperty.getName()); } }
private String parseInternal() { StringBuilder sb = new StringBuilder(); List<Property> properties = orderBy.getProperties(); if (properties.isEmpty()) { // order by clause removed by filterMany() return null; } for (int i = 0; i < properties.size(); i++) { if (i > 0) { sb.append(", "); } Property p = properties.get(i); String expression = parseProperty(p); sb.append(expression); } return sb.toString(); }
private Property parseProperty(String chunk) { String[] pairs = chunk.split(" "); if (pairs.length == 0) { return null; } ArrayList<String> wordList = new ArrayList<>(pairs.length); for (String pair : pairs) { if (!isEmptyString(pair)) { wordList.add(pair); } } if (wordList.isEmpty()) { return null; } if (wordList.size() == 1) { return new Property(wordList.get(0), true); } if (wordList.size() == 2) { boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc); } if (wordList.size() == 4) { // nulls high or nulls low as 3rd and 4th boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc, wordList.get(2), wordList.get(3)); } return new Property(chunk.trim(), true); }
@Override public OrderBy<T> order() { if (orderBy == null) { orderBy = new OrderBy<>(this, null); } return orderBy; }
@Override public boolean orderByIsEmpty() { return orderBy == null || orderBy.isEmpty(); }
@Override public void enterOrderby_property(EQLParser.Orderby_propertyContext ctx) { int childCount = ctx.getChildCount(); String path = child(ctx, 0); boolean asc = true; String nulls = null; String nullsFirstLast = null; if (childCount == 3) { asc = child(ctx, 1).startsWith(ASC); nullsFirstLast = ctx.getChild(2).getChild(1).getText(); nulls = NULLS; } else if (childCount == 2) { String firstChild = child(ctx, 1); if (firstChild.startsWith(NULLS)) { nullsFirstLast = ctx.getChild(1).getChild(1).getText(); nulls = NULLS; } else { asc = firstChild.startsWith(ASC); } } query.orderBy().add(new OrderBy.Property(path, asc, nulls, nullsFirstLast)); }
/** * Order by descending on this property. */ public R desc() { expr().order().desc(_name); return _root; }
/** * Order by ascending on this property. */ public R asc() { expr().order().asc(_name); return _root; }
/** * Define the select and joins for this query. */ @SuppressWarnings("unchecked") public void configureBeanQuery(SpiQuery<?> query) { if (trimmedProperties != null && !trimmedProperties.isEmpty()) { query.select(trimmedProperties); } if (filterMany != null) { SpiExpressionList<?> trimPath = filterMany.trimPath(path.length() + 1); List<SpiExpression> underlyingList = trimPath.getUnderlyingList(); for (SpiExpression spiExpression : underlyingList) { query.where().add(spiExpression); } } if (secondaryChildren != null) { int trimPath = path.length() + 1; for (OrmQueryProperties p : secondaryChildren) { String path = p.getPath(); path = path.substring(trimPath); query.fetch(path, p.getProperties(), p.getFetchConfig()); query.setFilterMany(path, p.getFilterManyTrimPath(trimPath)); } } if (orderBy != null) { query.setOrder(orderBy.copyWithTrim(path)); } }
copy.maxRows = maxRows; if (orderBy != null) { copy.orderBy = orderBy.copy();
@Override public DefaultOrmQuery<T> order(String orderByClause) { if (orderByClause == null || orderByClause.trim().isEmpty()) { this.orderBy = null; } else { this.orderBy = new OrderBy<>(this, orderByClause); } return this; }
@Override public boolean orderByIsEmpty() { return orderBy == null || orderBy.isEmpty(); }
/** * <p>appendOrder.</p> * * @param orderBy a {@link io.ebean.OrderBy} object. * @param orderByClause a {@link java.lang.String} object. * @param <T> a T object. */ public static <T> void appendOrder(OrderBy<T> orderBy, String orderByClause) { if (orderByClause == null) { return; } String[] chunks = orderByClause.split(","); for (String chunk : chunks) { String[] pairs = chunk.split(" "); Property p = parseOrderProperty(pairs); if (p != null) { orderBy.add(p); } } }
private Property parseProperty(String chunk) { String[] pairs = chunk.split(" "); if (pairs.length == 0) { return null; } ArrayList<String> wordList = new ArrayList<>(pairs.length); for (String pair : pairs) { if (!isEmptyString(pair)) { wordList.add(pair); } } if (wordList.isEmpty()) { return null; } if (wordList.size() == 1) { return new Property(wordList.get(0), true); } if (wordList.size() == 2) { boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc); } if (wordList.size() == 4) { // nulls high or nulls low as 3rd and 4th boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc, wordList.get(2), wordList.get(3)); } return new Property(chunk.trim(), true); }
/** * Define the select and joins for this query. */ @SuppressWarnings("unchecked") public void configureBeanQuery(SpiQuery<?> query) { if (trimmedProperties != null && !trimmedProperties.isEmpty()) { query.select(trimmedProperties); } if (filterMany != null) { SpiExpressionList<?> trimPath = filterMany.trimPath(path.length() + 1); List<SpiExpression> underlyingList = trimPath.getUnderlyingList(); for (SpiExpression spiExpression : underlyingList) { query.where().add(spiExpression); } } if (secondaryChildren != null) { int trimPath = path.length() + 1; for (OrmQueryProperties p : secondaryChildren) { String path = p.getPath(); path = path.substring(trimPath); query.fetch(path, p.getProperties(), p.getFetchConfig()); query.setFilterMany(path, p.getFilterManyTrimPath(trimPath)); } } if (orderBy != null) { query.setOrder(orderBy.copyWithTrim(path)); } }
copy.maxRows = maxRows; if (orderBy != null) { copy.orderBy = orderBy.copy();