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

com.alexkasko.springjdbc.parallel.SingletoneRowMapperFactory Maven / Gradle / Ivy

Go to download

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.

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy