/*
 * 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 demojsoncrud.sqlserverdao;

import demojsoncrud.dao.DAOFactory;
import demojsoncrud.dao.PersonaDAO;
import demojsoncrud.dao.UbigeoDAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Alonso
 */
public class SqlserverDAOFactory extends DAOFactory {

    public static Connection obtenerConexion(String base) {
        Connection connection = null;
        String user = "sa";
        String pwd = "Saco1357$";
        String urlBase = "jdbc:sqlserver://172.16.2.118:1433;databaseName=";
        String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String url = "";
        if (base.equalsIgnoreCase("demojsoncrud")) {
            url = urlBase + "demojsoncrud";
        } else if (base.equalsIgnoreCase("ubigeo")) {
            url = urlBase + "ubigeo";
        } else {
            url = "";
        }

        try {
            Class.forName(driver);
            connection = DriverManager.getConnection(url, user, pwd);
        } catch (ClassNotFoundException | SQLException e) {
            System.out.println("Error al conectarse => " + e.getMessage());
        }

        return connection;
    }

//    public static void main(String[] args) {
//        SqlserverDAOFactory sqlserverDAOFactory = new SqlserverDAOFactory();
//        System.out.println(sqlserverDAOFactory.obtenerConexion("demojsoncrud"));
//    }
    @Override
    public PersonaDAO getPersonaDAO() {
        return new PersonaSqlserverDAO();
    }

    @Override
    public UbigeoDAO getUbigeoDAO() {
        return new UbigeoSqlserverDAO();
    }
}
