package mobvista.prd.datasource.db;

import java.sql.Connection;
import java.sql.DriverManager;


public class DBDataSource {
	private static String URL;
	private static String DRIVER;
	private static String USERNAME;
	private static String PASSWORD;
	
	private volatile static DBDataSource instance;
	private static Object lock = new Object();
	
	private DBDataSource () {
//		Configuration conf = ConfigUtil.create();
//		URL = conf.get(Constants.DB_URL, "jdbc:mysql://mysql.data.sina.com.cn:4045/tianyi?characterEncoding=utf-8");
//		DRIVER = conf.get(Constants.DB_DRIVER, "com.mysql.jdbc.Driver");
//		USERNAME = conf.get(Constants.DB_USER, "tianyi");
//		PASSWORD = conf.get(Constants.DB_PWD, "rIqoFfyhABV6RZfTXhYzUDOCswvn");
		URL = "jdbc:mysql://datameta.c5yzcdreb1xr.us-east-1.rds.amazonaws.com:3306/dataplatform?characterEncoding=UTF8";
		DRIVER = "com.mysql.jdbc.Driver";
		USERNAME = "dataplatform";
		PASSWORD = "Mobdataplatform_123";
	}
	
	public static DBDataSource getInstance() {
		if (instance == null) {
			synchronized (lock) {
				instance = new DBDataSource();
			}
		}
		return instance;
	}
	
	public Connection getConnection() throws Exception {
		Class.forName(DRIVER);
		return DriverManager.getConnection(URL, USERNAME, PASSWORD);
	}
}