package app.config;

import ca.tecreations.db.mysql.MySQL;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Configuration;

import org.springframework.jdbc.datasource.DriverManagerDataSource;
/**
 *
 * @author tim
 */
@Configuration
@Component
public class SiteSecDataSource {

    public SiteSecDataSource() {}
    
    public MySQL mysql;
    
    @Value("${spring.datasource.url}")
    String url;
    
    @Value("${spring.datasource.username}")
    String username; 
    
    @Value("${spring.datasource.password}")
    String password;
    
    @Value("${spring.datasource.driver-class-name}")
    String driverClassName;
    
    @Bean
    public DriverManagerDataSource dataSource() {
        //System.setProperty("spring.jpa.properties.hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username); 
        dataSource.setPassword(password);
        //System.out.println("dCN: " + driverClassName + " url: " + url + " user: " + username + " pass: " + password);
        //System.exit(0);
        mysql = new MySQL(dataSource);
        return dataSource;
    }
    
    public MySQL getMysql() { return new MySQL(dataSource()); }
    
    public MySQL getMySQL() { return new MySQL(dataSource()); }
    
}