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

📄 countersserviceimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2007-1-30
 * Last modified on 2007-11-3
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.service.util.impl;

import java.util.List;

import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.cache.CacheFactory;
import com.yeqiangwei.club.dao.CountersDAO;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;

import org.apache.log4j.Logger;
import com.yeqiangwei.club.dao.model.Counters;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.CounterParameter;
import com.yeqiangwei.club.service.util.CountersService;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.TypeChange;

public class CountersServiceImpl implements CountersService {
	
	private static final Logger logger = Logger.getLogger(CountersServiceImpl.class);
	
	private Cache cache = CacheFactory.creator(); 
	
	private CountersDAO dao = DAOWrapper.<CountersDAO>getDAO(DAOLocator.COUNTERS);

	public Counters findById(int id) {
		if(id>0){
			Counters item = (Counters) cache.get("Counters_"+id);
			if(item==null){
				item = dao.findById(id);
				cache.put("Counters_"+id,item);
			}
			return item;
		}else{
			return null;
		}
	}

	public void createOrUpdate(Counters item) throws ClubException {
		try {
			if(item.getCountersId()>0){
				dao.update(item);
			}else{
				dao.create(item);
			}
		} catch (DAOException e) {
			throw new ClubException(MessageUtils.getMessage("error_system"));
		}

	}

	public void create(Counters item) throws ClubException {
		if(item!=null){
			try {
				dao.create(item);
			} catch (DAOException e) {
				throw new ClubException(MessageUtils.getMessage("error_system"));
			}
			cache.put("Counters_"+item.getCountersId(),item);
		}
	}

	public void update(Counters item) throws ClubException {
		try {
			dao.update(item);
		} catch (DAOException e) {
			throw new ClubException(MessageUtils.getMessage("error_system"));
		}
		cache.update("Counters_"+item.getCountersId(),item);
	}

	public int delete(Counters item) throws ClubException {
		int c = 0;
		if(item.getCountersId()>0){
			try {
				c = dao.delete(item);
			} catch (DAOException e) {
				throw new ClubException(MessageUtils.getMessage("error_system"));
			}
		}
		return c;
	}

	public int delete(String[] ids) throws ClubException {
		int c = 0;
		if(ids!=null&&ids.length>0){
			for(int i=0; i<ids.length; i++){
				int id = TypeChange.stringToInt(ids[i]);
				Counters item = new Counters();
				item.setCountersId(id);
				try {
					c = c+this.delete(item);
				} catch (ClubException e) {
					logger.error(e.toString());
				}
			}
		}else{
			throw new ClubException(MessageUtils.getMessage("error_delete_noid"));
		}
		return c;
	}

	public List<Counters> findByParameter(CounterParameter param) {
		return dao.findByParameter(param);
	}

	public long countByParameter(CounterParameter param) {
		return dao.countByParameter(param);
	}

	public Counters findOnlyByParameter(CounterParameter param) {
		return dao.findOnlyByParameter(param);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -