Map处理内存的方法

public static Map<String, Map<String, EsbErrorInfo>> listMap = null;
    private static void listErrorInfos(String Language)
    {
        if (Contants.listMap != null)
        {
            return;
        }
        else
        {
            Contants.listMap = new HashMap<String, Map<String, EsbErrorInfo>>();
        }
        String sys_type = "";
        Map<String, EsbErrorInfo> MapErrors = null;

        initConnect();
        PreparedStatement pre = null;
        ResultSet rs = null;
        // log.info(select_esb_error.toString());
        try
        {
            pre = conn.prepareStatement(select_esb_error.toString());
            pre.setString(1, Language);
            rs = pre.executeQuery();
            while (rs.next())
            {
                sys_type = rs.getString("SYS_TYPE");
                if (Contants.listMap.containsKey(sys_type))
                {
                    MapErrors = Contants.listMap.get(sys_type);
                    EsbErrorInfo info = new EsbErrorInfo();
                    info.setESB_ERROR_CODE(rs.getString("ESB_ERROR_CODE"));
                    info.setESB_ERROR_MSG(rs.getString("ESB_ERROR_MSG"));
                    info.setEXTEND_ERROR_CODE(rs.getString("EXTEND_ERROR_CODE"));
                    info.setLANGUAGE(rs.getString("LANGUAGE"));
                    info.setSYS_TYPE(rs.getString("SYS_TYPE"));
                    MapErrors.put(info.getEXTEND_ERROR_CODE(), info);
                }
                else
                {
                    MapErrors = new HashMap<String, EsbErrorInfo>();
                    Contants.listMap.put(sys_type, MapErrors);
                    EsbErrorInfo info = new EsbErrorInfo();
                    info.setESB_ERROR_CODE(rs.getString("ESB_ERROR_CODE"));
                    info.setESB_ERROR_MSG(rs.getString("ESB_ERROR_MSG"));
                    info.setEXTEND_ERROR_CODE(rs.getString("EXTEND_ERROR_CODE"));
                    info.setLANGUAGE(rs.getString("LANGUAGE"));
                    info.setSYS_TYPE(rs.getString("SYS_TYPE"));
                    MapErrors.put(info.getEXTEND_ERROR_CODE(), info);
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    public static String getErrorInfoByKeys(String Language,
            String Extend_Error_code, String Sys_Type)
    {
        String ErrorInfo = null;
        try
        {
            listErrorInfos(Language);
            EsbErrorInfo info = listMap.get(Sys_Type).get(Extend_Error_code);
            if (info != null)
            {
                ErrorInfo = info.getESB_ERROR_CODE() + "&"
                        + info.getESB_ERROR_MSG();
            }
        }
        catch (Exception e)
        {
        }
        return ErrorInfo;
    }
    protected static StringBuffer select_esb_error = new StringBuffer(
            "select * from esb_error_code_info where LANGUAGE=? order by sys_type");
    public static void main(String[] args)
    {
        System.out.println(getErrorInfoByKeys("en", "831310", "CRM"));
    }
}

你可能感兴趣的:(map)