package com.eactive.eai.batch.rule.ruleinfo;

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.exception.ExceptionUtil;

public class RuleInfoDAO extends BaseDAO implements RuleInfoQuery
{
    public HashMap<String, RuleInfoVO> getAllRuleInfo() throws DAOException
    {
    	HashMap<String, RuleInfoVO> all = new HashMap<String, RuleInfoVO>();
        ResultSet rs = null;
        RuleInfoVO vo = null;
        try
        {
            this.connect(GET_ALL_RULEINFO);
            rs = this.executeQuery();

            while(rs.next())
            {
                vo = new RuleInfoVO();
                vo.setRuleCode(rs.getString(1).trim());
                vo.setDesc(rs.getString(2).trim());

                all.put(vo.getRuleCode(), vo);
            }
        } catch(Exception e) {
            throw new DAOException(ExceptionUtil.getErrorCode(e,"BECEAIMFR028"));
        } finally {
            this.disconnect();
        }
        return all;
    }
    /**
     * Rule 정보를 읽어 낸다.
     */
    public RuleInfoVO getRuleInfo(String strRuleCode) throws DAOException
    {
        RuleInfoVO vo = new RuleInfoVO();
        ResultSet   rs = null;
        try {
            this.connect(GET_RULEINFO_BYCODE);
            this.preparedStatement.setString(1, strRuleCode);
            rs = executeQuery();
            vo = new RuleInfoVO();
            while (rs.next())
            {
                vo.setRuleCode(rs.getString(1));
                vo.setDesc(rs.getString(2));
            }
        } catch(Exception e) {
            throw new DAOException(ExceptionUtil.getErrorCode(e,"BECEAIMFR029", new String[] {strRuleCode}));
        } finally {
            this.disconnect();
        }
        return vo;
    }
}
