use of org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer in project jdbi by jdbi.
the class BindFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
Bind b = (Bind) annotation;
String nameFromAnnotation = b == null ? Bind.NO_VALUE : b.value();
Optional<String> name = ParameterUtil.findParameterName(nameFromAnnotation, param);
return (stmt, arg) -> {
stmt.bindByType(index, arg, type);
name.ifPresent(n -> stmt.bindByType(n, arg, type));
};
}
use of org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer in project jdbi by jdbi.
the class BindListFactory method createForParameter.
@Override
public SqlStatementParameterCustomizer createForParameter(Annotation annotation, Class<?> sqlObjectType, Method method, Parameter param, int index, Type type) {
final BindList bindList = (BindList) annotation;
final String name = ParameterUtil.findParameterName(bindList.value(), param).orElseThrow(() -> new UnsupportedOperationException("A @BindList parameter was not given a name, " + "and parameter name data is not present in the class file, for: " + param.getDeclaringExecutable() + "::" + param));
return (stmt, arg) -> {
if (arg == null || IterableLike.isEmpty(arg)) {
switch(bindList.onEmpty()) {
case VOID:
stmt.define(name, "");
return;
case NULL:
stmt.define(name, "null");
return;
case THROW:
throw new IllegalArgumentException(arg == null ? "argument is null; null was explicitly forbidden on this instance of BindList" : "argument is empty; emptiness was explicitly forbidden on this instance of BindList");
default:
throw new IllegalStateException(valueNotHandledMessage);
}
}
stmt.bindList(name, IterableLike.toList(arg));
};
}
Aggregations