/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package salidasautomaticas.mysqldao;


import java.sql.Connection;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import salidasautomaticas.dao.DAOFactory;
import salidasautomaticas.dao.SalidasDAO;

/**
 *
 * @author sistem08user
 */
public class MysqlDAOFactory extends DAOFactory {

    
    private static DataSource dataSourceMySQL;
    
    static {
        try {
            createPoolConnectionsMySQL();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void createPoolConnectionsMySQL() {
        if (dataSourceMySQL == null) {
            BasicDataSource basicDataSource = new BasicDataSource();
            basicDataSource.setDriverClassName("com.mysql.jdbc.Driver");
            basicDataSource.setUsername("billy");
            basicDataSource.setPassword("billy");
            basicDataSource.setUrl("jdbc:mysql://172.16.2.39:3306/nuevo");
            basicDataSource.setMaxActive(30);
            basicDataSource.setMaxIdle(30);
            basicDataSource.setRemoveAbandoned(true);
            basicDataSource.setRemoveAbandonedTimeout(5000);
            basicDataSource.setMaxWait(6000);

            dataSourceMySQL = basicDataSource;
        }
    }

    public static Connection getConneccion(String bd) {
        Connection connection = null;
        if (bd.equals("nuevo")) {
            try {
                connection = dataSourceMySQL.getConnection();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return connection;
    }


    @Override
    public SalidasDAO getSalidasDAO() {
        return new SalidasMysqlDAO();
    }

}
