package org.greenhouse.model.alert;

import org.greenhouse.util.configuration.ConfigurationParametersManager;

public class SqlAlertDaoFactory {

	private final static String CLASS_NAME_PARAMETER = "SqlAlertDaoFactory.className";
    private static SqlAlertDao dao = null;

    private SqlAlertDaoFactory() {
    }

    @SuppressWarnings("rawtypes")
    private static SqlAlertDao getInstance() {
        try {
            String daoClassName = ConfigurationParametersManager
                    .getParameter(CLASS_NAME_PARAMETER);
            Class daoClass = Class.forName(daoClassName);
            return (SqlAlertDao) daoClass.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    public synchronized static SqlAlertDao getDao() {

        if (dao == null) {
            dao = getInstance();
        }
        return dao;

    }
}
