forumlabelserviceimpl.java
来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 113 行
JAVA
113 行
/*
* Created on 2007-5-21
* Last modified on 2008-1-1
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.forum;
import java.util.List;
import com.yeqiangwei.cache.Cache;
import com.yeqiangwei.club.cache.CacheRegion;
import com.yeqiangwei.cache.singleton.CacheFactory;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.ForumLabelDAO;
import com.yeqiangwei.club.model.ForumLabel;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.param.ForumParameter;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.Validator;
public class ForumLabelServiceImpl implements ForumLabelService{
@SuppressWarnings("unchecked")
public static Cache CACHE_LABEL = CacheFactory.creator(CacheRegion.FORUM_LABEL);
public ForumLabel findById(int id) {
return this.getForumLabelDAO().findById(id);
}
public void createOrUpdate(ForumLabel model) throws ClubException {
if(model.getLabelId()>0){
this.update(model);
}else{
this.create(model);
}
}
public void create(ForumLabel model) throws ClubException {
if(Validator.isEmpty(model)
||Validator.isEmpty(model.getLabelName())
||model.getForumId()==0
){
throw new ClubException(MessageUtils.getMessage("error_empty"));
}else{
this.getForumLabelDAO().create(model);
CACHE_LABEL.clear();
}
}
public void update(ForumLabel model) throws ClubException {
if(Validator.isEmpty(model)
||Validator.isEmpty(model.getLabelName())
||model.getForumId()==0
||model.getLabelId()==0
){
throw new ClubException(MessageUtils.getMessage("error_empty"));
}else{
this.getForumLabelDAO().update(model);
CACHE_LABEL.clear();
}
}
public int delete(ForumLabel model) throws ClubException {
CACHE_LABEL.clear();
return this.getForumLabelDAO().delete(model);
}
public int update(int forumId, int toForumId) throws ClubException {
if(forumId>0&&toForumId>0){
CACHE_LABEL.clear();
return this.getForumLabelDAO().update(forumId,toForumId);
}else{
return 0;
}
}
@SuppressWarnings("unchecked")
public List<ForumLabel> findByForumId(int forumId) {
Boolean isput = (Boolean) CACHE_LABEL.get(cacheKey(forumId)+"-isput");
List<ForumLabel> list = (List<ForumLabel>) CACHE_LABEL.get(cacheKey(forumId));
if(Validator.isEmpty(list)&&Validator.isEmpty(isput)){
ForumParameter param = new ForumParameter();
param.setForumId(new Integer(forumId));
list = this.findByParameter(param);
CACHE_LABEL.put(cacheKey(forumId),list);
CACHE_LABEL.put(cacheKey(forumId)+"-isput", new Boolean(true));
}
return list;
}
public List<ForumLabel> findByParameter(ForumParameter param) {
return this.getForumLabelDAO().findByParameter(param);
}
public long countByParameter(ForumParameter param) {
return 0;
}
private ForumLabelDAO getForumLabelDAO(){
return DAOWrapper.<ForumLabelDAO>getSingletonInstance(DAOLocator.FORUMLABEL);
}
public String cacheKey(int forumId){
StringBuffer sb = new StringBuffer("ForumLabel:");
sb.append(forumId);
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?