📄 forumlabelserviceimpl.java
字号:
/*
* Created on 2007-5-21
* Last modified on 2007-11-3
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.forum;
import java.util.List;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.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.dao.model.ForumLabel;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.ForumParameter;
import com.yeqiangwei.club.service.model.ForumLabelModel;
import com.yeqiangwei.club.util.BeanLocator;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.Validator;
public class ForumLabelServiceImpl implements ForumLabelService{
public static Cache labelCache = CacheFactory.creator("ForumLabel");
public ForumLabelModel findById(int id) {
ForumLabelModel model = null;
ForumLabel item = this.getForumLabelDAO().findById(id);
if(!Validator.isEmpty(item)){
model = new ForumLabelModel();
BeanUtils.copyProperties(model,item);
}
return model;
}
public void createOrUpdate(ForumLabelModel model) throws ClubException {
if(model.getLabelId()>0){
this.update(model);
}else{
this.create(model);
}
}
public void create(ForumLabelModel model) throws ClubException {
if(Validator.isEmpty(model)
||Validator.isEmpty(model.getLabelName())
||model.getForumId()==0
){
throw new ClubException(MessageUtils.getMessage("error_empty"));
}else{
ForumLabel item = new ForumLabel();
BeanUtils.copyProperties(item,model);
try {
this.getForumLabelDAO().create(item);
labelCache.clear();
model.setLabelId(item.getLabelId());
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
}
}
public void update(ForumLabelModel 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{
ForumLabel item = new ForumLabel();
BeanUtils.copyProperties(item,model);
try {
this.getForumLabelDAO().update(item);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
labelCache.clear();
}
}
public int delete(ForumLabelModel model) throws ClubException {
ForumLabel item = new ForumLabel();
item.setLabelId(model.getLabelId());
labelCache.clear();
try {
return this.getForumLabelDAO().delete(item);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
}
public int update(int forumId, int toForumId) throws ClubException {
if(forumId>0&&toForumId>0){
labelCache.clear();
try {
return this.getForumLabelDAO().update(forumId,toForumId);
} catch (DAOException e) {
throw new ClubException(e.getMessage());
}
}else{
return 0;
}
}
@SuppressWarnings("unchecked")
public List<ForumLabelModel> findByForumId(int forumId) {
Boolean isput = (Boolean) labelCache.get(cacheKey(forumId)+"-isput");
List<ForumLabelModel> list = (List<ForumLabelModel>) labelCache.get(cacheKey(forumId));
if(Validator.isEmpty(list)&&Validator.isEmpty(isput)){
ForumParameter param = new ForumParameter();
param.setForumId(new Integer(forumId));
list = this.findByParameter(param);
labelCache.put(cacheKey(forumId),list);
labelCache.put(cacheKey(forumId)+"-isput", new Boolean(true));
}
return list;
}
public List<ForumLabelModel> findByParameter(ForumParameter param) {
List<ForumLabel> list = this.getForumLabelDAO().findByParameter(param);
List<ForumLabelModel> mlist = BeanUtils.<ForumLabel,ForumLabelModel>copyList(list,BeanLocator.FORUMLABELMODEL);
return mlist;
}
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -