All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.jdbc.spring.SqlParameterSourceFactory Maven / Gradle / Ivy

There is a newer version: 9.0.2
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy