/** * Return the last string element of this path, throw an exception of there is only one element, * i.e. for 'Company.departments.manager' return 'manager'. * @return the last string element of the path */ public String getLastElement() { if (isRootPath()) { throw new RuntimeException("path (" + this + ") has only one element"); } return elements.get(elements.size() - 1); }
/** * Return the last string element of this path, throw an exception of there is only one element, * i.e. for 'Company.departments.manager' return 'manager'. * @return the last string element of the path */ public String getLastElement() { if (isRootPath()) { throw new RuntimeException("path (" + this + ") has only one element"); } return elements.get(elements.size() - 1); }
/** * Returns a list of paths, each corresponding to one step further along the path. Starts with * the root path, and ends in the current path, ie: * * Company.departments.manager.name * decomposes to: * Company, Company.departments, Company.departments.manager, Company.departments.manager.name * * @return the list of composing paths. */ public List<Path> decomposePath() { List<Path> pathList = new ArrayList<Path>(); pathList.add(this); Path currentPath = this; while (!currentPath.isRootPath()) { Path nextPath = currentPath.getPrefix(); pathList.add(nextPath); currentPath = nextPath; } Collections.reverse(pathList); return pathList; }
/** * Returns a list of paths, each corresponding to one step further along the path. Starts with * the root path, and ends in the current path, ie: * * Company.departments.manager.name * decomposes to: * Company, Company.departments, Company.departments.manager, Company.departments.manager.name * * @return the list of composing paths. */ public List<Path> decomposePath() { List<Path> pathList = new ArrayList<Path>(); pathList.add(this); Path currentPath = this; while (!currentPath.isRootPath()) { Path nextPath = currentPath.getPrefix(); pathList.add(nextPath); currentPath = nextPath; } Collections.reverse(pathList); return pathList; }
/** * Return a Path object that represents the prefix of this path, ie this Path without the * last element. If the Path contains only the root class, an exception is thrown. * * @return the prefix Path */ public Path getPrefix() { if (isRootPath()) { throw new RuntimeException("path (" + this + ") has only one element"); } String pathString = toString(); int lastDotIndex = pathString.lastIndexOf('.'); int lastIndex = pathString.lastIndexOf(':'); if (lastDotIndex > lastIndex) { lastIndex = lastDotIndex; } try { return new Path(model, pathString.substring(0, lastIndex)); } catch (PathException e) { // Should not happen throw new Error("There must be a bug", e); } }
/** * Return a Path object that represents the prefix of this path, ie this Path without the * last element. If the Path contains only the root class, an exception is thrown. * * @return the prefix Path */ public Path getPrefix() { if (isRootPath()) { throw new RuntimeException("path (" + this + ") has only one element"); } String pathString = toString(); int lastDotIndex = pathString.lastIndexOf('.'); int lastIndex = pathString.lastIndexOf(':'); if (lastDotIndex > lastIndex) { lastIndex = lastDotIndex; } try { return new Path(model, pathString.substring(0, lastIndex)); } catch (PathException e) { // Should not happen throw new Error("There must be a bug", e); } }
/** * Adds all the parts of a Path to a Set. Call this with only a non-attribute Path. * * @param validMainPaths a Set of Strings to add to * @param path a Path object */ private static void addValidPaths(Set<String> validMainPaths, Path path) { Path pathToAdd = path; while (!pathToAdd.isRootPath()) { validMainPaths.add(pathToAdd.toStringNoConstraints()); pathToAdd = pathToAdd.getPrefix(); } validMainPaths.add(pathToAdd.toStringNoConstraints()); }
/** * Adds all the parts of a Path to a Set. Call this with only a non-attribute Path. * * @param validMainPaths a Set of Strings to add to * @param path a Path object */ private static void addValidPaths(Set<String> validMainPaths, Path path) { Path pathToAdd = path; while (!pathToAdd.isRootPath()) { validMainPaths.add(pathToAdd.toStringNoConstraints()); pathToAdd = pathToAdd.getPrefix(); } validMainPaths.add(pathToAdd.toStringNoConstraints()); }
continue; if (path.isRootPath()) { problems.add("Outer join status cannot be set on root path " + joinPath); continue;
continue; if (path.isRootPath()) { problems.add("Outer join status cannot be set on root path " + joinPath); continue;
while ((!path.isRootPath()) && (!root.equals(outerJoinGroups.get(path.getPrefix() .getNoConstraintsString())))) { path = path.getPrefix(); if (!path.isRootPath()) {
while ((!path.isRootPath()) && (!root.equals(outerJoinGroups.get(path.getPrefix() .getNoConstraintsString())))) { path = path.getPrefix(); if (!path.isRootPath()) {
while (!(groups.containsKey(groupPath.getNoConstraintsString()))) { toAdd.add(groupPath.toStringNoConstraints()); if (groupPath.isRootPath()) { break;
while (!(groups.containsKey(groupPath.getNoConstraintsString()))) { toAdd.add(groupPath.toStringNoConstraints()); if (groupPath.isRootPath()) { break;
public void testIsRootPath() throws Exception { Path path = new Path(model, "Department"); assertTrue(path.isRootPath()); path = new Path(model, "Department.manager"); assertFalse(path.isRootPath()); }
/** * Returns true if the given Path object represents a path that is inner-joined onto the parent * path in this query. This will return false for the root class. Do not call this method with * a Path that is an attribute. * * @param path a Path object * @return true if the join is inner, not outer and not the root * @throws IllegalArgumentException if the path is an attribute */ private boolean isInner(Path path) { if (path.isRootPath()) { return false; } if (path.endIsAttribute()) { throw new IllegalArgumentException("Cannot call isInner() with a path that is an " + "attribute"); } OuterJoinStatus status = getOuterJoinStatus(path.getNoConstraintsString()); if (OuterJoinStatus.INNER.equals(status)) { return true; } else if (OuterJoinStatus.OUTER.equals(status)) { return false; } // Fall back on defaults return true; }
/** * Returns true if the given Path object represents a path that is inner-joined onto the parent * path in this query. This will return false for the root class. Do not call this method with * a Path that is an attribute. * * @param path a Path object * @return true if the join is inner, not outer and not the root * @throws IllegalArgumentException if the path is an attribute */ private boolean isInner(Path path) { if (path.isRootPath()) { return false; } if (path.endIsAttribute()) { throw new IllegalArgumentException("Cannot call isInner() with a path that is an " + "attribute"); } OuterJoinStatus status = getOuterJoinStatus(path.getNoConstraintsString()); if (OuterJoinStatus.INNER.equals(status)) { return true; } else if (OuterJoinStatus.OUTER.equals(status)) { return false; } // Fall back on defaults return true; }
continue; if (subclassPath.isRootPath()) { problems.add("Root node " + subclass.getPath() + " may not have a subclass constraint");
continue; if (subclassPath.isRootPath()) { problems.add("Root node " + subclass.getPath() + " may not have a subclass constraint");
if (path.isRootPath()) { problems.add("Constraint " + constraint + " cannot be applied to the root path");