org.simpleflatmapper.jdbc.spring.SqlParameterSourceFactory Maven / Gradle / Ivy
package org.simpleflatmapper.jdbc.spring;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import java.util.ArrayList;
import java.util.Iterator;
public class SqlParameterSourceFactory {
private final PlaceHolderValueGetterSource placeHolderValueGetterSource;
public SqlParameterSourceFactory(PlaceHolderValueGetterSource placeHolderValueGetterSource) {
this.placeHolderValueGetterSource = placeHolderValueGetterSource;
}
public SqlParameterSource newSqlParameterSource(T value) {
return new SqlParameterSourceImpl(placeHolderValueGetterSource, value);
}
public SqlParameterSource[] newSqlParameterSources(Iterable values) {
return newSqlParameterSources(values.iterator());
}
public SqlParameterSource[] newSqlParameterSources(Iterator values) {
ArrayList sources = new ArrayList();
while(values.hasNext()) {
sources.add(newSqlParameterSource(values.next()));
}
return sources.toArray(new SqlParameterSource[0]);
}
public SqlParameterSource[] newSqlParameterSources(T[] values) {
SqlParameterSource[] sources = new SqlParameterSource[values.length];
for(int i = 0; i < values.length; i++) {
T value = values[i];
sources[i] = newSqlParameterSource(value);
}
return sources;
}
}