Example usage for javax.persistence Query getParameterValue

List of usage examples for javax.persistence Query getParameterValue

Introduction

In this page you can find the example usage for javax.persistence Query getParameterValue.

Prototype

Object getParameterValue(int position);

Source Link

Document

Return the input value bound to the positional parameter.

Usage

From source file:net.nan21.dnet.core.presenter.action.query.QueryBuilderWithJpql.java

private void bindFilterParams(Query q) throws Exception {

    if (this.defaultFilterItems != null) {
        for (String key : this.defaultFilterItems.keySet()) {
            Object value = this.defaultFilterItems.get(key);
            try {
                if (value instanceof java.lang.String) {
                    q.setParameter(key, ((String) value).replace('*', '%'));
                } else {
                    q.setParameter(key, value);
                }// ww  w. j  a  va2s  .  c  om
            } catch (IllegalArgumentException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.getMessage());
                }
            }
        }
    }
    if (this.customFilterItems != null) {
        for (String key : this.customFilterItems.keySet()) {
            Object value = this.customFilterItems.get(key);
            if (value instanceof java.lang.String) {
                q.setParameter(key, ((String) value).replace('*', '%'));
            } else {
                q.setParameter(key, value);
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Bound filter params:");
        for (Parameter<?> p : q.getParameters()) {
            try {
                logger.debug(" -> " + p.getName() + " = " + q.getParameterValue(p));
            } catch (Exception e) {
                // maybe a parameter has not been bound
            }
        }
    }
}