Example usage for org.hibernate Query getNamedParameters

List of usage examples for org.hibernate Query getNamedParameters

Introduction

In this page you can find the example usage for org.hibernate Query getNamedParameters.

Prototype

@Deprecated
String[] getNamedParameters();

Source Link

Document

Return the names of all named parameters of the query.

Usage

From source file:org.riotfamily.core.dao.hibernate.HqlParentChildDao.java

License:Apache License

@Override
protected void setQueryParameters(Query query, Object parent, ListParams params) {

    super.setQueryParameters(query, parent, params);
    if (parent != null) {
        for (String param : query.getNamedParameters()) {
            Matcher m = Pattern.compile("parent(?:_(\\w+))?").matcher(param);
            if (m.matches()) {
                Object value = parent;
                String nested = m.group(1);
                if (nested != null) {
                    value = PropertyUtils.getProperty(parent, nested);
                }//from   www  .  ja  v  a2s . c  o m
                query.setParameter(param, value);
            }
        }
    }
}

From source file:org.webcurator.domain.Pagination.java

License:Apache License

/**
 * Bind the parameters passed in to the query.
 * @param q the query to bind to/*from  ww  w .  j av a  2s  .c  om*/
 * @param map the query parameters
 */
private void bindQueryParams(Query q, Map map) {
    String[] allParams = q.getNamedParameters();
    log.debug("Binding parameters in Pagination");
    for (int i = 0; i < allParams.length; i++) {
        // for each named parameter, bind it to the query
        if (map.containsKey(allParams[i])) {
            log.debug("Found a parameter in Map to bind to query called " + allParams[i] + " value = "
                    + map.get(allParams[i]));
            q.setParameter(allParams[i], map.get(allParams[i]));
        } else {
            throw new HibernateException("Map doesn't contain the correct parameters to bind to query");
        }
    }
}

From source file:org.xchain.framework.hibernate.HqlEntityPermission.java

License:Apache License

private void populateParameters(Query query, String principal, Serializable id)
        throws IllegalArgumentException {
    String[] namedParameters = query.getNamedParameters();
    for (String namedParameter : namedParameters) {
        if ("id".equals(namedParameter)) {
            query.setParameter(namedParameter, id);
        } else if ("principal".equals(namedParameter)) {
            query.setParameter(namedParameter, principal);
        } else {// w w  w .  j a va2s  .com
            throw new IllegalArgumentException(String.format(
                    "Unknown parameter '%s' in permission hql '%s'.  The only defined parameters are the current entity id (:id) and the principal (:principal).",
                    namedParameter, query.getQueryString()));
        }
    }
}