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

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 KikwanInfoDAO extends BaseDAO implements KikwanInfoQuery
{

    public HashMap<String, KikwanInfoVO> getAllKikwanInfos() throws DAOException
    {
    	HashMap<String, KikwanInfoVO> map = new HashMap<String, KikwanInfoVO>();
        ResultSet rs = null;
        KikwanInfoVO vo = null;
        try
        {
            this.connect(GET_ALL_KIKWANCODES);
            rs = this.executeQuery();

            while(rs.next())
            {
                vo = new KikwanInfoVO();

            	vo.setKikwanCd  ( rs.getString("KikwanCd").trim());
            	vo.setKikwanName( rs.getString("KikwanName").trim());
            	vo.setSysIp     ( rs.getString("SysIp").trim());
            	vo.setEncIp     ( rs.getString("EncIp").trim());

                map.put(vo.getKikwanCd(), vo);
            }
        } catch(Exception e) {
            throw new DAOException(ExceptionUtil.getErrorCode(e,"BECEAIMFR016"));
        } finally {
            this.disconnect();
        }
        return map;
    }

    /**
     * 지정된 RuleCode와 PhaseCode에 해당 NodeInfo 리스트를 리턴한다.
     */
    public KikwanInfoVO getKikwanInfo(String kikwanCd ) throws DAOException
    {
        KikwanInfoVO vo = null;
        ResultSet   rs = null;
        try {
            this.connect(GET_KIKWANCODE);
            this.preparedStatement.setString(1, kikwanCd);
            rs = executeQuery();
            vo = new KikwanInfoVO();
            if (rs.next())
            {
            	vo.setKikwanCd  ( rs.getString("KikwanCd").trim());
            	vo.setKikwanName( rs.getString("KikwanName").trim());
            	vo.setSysIp     ( rs.getString("SysIp").trim());
            	vo.setEncIp     ( rs.getString("EncIp").trim());
            }
        } catch(Exception e) {
            throw new DAOException(ExceptionUtil.getErrorCode(e,"BECEAIMFR017", new String[] {kikwanCd, kikwanCd}));
        } finally {
            this.disconnect();
        }
        return vo;
    }
}
