com.alexkasko.springjdbc.parallel.SingletoneRowMapperFactory 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 org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Transparent holder of provided row mapper.
*
* @author alexkasko
* Date: 8/18/12
*/
class SingletoneRowMapperFactory implements RowMapperFactory {
private final RowMapper singletone;
/**
* @param singletone singletone row mapper
*/
SingletoneRowMapperFactory(RowMapper singletone) {
checkNotNull(singletone, "Provided row mapper is null");
this.singletone = singletone;
}
/**
* Generic-friendly constructor method
*
* @param singletone singletone row mapper
* @param mapper result type
* @return factory instance
*/
static SingletoneRowMapperFactory of(RowMapper singletone) {
return new SingletoneRowMapperFactory(singletone);
}
/**
* {@inheritDoc}
*/
@Override
public RowMapper produce(SqlParameterSource params) {
return singletone;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("SingletoneRowMapperFactory");
sb.append("{singletone=").append(singletone);
sb.append('}');
return sb.toString();
}
}