private static void bindNamed(ParsedParameters params, Binding binding, PreparedStatement statement, StatementContext context) {
List<String> paramNames = params.getParameterNames();
boolean argumentsProvidedButNoneDeclared = paramNames.isEmpty() && !binding.isEmpty();
if (argumentsProvidedButNoneDeclared && !context.getConfig(SqlStatements.class).isUnusedBindingAllowed()) {
throw new UnableToCreateStatementException(String.format(
"Superfluous named parameters provided while the query "
+ "declares none: '%s'. This check may be disabled by calling "
+ "getConfig(SqlStatements.class).setUnusedBindingAllowed(true) "
+ "or using @AllowUnusedBindings in SQL object.", binding), context);
}
for (int i = 0; i < paramNames.size(); i++) {
final String name = paramNames.get(i);
try {
binding.findForName(name, context)
.orElseThrow(() -> new UnableToCreateStatementException(String.format("Missing named parameter '%s'.", name), context))
.apply(i + 1, statement, context);
} catch (SQLException e) {
throw new UnableToCreateStatementException(String.format("Exception while binding named parameter '%s'", name), e, context);
}
}
}
}