areaserviceimpl.java

来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 96 行

JAVA
96
字号
/* 
 * Created on 2007-2-3
 * Last modified on 2007-12-20
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.service.util.impl;

import java.util.ArrayList;
import java.util.List;

import com.yeqiangwei.club.dao.AreaDAO;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.model.Area;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.param.AreaParameter;
import com.yeqiangwei.club.service.util.AreaService;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;

public class AreaServiceImpl implements AreaService {
	
	public Area findById(int id) {
		if(id>0){
			return this.getAreaDAO().findById(id);
		}
		return null;
	}

	public void createOrUpdate(Area model) throws ClubException {
		if(model.getAreaId()>0){
			this.update(model);
		}else{
			this.create(model);
		}
	}

	public void create(Area model) throws ClubException {
		if(Validator.isEmpty(model)){
			throw new ClubException(MessageUtils.getMessage("error_system"));
		}
		else if(Validator.isEmpty(model.getName())){
			throw new ClubException(MessageUtils.getMessage("error_empty"));
		}
		else{
			this.getAreaDAO().create(model);
		}
	}

	public void update(Area model) throws ClubException {
		if(Validator.isEmpty(model)){
			throw new ClubException(MessageUtils.getMessage("error_param"));
		}
		else if(Validator.isEmpty(model.getName())){
			throw new ClubException(MessageUtils.getMessage("error_param"));
		}
		else{
			this.getAreaDAO().update(model);
		}
	}

	public int delete(Area model) throws ClubException {
		if(model.getAreaId()>0){
			return this.getAreaDAO().delete(model);
		}else{
			throw new ClubException(MessageUtils.getMessage("error_param"));
		}
	}

	public int delete(String[] ids) throws ClubException {
		if(!Validator.isEmpty(ids)){
			List<Integer> list = new ArrayList<Integer>();
			for(int i=0; i<ids.length; i++){
				int id = TypeChange.stringToInt(ids[i]);
				list.add(new Integer(id));
			}
			return this.getAreaDAO().delete(list);
		}else{
			throw new ClubException(MessageUtils.getMessage("error_param"));
		}
	}

	public List<Area> findByParameter(AreaParameter param) {
		return this.getAreaDAO().findByParameter(param);
	}

	public long countByParameter(AreaParameter param) {
		return this.getAreaDAO().countByParameter(param);
	}

	public AreaDAO getAreaDAO() {
		return DAOWrapper.<AreaDAO>getSingletonInstance(DAOLocator.AREA);
	}
}

⌨️ 快捷键说明

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