/** * Bind a parameter for each value in the given vararg array, and defines an attribute as the comma-separated list * of parameter references (using colon prefix). * <p> * Examples: * <pre> * handle.createUpdate("insert into things (<columnNames>) values (<values>)") * .defineList("columnNames", "id", "name", "created_on") * .bindList("values", 1, "Alice", LocalDate.now()) * .execute(); * * List<Thing> things = handle.createQuery("select * from things where id in (<ids>)") * .bindList("ids", 1, 2, 3) * .mapTo(Contact.class) * .list(); * </pre> * * @param key attribute name * @param values vararg values that will be comma-spliced into the defined attribute value. * @return this * @throws IllegalArgumentException if the vararg array is empty. */ public final This bindList(String key, Object... values) { if (values.length == 0) { throw new IllegalArgumentException( getClass().getSimpleName() + ".bindList was called with no vararg values."); } return bindList(key, Arrays.asList(values)); }
@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)) { bindList.onEmpty().define(stmt, name); } else { stmt.bindList(name, IterableLike.toList(arg)); } }; } }
/** * Bind a parameter for each value in the given vararg array, and defines an attribute as the comma-separated list * of parameter references (using colon prefix). * <p> * Examples: * <pre> * handle.createUpdate("insert into things (<columnNames>) values (<values>)") * .defineList("columnNames", "id", "name", "created_on") * .bindList("values", 1, "Alice", LocalDate.now()) * .execute(); * * List<Thing> things = handle.createQuery("select * from things where id in (<ids>)") * .bindList("ids", 1, 2, 3) * .mapTo(Contact.class) * .list(); * </pre> * * @param key attribute name * @param values vararg values that will be comma-spliced into the defined attribute value. * @return this * @throws IllegalArgumentException if the vararg array is empty. */ public final This bindList(String key, Object... values) { if (values.length == 0) { throw new IllegalArgumentException( getClass().getSimpleName() + ".bindList was called with no vararg values."); } return bindList(key, Arrays.asList(values)); }