⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumlabelserviceimpl.java

📁 这是一款最新的野蔷薇论坛源码,有需要的朋友可以尽情下载
💻 JAVA
字号:
/* 
 * Created on 2007-5-21
 * Last modified on 2007-6-6
 * 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.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 extends MessageUtils 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 ForumLabelModel createOrUpdate(ForumLabelModel model) {
		if(model.getLabelId()>0){
			return this.update(model);
		}else{
			return this.create(model);
		}
	}

	public ForumLabelModel create(ForumLabelModel model) {
		if(Validator.isEmpty(model)
				||Validator.isEmpty(model.getLabelName())
				||model.getForumId()==0
		){
			this.setMessage(super.getMessage("error_empty"));
			model = null;
		}else{
			ForumLabel item = new ForumLabel();
			BeanUtils.copyProperties(item,model);
			item = this.getForumLabelDAO().create(item);
			if(Validator.isEmpty(item)){
				model = null;
				this.setMessage(super.getMessage("error_system"));
			}else{
				labelCache.clear();
				model.setLabelId(item.getLabelId());
				this.setMessage(super.getMessage("success"));
			}
		}
		return model;
	}

	public ForumLabelModel update(ForumLabelModel model) {
		if(Validator.isEmpty(model)
				||Validator.isEmpty(model.getLabelName())
				||model.getForumId()==0
				||model.getLabelId()==0
		){
			this.setMessage(super.getMessage("error_empty"));
			model = null;
		}else{
			ForumLabel item = new ForumLabel();
			BeanUtils.copyProperties(item,model);
			item = this.getForumLabelDAO().update(item);
			if(Validator.isEmpty(item)){
				model = null;
				this.setMessage(super.getMessage("error_system"));
			}else{
				labelCache.clear();
				this.setMessage(super.getMessage("success"));
			}
		}
		return model;
	}

	public int delete(ForumLabelModel model) {
		ForumLabel item = new ForumLabel();
		item.setLabelId(model.getLabelId());
		int c = this.getForumLabelDAO().delete(item);
		if(c>0){
			labelCache.clear();
			this.setMessage(super.getMessage("success"));
		}else{
			this.setMessage(super.getMessage("error_system"));
		}
		return c;
	}

	@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;
	}
	

	public int update(int forumId, int toForumId) {
		if(forumId>0&&toForumId>0){
			labelCache.clear();
			this.setMessage(MessageUtils.getMessage("success"));
			return this.getForumLabelDAO().update(forumId,toForumId);
		}
		else{
			this.setMessage(MessageUtils.getMessage("error"));
			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 + -