/** * Returns true if the constraint is associated with the given FromElement. * * @param constraint the constraint in question * @param fromElement the FromElement to check * @return true if associated */ public static boolean isRelatedTo(Constraint constraint, FromElement fromElement) { if (isAssociatedWith(constraint, fromElement)) { return true; } // also want to find out if this is referred to in a Contains or Subquery // constraint that is associated with another fromElement. if (constraint instanceof ContainsConstraint) { if (fromElement == ((ContainsConstraint) constraint).getQueryClass()) { return true; } } else if (constraint instanceof SubqueryConstraint) { if (fromElement == ((SubqueryConstraint) constraint).getQuery()) { return true; } } else if (constraint instanceof SimpleConstraint) { SimpleConstraint sc = (SimpleConstraint) constraint; Set<QueryField> qFields = getQueryFields(sc.getArg1()); qFields.addAll(getQueryFields(sc.getArg2())); for (QueryField qf : qFields) { if (fromElement == qf.getFromElement()) { return true; } } } return false; }
/** * Returns true if the given constraint is related to no FromElement. This should only return true * if c is a SimpleConstraint that only references constants. * * @param c the constraint to examine * @return true if constraint is not associated with a FromElement */ public static boolean isRelatedToNothing(Constraint c) { if (c instanceof SimpleConstraint) { SimpleConstraint sc = (SimpleConstraint) c; Set<QueryField> fields = getQueryFields(sc.getArg1()); fields.addAll(getQueryFields(sc.getArg2())); if (fields.size() == 0) { return true; } } return false; }