📄 friendlabelserviceimpl.java
字号:
/*
* Created on 2007-4-26
* Last modified on 2007-11-3
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.user;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.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.dao.model.FriendLabel;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.param.FriendParameter;
import com.yeqiangwei.club.service.model.FriendLabelModel;
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 cache = CacheFactory.creator(CacheRegion.FRIEND_LABEL);
public static void main(String args[]){
}
public void createOrUpdate(FriendLabelModel model) throws ClubException {
if(model.getFriendLabelId()>0){
this.update(model);
}else{
this.create(model);
}
}
public void create(FriendLabelModel model) throws ClubException {
if(!Validator.isEmpty(model)){
if(!Validator.isEmpty(model.getLabelName())){
FriendLabel item = new FriendLabel();
BeanUtils.copyProperties(item,model);
try {
this.getFriendLabelDAO().create(item);
} catch (DAOException e) {
logger.error(e.toString());
throw new ClubException(MessageUtils.getMessage("error_system"));
}
}else{
throw new ClubException(MessageUtils.getMessage("error_empty"));
}
}
}
public void update(FriendLabelModel model) throws ClubException {
if(!Validator.isEmpty(model)||model.getFriendLabelId()>0){
if(!Validator.isEmpty(model.getLabelName())){
FriendLabel item = this.getFriendLabelDAO().findById(model.getFriendLabelId());
BeanUtils.copyProperties(item,model);
try {
this.getFriendLabelDAO().create(item);
} catch (DAOException e) {
logger.error(e.toString());
throw new ClubException(MessageUtils.getMessage("error_system"));
}
BeanUtils.copyProperties(model,item);
cache.put(CacheKeys.getKey(model),model);
}else{
throw new ClubException(MessageUtils.getMessage("error_empty"));
}
}
}
public int delete(FriendLabelModel model) throws ClubException {
int c = 0;
if(!Validator.isEmpty(model)&&model.getFriendLabelId()>0){
FriendLabel item = new FriendLabel();
BeanUtils.copyProperties(item,model);
try {
c = this.getFriendLabelDAO().delete(item);
} catch (DAOException e) {
logger.error(e.toString());
throw new ClubException(MessageUtils.getMessage("error_system"));
}
cache.remove(model);
}
return c;
}
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]);
FriendLabelModel model = new FriendLabelModel();
model.setFriendLabelId(id);
try {
s = s+this.delete(model);
} catch (ClubException e1) {
logger.error(e1.toString());
}
}
}
return s;
}
public FriendLabelModel findById(int id) {
FriendLabelModel model = null;
if(id>0){
FriendLabel item = this.getFriendLabelDAO().findById(id);
if(!Validator.isEmpty(item)){
model = new FriendLabelModel();
BeanUtils.copyProperties(model,item);
cache.put(CacheKeys.getKey(model),model);
}
}
return model;
}
public List<FriendLabelModel> findByParameter(FriendParameter param) {
List<FriendLabel> list = this.getFriendLabelDAO().findByParameter(param);
List<FriendLabelModel> mlist = new ArrayList<FriendLabelModel>();
if(!Validator.isEmpty(list)){
for(int i=0; i<list.size(); i++){
FriendLabel item = list.get(i);
FriendLabelModel model = new FriendLabelModel();
com.yeqiangwei.util.BeanUtils.copyProperties(model,item);
mlist.add(i,model);
cache.put(CacheKeys.getKey(model),model);
}
}
return mlist;
}
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -