在java 项目中如何将map缓存改为ehcache缓存?各位大神帮帮忙,代码如下,这些缓存以前是放在map中的,现在想换成放在ehcache中
你看,我这些缓存以前是放在map中,现在想放入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<String, Codebassexualdistinction> 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<String, String>();
fullNamedistrictMap = new LinkedHashMap<String, String>();
allDistrictMap = new LinkedHashMap<String, String>();
districtObjectMap = new LinkedHashMap<String, Codebasdistrict>();
List<Codebasdistrict> districtList = null;
ICodebasdistrictService districtService = UtilFactory
.getCodebasdistrictService();
districtList = districtService.findAllCodebasdistrict();
if (districtList != null) {
for (Iterator<Codebasdistrict> 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);
}
/**
* 性别代码表Map
*/
public static Map<String, Codebassexualdistinction> getCodebassexualdistinction() {
if (basesexMap == null) {
ICodebassexualdistinctionService service = UtilFactory
.getCodebassexualdistinctionService();
List ls = service.findAllCodebassexualdistinction();
basesexMap = new LinkedHashMap<String, Codebassexualdistinction>();
for (int i = 0; i < ls.size(); i++) {
Codebassexualdistinction obj = (Codebassexualdistinction) ls
.get(i);
basesexMap.put(obj.getSexcode(), obj);
}
}
return basesexMap;
}
private static Map<String, Map<String, Map<String, Emslisttablebase>>> roleRefListMap;
/**
* 角色能访问的列表MAP
* --------------(角色ID,((-列表代码,(--字段代码,字段对象))))
*/
public static Map<String,Map<String,Map<String,Emslisttablebase>>> getRoleRefListMap(){
if (roleRefListMap == null) {
long c = System.currentTimeMillis();
roleRefListMap = new HashMap<String, Map<String,Map<String,Emslisttablebase>>>();
if(tablebaseMap == null){
tablebaseMap = new HashMap<String, Emslisttablebase>();
}else{
tablebaseMap.clear();
}
List list = UtilFactory.getEmslisttableconfigService().queryAllEmslisttableconfig();
int l = list.size();
for(int i=0; i<l; i++){
Emslisttableconfig cfg = (Emslisttableconfig)list.get(i);
if(!tablebaseMap.containsKey(cfg.getListbaseid())){
tablebaseMap.put(cfg.getListbaseid(), cfg.getTablebase());
}
if(!roleRefListMap.containsKey(cfg.getRoleid())){
roleRefListMap.put(cfg.getRoleid(), new HashMap<String,Map<String, Emslisttablebase>>());
}
if(cfg.getTablebase().getDataflag().equals("0")){//列表
if(!roleRefListMap.get(cfg.getRoleid()).containsKey(cfg.getListbaseid())){
roleRefListMap.get(cfg.getRoleid()).put(cfg.getTablebase().getColumncode(),new HashMap<String, Emslisttablebase>());
}
}else{//字段
if(!roleRefListMap.get(cfg.getRoleid()).containsKey(tablebaseMap.get(cfg.getTablebase().getParentcode()).getColumncode())){
roleRefListMap.get(cfg.getRoleid()).put(tablebaseMap.get(cfg.getTablebase().getParentcode()).getColumncode(),
new HashMap<String, Emslisttablebase>());
}
roleRefListMap.get(cfg.getRoleid()).get(tablebaseMap.get(cfg.getTablebase().getParentcode()).getColumncode())
.put(cfg.getTablebase().getColumncode(), cfg.getTablebase());
}
}
System.out.println("初始化列表访问权限:------taste-----------"+(System.currentTimeMillis()-c));
}
return roleRefListMap;
}
public static void resetRoleRefListMap(){
if (roleRefListMap != null) {
roleRefListMap.clear();
roleRefListMap = null;
}
getRoleRefListMap();
}
/**
* 根据角色id获取该角色所有可访问的列表权限
* @param roleid
* @return
*/
public static Map<String, Map<String, Emslisttablebase>> getAllListPrivByRoleid(String roleid){
Map<String,Map<String, Emslisttablebase>> pMap = new HashMap<String,Map<String, Emslisttablebase>>();
//得到该角色所有可访问的列表
List privlist = UtilFactory.getEmslisttableconfigService().findAllListByRoleid(roleid);
if (privlist != null) {
for (int j = 0; j < privlist.size(); j++) {
Emslisttableconfig listTable = (Emslisttableconfig)privlist.get(j);
//得到列表的CODE
String listcode = getTablebaseMap().get(listTable.getListbaseid()).getColumncode();
if (!pMap.containsKey(listcode)) {
//得到该角色在该列表中的可访问字段
List colList = UtilFactory.getEmslisttableconfigService().findAllColumnByRoleidAndListcode(roleid, listcode);
Map<String, Emslisttablebase> colMap = new HashMap<String, Emslisttablebase>();
if(colList != null){
for(int i=0; i<colList.size(); i++){
Emslisttableconfig colTable = (Emslisttableconfig)colList.get(i);
colMap.put(getTablebaseMap().get(colTable.getListbaseid()).getColumncode(),
getTablebaseMap().get(colTable.getListbaseid()));
}
}
pMap.put(listcode, colMap);
}
}
}
return pMap;
}
/**
* 获取全部的列表基础信息
* @return
*/
public static Map<String, Emslisttablebase> getTablebaseMap() {
if(tablebaseMap == null){
tablebaseMap = new HashMap<String, Emslisttablebase>();
List tablebaseList = UtilFactory.getEmslisttablebaseService().findAllEmslisttablebase();
if(tablebaseList != null && tablebaseList.size() > 0){
for(int i=0; i< tablebaseList.size(); i++){
Emslisttablebase tablebase = (Emslisttablebase)tablebaseList.get(i);
tablebaseMap.put(tablebase.getListbaseid(), tablebase);
}
}
}
return tablebaseMap;
}
public static void resetTablebaseMap(){
if(tablebaseMap != null){
tablebaseMap.clear();
tablebaseMap = null;
}
resetRoleRefListMap();
}
/**
* 人名处理,加判断会出现问题,去掉判断的方法 这个Map方法使用时效率太低,不建议使用
*
* @author tzw
* @return
*/
public static Map getUserMap() {
personMap = new LinkedHashMap<String, String>();
List peopleList = null;
peopleList = UtilFactory.getEmsuserService().findAllEmsuser();
if (peopleList != null) {
for (Iterator iterator = peopleList.iterator(); iterator.hasNext();) {
Emsuser element = (Emsuser) iterator.next();
personMap.put(element.getUserid(), element.getUsername());
}
}
return personMap;
}
/**
* 人名处理,加判断会出现问题,去掉判断的方法 这个Map方法使用时效率太低,不建议使用
*
* @author tzw
* @return
*/
public static Map getPersonMap() {
userMap = new LinkedHashMap<String, Emsuser>();
List peopleList = null;
peopleList = UtilFactory.getEmsuserService().findAllEmsuser();
if (peopleList != null) {
for (Iterator iterator = peopleList.iterator(); iterator.hasNext();) {
Emsuser element = (Emsuser) iterator.next();
userMap.put(element.getUserid(), element);
}
}
return userMap;
}
public static Map<String, String> getDutyPersonNameMap() {
if (dutyPersonNameMap == null) {
dutyPersonNameMap = new LinkedHashMap<String, String>();
List peopleList = null;
peopleList = UtilFactory.getEmsuserService().findAllEmsuser();
if (peopleList != null) {
for (Iterator iterator = peopleList.iterator(); iterator
.hasNext();) {
Emsuser element = (Emsuser) iterator.next();
// dutyPersonNameMap.put(element.getUserid(), element
// .getShortname());
dutyPersonNameMap.put(element.getUserid(), element.getUsername());
}
}
}
return dutyPersonNameMap;
}
public static Map<String, String> getDutyPersonOrgMap() {
if (dutyPersonOrgMap == null) {
dutyPersonOrgMap = new LinkedHashMap<String, String>();
List peopleList = null;
peopleList = UtilFactory.getEmsuserService().findAllEmsuser();
if (peopleList != null) {
for (Iterator iterator = peopleList.iterator(); iterator
.hasNext();) {
Emsuser element = (Emsuser) iterator.next();
dutyPersonOrgMap.put(element.getUserid(), element
.getOrgcode());
}
}
}
return dutyPersonNameMap;
}
public static Map<String, String> getDutyPersonSexMap() {
if (dutyPersonSexMap == null) {
dutyPersonSexMap = new LinkedHashMap<String, String>();
List peopleList = null;
peopleList = UtilFactory.getEmsuserService().findAllEmsuser();
if (peopleList != null) {
for (Iterator iterator = peopleList.iterator(); iterator
.hasNext();) {
Emsuser element = (Emsuser) iterator.next();
dutyPersonSexMap.put(element.getUserid(), element.getSex());
}
}
}
return dutyPersonSexMap;
}
/**
* 用户组
*/
public static Map<String,String> getUsergroupMap(){
if(usergroupMap==null||usergroupMap.size()==0){
usergroupMap = new LinkedHashMap<String, String>();
ICodebasdistrictService iService = (ICodebasdistrictService)BeanUtil.getBean("codebasdistrictService");
List lst = iService.findAllTypeById("usergroup");
if(null!=lst &&lst.size()>0){
for(Iterator iterator = lst.iterator();iterator.hasNext();){
Object[] objs = (Object[]) iterator.next();
usergroupMap.put(objs[0].toString(), objs[1].toString());
}
}
}
return usergroupMap;
}
}
这谁看的懂…………
我改了一下,你在看看