yxlhw1
yxlhw1
2017-06-23 01:30
采纳率: 50%
浏览 762

如何在ssh中将以下缓存代码改为Ehcache?

package gov.csc.ems.util.cache;

import gov.csc.ems.basedata.code.model.Codebasdistrict;
import gov.csc.ems.basedata.code.model.Codebassexualdistinction;
import gov.csc.ems.basedata.code.service.ICodebasdistrictService;
import gov.csc.ems.basedata.code.service.ICodebassexualdistinctionService;
import gov.csc.ems.util.dataaccess.model.Emslisttablebase;
import gov.csc.ems.util.dataaccess.model.Emslisttableconfig;
import gov.csc.ems.util.servicebase.UtilFactory;
import gov.csc.ems.util.sys.priv.model.Emsorg;
import gov.csc.ems.util.sys.priv.model.Emspriv;
import gov.csc.ems.util.sys.priv.model.Emsroleprivrel;
import gov.csc.ems.util.sys.priv.model.Emsuser;
import gov.csc.ems.util.sys.priv.util.IConstants;
import gov.csc.ems.util.sys.priv.util.PrivServiceFactory;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.thtf.ezone.security.util.BeanUtil;

public final class BaseCodeUtil {

private static Map<String, String> orgMap;// ok
private static Map<String, String> orgReverseMap;// ok
private static Map<String, String> orgIdMap;// 没动
private static Map<String, String> orgParentMap;// ok
private static Map orgObjectMap;// ok

private static Map<String, String> districtMap;// ok
private static Map<String, String> fullNamedistrictMap;// ok
private static Map<String, String> parentDistrictMap;// 
private static Map<String, String> allDistrictMap;// ok
private static Map<String, String> shortNameDistrictMap;// ok
private static Map<String, Codebasdistrict> districtObjectMap;// ok
private static Map<String, String> personMap;// not ok

private static Map<String, Emsuser> userMap;// not ok
private static Map<String, String> dutyPersonNameMap;// ok
private static Map<String, String> dutyPersonOrgMap;// ok
private static Map<String, String> dutyPersonSexMap;// ok


//用户组
private static Map<String,String> usergroupMap;

// // 性别MAP表
private static Map basesexMap;

// // 机构
private static final String ALL_ORG_MAP = "all_org_map";
private static final String ORGCODE_BYNAME_MAP = "orgcode_byname_map";
private static final String ORG_PARENT_MAP = "orgparentmap";
private static final String ALL_ORG_MAP_OBJ = "all_org_map_obj";
private static final String RE_INIT_ORG = "re_init_org";

/**
 * 列表基础信息MAP
 */
private static Map<String, Emslisttablebase> tablebaseMap;


public static Map getOrgMap() {
    return BaseCodeUtil.getOrgMapByParam(ALL_ORG_MAP);
}

/**
 * 根据参数取得org相关map flag=,返回key:,value: flag=,返回key:,value:
 * 
 * @param flag
 * @return
 * @author guorj
 * @date May 7, 2009
 */
private static Map getOrgMapByParam(String flag) {
    if (orgMap == null || orgReverseMap == null || orgParentMap == null
            || orgObjectMap == null || RE_INIT_ORG.equals(flag)) {
        orgMap = new LinkedHashMap<String, String>();
        orgReverseMap = new LinkedHashMap<String, String>();
        orgParentMap = new LinkedHashMap<String, String>();
        orgObjectMap = new LinkedHashMap();

        List list = null;
        list = UtilFactory.getEmsorgService().findAllEmsorg();
        if (list != null) {
            for (Iterator iterator = list.iterator(); iterator.hasNext();) {
                Emsorg element = (Emsorg) iterator.next();
                orgMap.put(element.getOrgcode(), element.getOrgname());
                orgReverseMap.put(element.getOrgname(), element
                        .getOrgcode());
                orgParentMap
                        .put(element.getOrgname(), element.getOrgcode());
                orgObjectMap.put(element.getOrgcode(), element);
            }
        }
    }
    if (ALL_ORG_MAP.equals(flag)) {
        return orgMap;
    }
    if (ORGCODE_BYNAME_MAP.equals(flag)) {
        return orgReverseMap;
    }
    if (ORG_PARENT_MAP.equals(flag)) {
        return orgParentMap;
    }
    if (ALL_ORG_MAP_OBJ.equals(flag)) {
        return orgObjectMap;
    }

    return null;
}

/**
 * 取得包含所有的行政区划的map key:Districtid value:name
 * 
 * @return
 * @date May 7, 2009
 */
public static Map<String, String> getAllDistrictMap() {
    return BaseCodeUtil.getDistrictMapByParam(DISTRICT_ALL);
}

/**
 * 短名字的行政区划map
 * 
 * @return
 * @author guorj
 * @date May 7, 2009
 */
public static Map<String, String> getShortNameDistrictMap() {
    return BaseCodeUtil.getDistrictMapByParam(DISTRICT_SHORTNAME);
}

/**
 * 取得行政区划对象 key:id value:Codebasdistrict对象
 * 
 * @return
 * @author guorj
 * @date May 31, 2009
 */
@SuppressWarnings("unchecked")
public static Map<String, Codebasdistrict> getDistrictObjectMap() {
    return BaseCodeUtil.getDistrictMapByParam(DISTRICT_ALL_OBJECT);
}

private static final String DISTRICT_SHORTNAME = "shortname";
private static final String DISTRICT_FULLNAME = "fullname";
private static final String DISTRICT_ALL = "all";
private static final String DISTRICT_ALL_OBJECT = "allobject";

//
/**
* 根据不同的参数返回不同的map 包含所有行政区划map
* flag=shortname,返回key:Districtid,value:shortname
* flag=fullname,返回key:Districtid,value:fullname
* flag=all,返回key:Districtid,value:name
*
* @param flag
* @return
* @author guorj
* @date May 7, 2009 shortNameDistrictMap fullNamedistrictMap allDistrictMap
*/
private static Map getDistrictMapByParam(String flag) {
if (shortNameDistrictMap == null || fullNamedistrictMap == null
|| allDistrictMap == null || districtObjectMap == null) {
shortNameDistrictMap = new LinkedHashMap();
fullNamedistrictMap = new LinkedHashMap();
allDistrictMap = new LinkedHashMap();
districtObjectMap = new LinkedHashMap();
List districtList = null;
ICodebasdistrictService districtService = UtilFactory
.getCodebasdistrictService();
districtList = districtService.findAllCodebasdistrict();
if (districtList != null) {
for (Iterator it = districtList.iterator(); it
.hasNext();) {
Codebasdistrict ele = it.next();
shortNameDistrictMap.put(ele.getDistrictcode(), ele
.getShortname());
fullNamedistrictMap.put(ele.getDistrictcode(), ele
.getFullname());
allDistrictMap.put(ele.getDistrictcode(), ele
.getDistrictname());
districtObjectMap.put(ele.getDistrictcode(), ele);
}
}
}
if (flag != null) {
if (flag.equals(DISTRICT_SHORTNAME)) {
return shortNameDistrictMap;
}
if (flag.equals(DISTRICT_FULLNAME)) {
return fullNamedistrictMap;
}
if (flag.equals(DISTRICT_ALL)) {
return allDistrictMap;
}
if (flag.equals(DISTRICT_ALL_OBJECT)) {
return districtObjectMap;
}
}
return null;
}

public static Map getFullNamedistrictMap() {
    return getDistrictMapByParam(DISTRICT_FULLNAME);
}

/**
 * 根据行政区划id取得全名
 * 
 * @param districtid
 * @return
 * @author guorj
 * @date Jun 10, 2009
 */
public static String getDistrictFullnameById(String districtid) {
    return (String) getFullNamedistrictMap().get(districtid);
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • zy_281870667
    Bug开发攻城狮 2017-06-23 01:48
    已采纳

    引入ehcache的jar和配置文件,写个util类,名字和你现在方法名一致。

    具体的代码,参考
    http://www.cnblogs.com/jingmoxukong/p/5975994.html

    点赞 评论
  • zy_281870667
    Bug开发攻城狮 2017-06-23 09:42

    代码很简单的

    private static Map getOrgMapByParam(String flag) {
    if(null != 存储的key){
    return ehcacheUtils.getOrgMapByParam(存储的key);
    }
    return null;
    }

    点赞 评论

相关推荐