friendlabelserviceimpl.java
来自「社区文章采用的是平板、树形自由选择的两种展示方式」· Java 代码 · 共 120 行
JAVA
120 行
/*
* Created on 2007-4-26
* Last modified on 2008-1-1
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.user;
import java.util.List;
import org.apache.log4j.Logger;
import com.yeqiangwei.cache.Cache;
import com.yeqiangwei.cache.CacheFactory;
import com.yeqiangwei.club.cache.CacheKeys;
import com.yeqiangwei.club.cache.CacheRegion;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.FriendLabelDAO;
import com.yeqiangwei.club.model.FriendLabel;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.param.FriendParameter;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;
public class FriendLabelServiceImpl implements FriendLabelService{
private static Logger logger = Logger.getLogger(FriendLabelServiceImpl.class);
private static Cache<FriendLabel> CACHE = CacheFactory.<FriendLabel>creator(CacheRegion.FRIEND_LABEL);
public static void main(String args[]){
}
public void createOrUpdate(FriendLabel model) throws ClubException {
if(model.getLabelId()>0){
this.update(model);
}else{
this.create(model);
}
}
public void create(FriendLabel model) throws ClubException {
if(!Validator.isEmpty(model)){
if(!Validator.isEmpty(model.getLabelName())){
this.getFriendLabelDAO().create(model);
}else{
throw new ClubException(MessageUtils.getMessage("error_empty"));
}
}
}
public void update(FriendLabel model) throws ClubException {
if(!Validator.isEmpty(model)||model.getLabelId()>0){
if(!Validator.isEmpty(model.getLabelName())){
FriendLabel item = this.getFriendLabelDAO().findById(model.getLabelId());
BeanUtils.copyProperties(item,model);
this.getFriendLabelDAO().update(item);
CACHE.put(CacheKeys.getKey(model),model);
}else{
throw new ClubException(MessageUtils.getMessage("error_empty"));
}
}
}
public int delete(FriendLabel model) throws ClubException {
if(!Validator.isEmpty(model)&&model.getLabelId()>0){
CACHE.remove(model);
return this.getFriendLabelDAO().delete(model);
}else{
throw new ClubException(MessageUtils.getMessage("error_system"));
}
}
public int delete(String[] ids) {
int s = 0;
if(!Validator.isEmpty(ids)){
for(int i=0; i<ids.length; i++){
int id = TypeChange.stringToInt(ids[i]);
FriendLabel model = new FriendLabel();
model.setLabelId(id);
try {
s = s+this.delete(model);
} catch (ClubException e1) {
logger.error(e1.toString());
}
}
}
return s;
}
public FriendLabel findById(int id) {
FriendLabel model = null;
if(id>0){
FriendLabel item = this.getFriendLabelDAO().findById(id);
if(!Validator.isEmpty(item)){
model = new FriendLabel();
BeanUtils.copyProperties(model,item);
CACHE.put(CacheKeys.getKey(model),model);
}
}
return model;
}
public List<FriendLabel> findByParameter(FriendParameter param) {
return this.getFriendLabelDAO().findByParameter(param);
}
public long countByParameter(FriendParameter param) {
return this.getFriendLabelDAO().countByParameter(param);
}
public FriendLabelDAO getFriendLabelDAO() {
return DAOWrapper.<FriendLabelDAO>getDAO(DAOLocator.FRIENDLABEL);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?