use of com.querydsl.core.types.ParamNotSetException in project querydsl by querydsl.
the class JPAUtil method setConstants.
public static void setConstants(Query query, Map<Object, String> constants, Map<ParamExpression<?>, Object> params) {
boolean hasParameters = !query.getParameters().isEmpty();
for (Map.Entry<Object, String> entry : constants.entrySet()) {
String key = entry.getValue();
Object val = entry.getKey();
if (Param.class.isInstance(val)) {
val = params.get(val);
if (val == null) {
throw new ParamNotSetException((Param<?>) entry.getKey());
}
}
if (hasParameters) {
Parameter parameter = query.getParameter(Integer.parseInt(key));
Class parameterType = parameter != null ? parameter.getParameterType() : null;
if (parameterType != null && !parameterType.isInstance(val)) {
if (val instanceof Number && Number.class.isAssignableFrom(parameterType)) {
val = MathUtils.cast((Number) val, parameterType);
}
}
}
query.setParameter(Integer.valueOf(key), val);
}
}
Aggregations