package com.mini.capi.config;

import com.mini.capi.biz.domain.DbConfig;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

public class DataSourceConfig {

    public static DataSource createDataSource(DbConfig dbConfig) {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(dbConfig.getDriverClass());
        dataSource.setUrl(dbConfig.getUrlTemplate());
        dataSource.setUsername(dbConfig.getLinkUsername());
        dataSource.setPassword(dbConfig.getLinkPassword());
        return dataSource;
    }

    public static JdbcTemplate createJdbcTemplate(DbConfig dbConfig) {
        return new JdbcTemplate(createDataSource(dbConfig));
    }
}
