com.github.randyp.jdbj.ListBindingsBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdbj Show documentation
Show all versions of jdbj Show documentation
a java8 fluent interface for jdbc
package com.github.randyp.jdbj;
import com.github.randyp.jdbj.lambda.Binding;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
public interface ListBindingsBuilder extends DefaultValueBindingsBuilder {
E bindList(String name, List bindings);
default E bindLongs(String name, long... xs){
if (xs == null) {
throw new IllegalArgumentException("xs cannot be null - consider using bindArray");
}
final List bindings = new ArrayList<>();
for (final long x : xs) {
bindings.add(pc -> pc.setLong(x));
}
return bindList(name, bindings);
}
default E bindStrings(String name, List xs){
if (xs == null) {
throw new IllegalArgumentException("xs cannot be null - consider using bindArray");
}
final Function createBinding = x -> (Binding) preparedColumn -> preparedColumn.setString(x);
final List bindings = xs.stream().map(createBinding).collect(Collectors.toList());
return bindList(name, bindings);
}
default E bindStrings(String name, String... xs){
if (xs == null) {
throw new IllegalArgumentException("xs cannot be null - consider using bindArray");
}
return bindStrings(name, Arrays.asList(xs));
}
}