public Object getParameterValue(String name) {
return getParameterValue( resolveExplicitCriteriaParameterName( name ) );
}
private Parameter resolveExplicitCriteriaParameterName(String name) {
Parameter parameter = explicitParameterNameMapping.get( name );
if ( parameter == null ) {
throw new IllegalArgumentException( "Named parameter [" + name + "] not encountered" );
}
return parameter;
}
public Parameter<?> getParameter(String name) {
return mapToNamedParameter( resolveExplicitCriteriaParameterName( name ) );
}
@SuppressWarnings({ "unchecked" })
public <T> Parameter<T> getParameter(String name, Class<T> type) {
Parameter parameter = resolveExplicitCriteriaParameterName( name );
if ( type.isAssignableFrom( parameter.getParameterType() ) ) {
return parameter;
}
throw new IllegalArgumentException(
"Named parameter [" + name + "] type is not assignanle to request type ["
+ type.getName() + "]"
);
}
@SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(String name, Object value) {
setParameter(
resolveExplicitCriteriaParameterName( name, value ),
value
);
return this;
}
private Parameter resolveExplicitCriteriaParameterName(String name, Object value) {
Parameter parameter = resolveExplicitCriteriaParameterName( name );
// todo : is null valid?
if ( value != null ) {
if ( ! parameter.getParameterType().isInstance( value ) ) {
throw new IllegalArgumentException(
"Named parameter [" + name + "] type mismatch; expecting ["
+ parameter.getParameterType().getName() + "], found ["
+ value.getClass().getName() + "]"
);
}
}
return parameter;
}
@SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(String name, Calendar calendar, TemporalType temporalType) {
Parameter parameter = resolveExplicitCriteriaParameterName( name );
if ( ! Calendar.class.isAssignableFrom( parameter.getParameterType() ) ) {
throw new IllegalArgumentException(
"Named parameter [" + name + "] type mismatch; expecting ["
+ Calendar.class.getName() + "], found ["
+ parameter.getParameterType().getName() + "]"
);
}
setParameter( parameter, calendar, temporalType );
return this;
}
@SuppressWarnings({ "unchecked" })
public TypedQuery<X> setParameter(String name, Date date, TemporalType temporalType) {
Parameter parameter = resolveExplicitCriteriaParameterName( name );
if ( ! Date.class.isAssignableFrom( parameter.getParameterType() ) ) {
throw new IllegalArgumentException(
"Named parameter [" + name + "] type mismatch; expecting ["
+ Date.class.getName() + "], found ["
+ parameter.getParameterType().getName() + "]"
);
}
setParameter( parameter, date, temporalType );
return this;
}