Пример #1
0
  /**
   * Returns whether the given {@link Query} contains named parameters.
   *
   * @param query
   * @return
   */
  public static boolean hasNamedParameter(Query query) {

    for (Parameter<?> parameter : query.getParameters()) {
      if (parameter.getName() != null) {
        return true;
      }
    }

    return false;
  }
Пример #2
0
  /**
   * Returns whether the given {@link Query} contains named parameters.
   *
   * @param query
   * @return
   */
  public static boolean hasNamedParameter(Query query) {

    for (Parameter<?> parameter : query.getParameters()) {

      String name = parameter.getName();

      // Hibernate 3 specific hack as it returns the index as String for the name.
      if (name != null && NO_DIGITS.matcher(name).find()) {
        return true;
      }
    }

    return false;
  }
  private void setQueryParameters(Query query, SearchParameters sp) {
    // add default parameter if specified in the named query
    for (Parameter<?> p : query.getParameters()) {
      if (NAMED_PARAMETER_CURRENT_USER_ID.equals(p.getName())) {
        query.setParameter(NAMED_PARAMETER_CURRENT_USER_ID, UserContext.getId());
      } else if (NAMED_PARAMETER_NOW.equals(p.getName())) {
        query.setParameter(NAMED_PARAMETER_NOW, Calendar.getInstance().getTime());
      }
    }

    // add parameters for the named query
    for (String paramName : sp.getNamedQueryParameters().keySet()) {
      query.setParameter(paramName, sp.getNamedQueryParameter(paramName));
    }
  }