Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package data.services; import data.dao.BaseParamDao; import data.dao.ProfileParamDao; import data.dao.SceneDao; import data.entity.BaseParam; import data.entity.ProfileParam; import data.services.parent.PrimService; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import logic.Radical; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import support.StringAdapter; /** * * @author bezdatiuzer */ @Service @Transactional @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) public class ProfileParamService extends PrimService { @Autowired private ProfileParamDao profileParamDao; @Autowired private BaseParamDao baseParamDao; @Autowired private BaseParamService baseParamService; public List<ProfileParam> getParams(Radical rd) { ProfileParam pp = new ProfileParam(); pp.setRadical(rd); return profileParamDao.find(pp); } public LinkedHashMap<ProfileParam, BaseParam> getParamsMap(Radical rd) throws Exception { LinkedHashMap<ProfileParam, BaseParam> ppMap = new LinkedHashMap(); List<ProfileParam> pplist = getParams(rd); List<BaseParam> bpList = baseParamService.getParams(); for (ProfileParam pp : pplist) { ppMap.put(pp, new BaseParam()); for (BaseParam bp : bpList) { if (pp.getUid().trim().equals(bp.getUid().trim())) { ppMap.put(pp, bp); } } } //throw new Exception(pplist.size()+" " +bpList.size()+" "+ ppMap.size() ); return ppMap; } public void delete(Long id) { if (profileParamDao.find(id) != null) { profileParamDao.delete(profileParamDao.find(id)); } } public void addHeap(String heap, Radical rd) throws Exception { if (StringAdapter.NotNull(heap)) { /*for(ProfileParam pp:getParams(rd)){ delete(pp.getId()); }*/ String[] paramsplit = heap.trim().split(";;"); String exception = ""; int cnt = 0; for (String param : paramsplit) { if (StringAdapter.NotNull(param)) { BaseParam bp = new BaseParam(); bp.setUid(param.trim()); if (!baseParamDao.find(bp).isEmpty()) { ProfileParam pp = new ProfileParam(); pp.setUid(param); pp.setRadical(rd); //List<ProfileParam> plist = profileParamDao.find(pp); if (validate(pp)) { for (ProfileParam ppd : profileParamDao.find(pp)) { profileParamDao.delete(ppd); } profileParamDao.save(pp); } } else { addError(" ? ? uid" + param); } } } } } }