/** * 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; }
private static Path getPathOfClass(TemplateQuery template, String pathStr) throws PathException { Path path = template.makePath(pathStr); if (path.endIsAttribute()) { path = path.getPrefix(); } return path; }
private static Path getPathOfClass(TemplateQuery template, String pathStr) throws PathException { Path path = template.makePath(pathStr); if (path.endIsAttribute()) { path = path.getPrefix(); } return path; }
/** * 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()); }
/** * Returns the outer join group that the given path is in. * * @param stringPath a pathString * @return a String representing the outer join group that the path is in * @throws NullPointerException if pathString is null * @throws PathException if the query is invalid or the path is invalid * @throws NoSuchElementException is the path is not in the query */ public String getOuterJoinGroup(String stringPath) throws PathException { if (stringPath == null) { throw new NullPointerException("stringPath is null"); } Map<String, String> groups = getOuterJoinGroups(); Path path = makePath(stringPath); if (path.endIsAttribute()) { path = path.getPrefix(); } if (!groups.containsKey(path.getNoConstraintsString())) { throw new NoSuchElementException("Path " + stringPath + " is not in the query"); } return groups.get(path.getNoConstraintsString()); }
Path path = new Path(model, validPath, subclasses); while (isInner(path)) { path = path.getPrefix();
/** * Returns the outer join group that the given path is in. * * @param stringPath a pathString * @return a String representing the outer join group that the path is in * @throws NullPointerException if pathString is null * @throws PathException if the query is invalid or the path is invalid * @throws NoSuchElementException is the path is not in the query */ public String getOuterJoinGroup(String stringPath) throws PathException { if (stringPath == null) { throw new NullPointerException("stringPath is null"); } Map<String, String> groups = getOuterJoinGroups(); Path path = makePath(stringPath); if (path.endIsAttribute()) { path = path.getPrefix(); } if (!groups.containsKey(path.getNoConstraintsString())) { throw new NoSuchElementException("Path " + stringPath + " is not in the query"); } return groups.get(path.getNoConstraintsString()); }
Path path = new Path(model, validPath, subclasses); while (isInner(path)) { path = path.getPrefix();
/** * Populate a TemplateQuery that has a single editable constraint with the given value. This * returns a copy of the template with the value filled in. * @param template the template query to populate * @param op operation of the constraint * @param value value to be constrained to * @return a copy of the template with the value filled in * @throws PathException if the template is invalid */ public static TemplateQuery populateTemplateOneConstraint( TemplateQuery template, ConstraintOp op, String value) throws PathException { Map<String, List<TemplateValue>> templateValues = new HashMap<String, List<TemplateValue>>(); if (template.getEditableConstraints().size() != 1) { throw new RuntimeException("Template must have exactly one editable constraint to be " + " configured with a single value."); } String editablePath = template.getEditablePaths().get(0); Path path = template.makePath(editablePath); if (path.endIsAttribute()) { path = path.getPrefix(); } PathConstraint constraint = template.getEditableConstraints(editablePath).get(0); TemplateValue templateValue = new TemplateValue(constraint, op, value, TemplateValue.ValueType.SIMPLE_VALUE, SwitchOffAbility.ON); templateValues.put(constraint.getPath(), new ArrayList<TemplateValue>(Collections.singleton(templateValue))); return TemplatePopulator.getPopulatedTemplate(template, templateValues); }
/** * Populate a TemplateQuery that has a single editable constraint with the given value. This * returns a copy of the template with the value filled in. * @param template the template query to populate * @param op operation of the constraint * @param value value to be constrained to * @return a copy of the template with the value filled in * @throws PathException if the template is invalid */ public static TemplateQuery populateTemplateOneConstraint( TemplateQuery template, ConstraintOp op, String value) throws PathException { Map<String, List<TemplateValue>> templateValues = new HashMap<String, List<TemplateValue>>(); if (template.getEditableConstraints().size() != 1) { throw new RuntimeException("Template must have exactly one editable constraint to be " + " configured with a single value."); } String editablePath = template.getEditablePaths().get(0); Path path = template.makePath(editablePath); if (path.endIsAttribute()) { path = path.getPrefix(); } PathConstraint constraint = template.getEditableConstraints(editablePath).get(0); TemplateValue templateValue = new TemplateValue(constraint, op, value, TemplateValue.ValueType.SIMPLE_VALUE, SwitchOffAbility.ON); templateValues.put(constraint.getPath(), new ArrayList<TemplateValue>(Collections.singleton(templateValue))); return TemplatePopulator.getPopulatedTemplate(template, templateValues); }
private Set<String> validateView(List<String> problems, Set<String> validMainPaths) { if (view.isEmpty()) { problems.add(NO_VIEW_ERROR); } else { for (String viewPath : view) { try { Path path = new Path(model, viewPath, subclasses); if (!path.endIsAttribute()) { problems.add("Path " + viewPath + " in view list must be an attribute"); continue; } if (rootClass == null) { rootClass = path.getStartClassDescriptor().getUnqualifiedName(); } else { String newRootClass = path.getStartClassDescriptor().getUnqualifiedName(); if (!rootClass.equals(newRootClass)) { problems.add("Multiple root classes in query: " + rootClass + " and " + newRootClass); continue; } } addValidPaths(validMainPaths, path.getPrefix()); } catch (PathException e) { problems.add("Path " + viewPath + " in view list is not in the model"); } } } return validMainPaths; }
private Set<String> validateView(List<String> problems, Set<String> validMainPaths) { if (view.isEmpty()) { problems.add(NO_VIEW_ERROR); } else { for (String viewPath : view) { try { Path path = new Path(model, viewPath, subclasses); if (!path.endIsAttribute()) { problems.add("Path " + viewPath + " in view list must be an attribute"); continue; } if (rootClass == null) { rootClass = path.getStartClassDescriptor().getUnqualifiedName(); } else { String newRootClass = path.getStartClassDescriptor().getUnqualifiedName(); if (!rootClass.equals(newRootClass)) { problems.add("Multiple root classes in query: " + rootClass + " and " + newRootClass); continue; } } addValidPaths(validMainPaths, path.getPrefix()); } catch (PathException e) { problems.add("Path " + viewPath + " in view list is not in the model"); } } } return validMainPaths; }
constrainedType = path.getPrefix().getEndType().getSimpleName(); } else {
constrainedType = path.getPrefix().getEndType().getSimpleName(); } else {
public void testGetPrefix() throws Exception { Map<String, String> constraintMap = new HashMap<String, String>(); constraintMap.put("Department.manager", "CEO"); constraintMap.put("Department.manager.company.departments.employees", "Manager"); String stringPath = "Department.manager.company.departments.employees.age"; Path path = new Path(model, stringPath, constraintMap); Path prefix = path.getPrefix(); assertEquals("Department.manager[CEO].company.departments.employees[Manager]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department.manager[CEO].company.departments", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department.manager[CEO].company", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department.manager[CEO]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department", prefix.toString()); try { prefix = prefix.getPrefix(); fail("expected RuntimeException"); } catch (RuntimeException e) { // expected } }
public void testGetPrefixOuterJoin() throws Exception { Map<String, String> constraintMap = new HashMap<String, String>(); constraintMap.put("Department.manager", "CEO"); constraintMap.put("Department.manager.company.departments.employees", "Manager"); String stringPath = "Department:manager.company:departments.employees.age"; Path path = new Path(model, stringPath, constraintMap); Path prefix = path.getPrefix(); assertEquals("Department:manager[CEO].company:departments.employees[Manager]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department:manager[CEO].company:departments", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department:manager[CEO].company", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department:manager[CEO]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department", prefix.toString()); try { prefix = prefix.getPrefix(); fail("expected RuntimeException"); } catch (RuntimeException e) { // expected } }
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());
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());