package com.eactive.eai.common.scheduler;

import java.sql.ResultSet;
import java.util.HashMap;

import com.eactive.eai.common.dao.BaseDAO;
import com.eactive.eai.common.dao.DAOException;
import com.eactive.eai.common.util.Logger;


public class SchedulerDAO extends BaseDAO implements SchedulerQuery {
    static Logger logger = Logger.getLogger(Logger.LOGGER_SCHEDULER);
	
	public HashMap<String, ScheduleJobInfo> getAllSchedule() throws DAOException {
		
		HashMap<String, ScheduleJobInfo> infos = new HashMap<String, ScheduleJobInfo>();
		ResultSet rs = null;
		try {
			
			this.connect(SELECT_SCHEDULE);
			
			rs = executeQuery();
			logger.debug("[ @@ Load ScheduleJobInfo Configuration - starting >>>>>>>>>>>>>>>>> ]");
            
			ScheduleJobInfo info = null;
			while(rs.next()) {
                info = new ScheduleJobInfo(
                		rs.getString(1),
                		rs.getString(2),
                		rs.getString(3),
                		rs.getString(4),
                		rs.getString(5),
                		rs.getString(6)
                		);
                infos.put(rs.getString(1), info);
                if(info!=null) logger.debug("@ "+info.toString());
            }
            
            logger.debug("[>>Load ScheduleJobInfo Configuration - ended ]");
            return infos;
		} catch(Exception e) {
			logger.error("SchedulerDAO Fail - " + e.getMessage(),e);
			throw new DAOException();
	    } finally {
	        this.disconnect();   
	    }
	}
}