Search in sources :

Example 11 with QueryParameterBinding

use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.

the class ProcedureCallImpl method setParameter.

@Override
@SuppressWarnings("unchecked")
public ProcedureCallImplementor<R> setParameter(String name, Object value, Type type) {
    final QueryParameterBinding binding = paramBindings.getBinding(getParameterMetadata().getQueryParameter(name));
    binding.setBindValue(value, type);
    return this;
}
Also used : QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding)

Example 12 with QueryParameterBinding

use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.

the class QueryParameterBindingsImpl method isBound.

public boolean isBound(QueryParameter parameter) {
    final QueryParameterBinding binding = locateBinding(parameter);
    if (binding != null) {
        return binding.getBindValue() != null;
    }
    final QueryParameterListBinding listBinding = locateQueryParameterListBinding(parameter);
    if (listBinding != null) {
        return listBinding.getBindValues() != null;
    }
    return false;
}
Also used : QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding) QueryParameterListBinding(org.hibernate.query.spi.QueryParameterListBinding)

Example 13 with QueryParameterBinding

use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.

the class QueryParameterBindingsImpl method transformQueryParameterBindingToQueryParameterListBinding.

/**
	 * @deprecated (since 5.2) expected changes to "collection-valued parameter binding" in 6.0
	 */
@Deprecated
private <T> QueryParameterListBinding<T> transformQueryParameterBindingToQueryParameterListBinding(QueryParameter<T> queryParameter) {
    log.debugf("Converting QueryParameterBinding to QueryParameterListBinding for given QueryParameter : %s", queryParameter);
    final QueryParameterBinding binding = getAndRemoveBinding(queryParameter);
    if (binding == null) {
        throw new IllegalArgumentException("Could not locate QueryParameterBinding for given QueryParameter : " + queryParameter + "; parameter list must be defined using named parameter");
    }
    final QueryParameterListBinding<T> convertedBinding = new QueryParameterListBindingImpl<>(binding.getBindType(), shouldValidateBindingValue());
    parameterListBindingMap.put(queryParameter, convertedBinding);
    return convertedBinding;
}
Also used : QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding)

Example 14 with QueryParameterBinding

use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.

the class AbstractProducedQuery method getParameterValue.

@Override
public Object getParameterValue(int position) {
    getProducer().checkOpen(false);
    final QueryParameterBinding binding;
    try {
        binding = getQueryParameterBindings().getBinding(position);
    } catch (QueryParameterException e) {
        throw new IllegalArgumentException("Could not resolve parameter by position - " + position, e);
    }
    LOGGER.debugf("Checking whether positional  parameter [%s] is bound : %s", (Integer) position, (Boolean) binding.isBound());
    if (!binding.isBound()) {
        throw new IllegalStateException("Parameter value not yet bound : " + position);
    }
    return binding.getBindValue();
}
Also used : QueryParameterException(org.hibernate.QueryParameterException) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding)

Example 15 with QueryParameterBinding

use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.

the class QueryParameterBindingsImpl method collectNamedParameterBindings.

/**
 * @deprecated (since 5.2) expect a different approach to org.hibernate.engine.spi.QueryParameters in 6.0
 */
@Deprecated
public Map<String, TypedValue> collectNamedParameterBindings() {
    final Map<String, TypedValue> collectedBindings = new HashMap<>();
    for (Map.Entry<QueryParameter, QueryParameterBinding> entry : parameterBindingMap.entrySet()) {
        final String key;
        if (entry.getKey().getPosition() != null) {
            key = Integer.toString(entry.getKey().getPosition());
        } else {
            key = entry.getKey().getName();
        }
        Type bindType = entry.getValue().getBindType();
        if (bindType == null) {
            log.debugf("Binding for parameter [%s] did not define type", key);
            bindType = SerializableType.INSTANCE;
        }
        collectedBindings.put(key, new TypedValue(bindType, entry.getValue().getBindValue()));
    }
    return collectedBindings;
}
Also used : QueryParameter(org.hibernate.query.QueryParameter) SerializableType(org.hibernate.type.SerializableType) Type(org.hibernate.type.Type) QueryParameterBinding(org.hibernate.query.spi.QueryParameterBinding) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) TypedValue(org.hibernate.engine.spi.TypedValue)

Aggregations

QueryParameterBinding (org.hibernate.query.spi.QueryParameterBinding)22 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 QueryParameterException (org.hibernate.QueryParameterException)3 QueryParameter (org.hibernate.query.QueryParameter)3 SerializableType (org.hibernate.type.SerializableType)3 Type (org.hibernate.type.Type)3 QueryParameterListBinding (org.hibernate.query.spi.QueryParameterListBinding)2 Collection (java.util.Collection)1 QueryException (org.hibernate.QueryException)1 Dialect (org.hibernate.dialect.Dialect)1 NamedParameterDescriptor (org.hibernate.engine.query.spi.NamedParameterDescriptor)1 OrdinalParameterDescriptor (org.hibernate.engine.query.spi.OrdinalParameterDescriptor)1 TypedValue (org.hibernate.engine.spi.TypedValue)1