com.alexkasko.springjdbc.parallel.NamedParameterJdbcTemplateFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of parallel-queries Show documentation
Show all versions of parallel-queries Show documentation
Processes given SQL query in parallel in multiple data sources (assuming that all data source
contain the same data). Combined results from multiple queries are exposed to application as
java.util.Iterator. Worker thread use spring's JdbcTemplate with named parameters support.
package com.alexkasko.springjdbc.parallel;
import com.google.common.base.Function;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import javax.sql.DataSource;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helper function, wraps {@link javax.sql.DataSource} into {@code NamedParameterJdbcTemplate}
*
* @author alexkasko
* Date: 11/9/12
*/
class NamedParameterJdbcTemplateFunction implements Function {
static final Function NPJT_FUNCTION = new NamedParameterJdbcTemplateFunction();
/**
* {@inheritDoc}
*/
@Override
public NamedParameterJdbcTemplate apply(DataSource input) {
checkNotNull(input, "Provided data source is null");
return new NamedParameterJdbcTemplate(input);
}
}