/*
   * Appends a new predicate to an old predicate using an AND logical operator between them
   * and uses the specified relationshipPred to constrain the newPred.
   *
   * Handles case where old or new predicate is non-existent (white spaces only).
   *
   */
  protected String appendPredicate(String oldPred, String newPred, String relationshipPred) {
    if (!(Utility.containsWhiteSpacesOnly(newPred))) {
      if (!(Utility.containsWhiteSpacesOnly(relationshipPred))) {
        newPred = "(" + relationshipPred + "AND " + newPred + ") ";
      }

      if (!(Utility.containsWhiteSpacesOnly(oldPred))) {
        oldPred += "AND ";
      }
      oldPred += newPred;
    }

    return oldPred;
  }
  /*
   * Appends a new predicate to an old predicate using an AND logical operator between them
   * and used the default joinPred to constrain the newPred.
   * Handles case where old or new predicate is non-existent (white spaces only).
   *
   */
  protected String appendPredicate(String oldPred, String newPred) {
    if (!(Utility.containsWhiteSpacesOnly(newPred))) {
      String joinPred = getJoinPredicate();

      oldPred = appendPredicate(oldPred, newPred, joinPred);
    }

    return oldPred;
  }
  private String buildWhereClause() throws RegistryException {
    String whereClause = "";
    String filterPredicate = processFilters();
    String branchPredicate = processBranches();
    String subQueryPredicate = processSubQueries();

    if (!(Utility.containsWhiteSpacesOnly(filterPredicate))) {
      whereClause += filterPredicate;
    }

    whereClause = appendPredicate(whereClause, branchPredicate);
    whereClause = appendPredicate(whereClause, subQueryPredicate);

    // Only add "WHERE" if if top level FilterQueryProcessor (has no parent) AND
    // there are non-white-space characters in whereClause
    if (parentQueryProcessor == null) {
      if (!(Utility.containsWhiteSpacesOnly(whereClause))) {
        whereClause = " WHERE " + whereClause;
      }
    }
    return whereClause;
  }