for (Iterator<OrderElement> it = order.iterator(); it.hasNext();) { OrderElement oe = it.next(); sb.append(String.format("{\"%s\":\"%s\"}", oe.getOrderPath(), oe.getDirection())); if (it.hasNext()) { sb.append(",");
private void updateOrderByPath(Map<String, String> renamedClasses, Map<String, String> renamedFields) throws PathException { String orderPath, newOrderPath; for (OrderElement orderElement : pathQuery.getOrderBy()) { orderPath = orderElement.getOrderPath(); newOrderPath = getPathUpdated(orderPath, renamedClasses, renamedFields); if (!newOrderPath.equals(orderPath)) { newPathQuery.addOrderBy(new OrderElement(newOrderPath, orderElement.getDirection())); } else { newPathQuery.addOrderBy(orderElement); } } }
/** * Removes an element from the order by list of this query. The element should be a normal path * expression, with dots separating the parts. Do not use colons to represent outer joins, and * do not use square brackets to represent subclass constraints. If there are multiple copies * of the path on the order by list (which is an invalid query), then this method will remove * all of them. * * @param orderPath the path String to remove from the order by list * @throws NullPointerException if the orderPath is null * @throws NoSuchElementException if the orderPath is not already in the order by list */ public synchronized void removeOrderBy(String orderPath) { deVerify(); checkPathFormat(orderPath); boolean found = false; int i = 0; while (i < orderBy.size()) { if (orderPath.equals(orderBy.get(i).getOrderPath())) { orderBy.remove(i); found = true; } else { i++; } } if (!found) { throw new NoSuchElementException("Path \"" + orderPath + "\" is not in the order by " + "list: \"" + orderBy + "\" - cannot remove it"); } }
q.addView("Employee.age"); q.addOrderBy("Employee.name", OrderDirection.ASC); assertEquals("Employee.name", q.getOrderBy().iterator().next().getOrderPath()); assertEquals(OrderDirection.ASC, q.getOrderBy().iterator().next().getDirection()); assertEquals(Collections.singletonList(new OrderElement("Employee.name", OrderDirection.ASC)), q.getOrderBy()); q.addOrderBys(new OrderElement("Employee.department.name", OrderDirection.ASC), new OrderElement("Employee.department.address.address", OrderDirection.DESC)); assertEquals(Arrays.asList(new OrderElement("Employee.name", OrderDirection.ASC), new OrderElement("Employee.department.name", OrderDirection.ASC), new OrderElement("Employee.department.address.address", OrderDirection.DESC)), q.getOrderBy()); Iterator<OrderElement> oeIter = q.getOrderBy().iterator(); OrderElement oe1 = oeIter.next(); OrderElement oe2 = oeIter.next(); assertFalse(oe1.equals(oe2)); assertTrue(oe1.equals(oe1)); assertFalse(oe1.hashCode() == oe2.hashCode()); assertFalse("Fred".equals(oe1)); assertTrue(oe1.equals(new OrderElement("Employee.name", OrderDirection.ASC))); assertFalse(oe1.equals(new OrderElement("Employee.name", OrderDirection.DESC))); q.removeOrderBy("Employee.name"); assertEquals(Arrays.asList(new OrderElement("Employee.department.name", OrderDirection.ASC), new OrderElement("Employee.department.address.address", OrderDirection.DESC)), q.getOrderBy()); try { q.removeOrderBy("lkjadsfldjsaf"); assertEquals(Arrays.asList(new OrderElement("Employee.department.name", OrderDirection.ASC), new OrderElement("Employee.department.address.address", OrderDirection.DESC)), q.getOrderBy()); q.addOrderBySpaceSeparated("Employee.name asc Employee.department.company.name desc"); assertEquals(Arrays.asList(new OrderElement("Employee.department.name", OrderDirection.ASC), new OrderElement("Employee.department.address.address", OrderDirection.DESC), new OrderElement("Employee.name", OrderDirection.ASC), new OrderElement("Employee.department.company.name", OrderDirection.DESC)), q.getOrderBy()); q.clearOrderBy(); assertEquals(Collections.EMPTY_LIST, q.getOrderBy()); try { new OrderElement("Emploelkjadf k adf asd", OrderDirection.ASC); fail("Expected IllegalArgumentException");
/** * Adds an element to the order by list of this query. The element should be a normal path * expression, with dots separating the parts. Do not use colons to represent outer joins, and * do not use square brackets to represent subclass constraints. The path will not be verified * until the verifyQuery() method is called, but will merely be checked for format. * * @param orderPath the path expression to add to the order by list * @param direction the sort order * @throws NullPointerException if orderPath or direction is null * @throws IllegalArgumentException if the orderPath contains colons or square brackets, or is * otherwise in a bad format */ public synchronized void addOrderBy(String orderPath, OrderDirection direction) { deVerify(); addOrderBy(new OrderElement(orderPath, direction)); }
/** * Removes an element from the order by list of this query. The element should be a normal path * expression, with dots separating the parts. Do not use colons to represent outer joins, and * do not use square brackets to represent subclass constraints. If there are multiple copies * of the path on the order by list (which is an invalid query), then this method will remove * all of them. * * @param orderPath the path String to remove from the order by list * @throws NullPointerException if the orderPath is null * @throws NoSuchElementException if the orderPath is not already in the order by list */ public synchronized void removeOrderBy(String orderPath) { deVerify(); checkPathFormat(orderPath); boolean found = false; int i = 0; while (i < orderBy.size()) { if (orderPath.equals(orderBy.get(i).getOrderPath())) { orderBy.remove(i); found = true; } else { i++; } } if (!found) { throw new NoSuchElementException("Path \"" + orderPath + "\" is not in the order by " + "list: \"" + orderBy + "\" - cannot remove it"); } }
for (int i = 0; i < orderPathArray.length - 1; i += 2) { if ("asc".equals(orderPathArray[i + 1].toLowerCase())) { toAdd.add(new OrderElement(orderPathArray[i], OrderDirection.ASC)); } else if ("desc".equals(orderPathArray[i + 1].toLowerCase())) { toAdd.add(new OrderElement(orderPathArray[i], OrderDirection.DESC)); } else { throw new IllegalArgumentException("Order direction \"" + orderPathArray[i + 1]
for (Iterator<OrderElement> it = order.iterator(); it.hasNext();) { OrderElement oe = it.next(); sb.append(String.format("{\"%s\":\"%s\"}", oe.getOrderPath(), oe.getDirection())); if (it.hasNext()) { sb.append(",");
for (OrderElement order : getOrderBy()) { String orderString = order.getOrderPath(); boolean outer = false; while (orderString.contains(".")) { removeOrderBy(order.getOrderPath()); messages.add("Removed path " + order.getOrderPath() + " from ORDER BY because of " + "outer joins");
private void updateOrderByPath(Map<String, String> renamedClasses, Map<String, String> renamedFields) throws PathException { String orderPath, newOrderPath; for (OrderElement orderElement : pathQuery.getOrderBy()) { orderPath = orderElement.getOrderPath(); newOrderPath = getPathUpdated(orderPath, renamedClasses, renamedFields); if (!newOrderPath.equals(orderPath)) { newPathQuery.addOrderBy(new OrderElement(newOrderPath, orderElement.getDirection())); } else { newPathQuery.addOrderBy(orderElement); } } }
/** * Adds an element to the order by list of this query. The element should be a normal path * expression, with dots separating the parts. Do not use colons to represent outer joins, and * do not use square brackets to represent subclass constraints. The path will not be verified * until the verifyQuery() method is called, but will merely be checked for format. * * @param orderPath the path expression to add to the order by list * @param direction the sort order * @throws NullPointerException if orderPath or direction is null * @throws IllegalArgumentException if the orderPath contains colons or square brackets, or is * otherwise in a bad format */ public synchronized void addOrderBy(String orderPath, OrderDirection direction) { deVerify(); addOrderBy(new OrderElement(orderPath, direction)); }
sort.append(oe.getOrderPath() + (oe.getDirection().equals(OrderDirection .ASC) ? " asc" : " desc"));
for (OrderElement order : getOrderBy()) { String orderString = order.getOrderPath(); boolean outer = false; while (orderString.contains(".")) { removeOrderBy(order.getOrderPath()); messages.add("Removed path " + order.getOrderPath() + " from ORDER BY because of " + "outer joins");
for (int i = 0; i < orderPathArray.length - 1; i += 2) { if ("asc".equals(orderPathArray[i + 1].toLowerCase())) { toAdd.add(new OrderElement(orderPathArray[i], OrderDirection.ASC)); } else if ("desc".equals(orderPathArray[i + 1].toLowerCase())) { toAdd.add(new OrderElement(orderPathArray[i], OrderDirection.DESC)); } else { throw new IllegalArgumentException("Order direction \"" + orderPathArray[i + 1]
sort.append(oe.getOrderPath() + (oe.getDirection().equals(OrderDirection .ASC) ? " asc" : " desc"));
Path path = new Path(model, orderPath.getOrderPath(), subclasses); if (!path.endIsAttribute()) { problems.add("Path " + orderPath.getOrderPath() + " in order by list must be " + "an attribute"); continue; problems.add("Order by element for path " + orderPath.getOrderPath() + " is not relevant to the query"); continue; problems.add("Path " + orderPath.getOrderPath() + " in order by list is not in the model"); continue;
Query qu = (Query) q; for (OrderElement order : pathQuery.getOrderBy()) { QueryField qf = (QueryField) queryBits.get(order.getOrderPath()); if (qf == null) { Path path = new Path(model, order.getOrderPath(), subclasses); QueryClass qc = (QueryClass) queryBits.get(path.getPrefix() .getNoConstraintsString()); qf = new QueryField(qc, path.getLastElement()); queryBits.put(order.getOrderPath(), qf); if (order.getDirection().equals(OrderDirection.DESC)) { qu.addToOrderBy(new OrderDescending(qf)); } else {
Path path = new Path(model, orderPath.getOrderPath(), subclasses); if (!path.endIsAttribute()) { problems.add("Path " + orderPath.getOrderPath() + " in order by list must be " + "an attribute"); continue; problems.add("Order by element for path " + orderPath.getOrderPath() + " is not relevant to the query"); continue; problems.add("Path " + orderPath.getOrderPath() + " in order by list is not in the model"); continue;
if (// The default query.getOrderBy().size() == 1 && query.getOrderBy().get(0).getOrderPath().equals(query.getView().get(0)) && query.getOrderBy().get(0).getDirection() == OrderDirection.ASC) { sb.append("# " + DEFAULT_SO_MSG + endl + "# "); } else { sb.append("\"" + oe.getOrderPath() + "\", \"" + oe.getDirection() + "\""); sb.append(")" + endl);
templateQuery.removeView(viewPath); for (OrderElement oe : templateQuery.getOrderBy()) { if (oe.getOrderPath().equals(viewPath)) { templateQuery.removeOrderBy(viewPath); break;