📄 basicservice.java
字号:
package com.pegasus.framework.service.impl;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import com.pegasus.framework.component.taglib.html.pager.PageAgent;
import com.pegasus.framework.constant.Constant;
import com.pegasus.framework.dao.IBasicDAO;
import com.pegasus.framework.exception.BusinessException;
import com.pegasus.framework.pojo.IBusinessObject;
import com.pegasus.framework.service.IBasicService;
public abstract class BasicService implements IBasicService {
protected final Log logger = LogFactory.getLog(this.getClass());
protected abstract IBasicDAO getBasicDAO();
public String getTableName() {
return getBasicDAO().getTableName();
}
public void delete(Serializable id) throws BusinessException{
getBasicDAO().delete(id);
}
public void delete(IBusinessObject data) throws BusinessException{
getBasicDAO().delete(data);
}
public IBusinessObject load(Serializable id) throws BusinessException{
IBusinessObject data = null;
data = getBasicDAO().selectOne(id);
if(data != null) {
try {
data = (IBusinessObject)data.clone();
}catch(Exception e) {
try {
data = data.clone(data);
}catch(Exception ex) {
logger.warn("load error " );
data = null;
}
}
}
return data;
}
public IBusinessObject load(String pk, String value) throws BusinessException{
IBusinessObject data = null;
data = getBasicDAO().selectOneByOtherPK(pk,value);
if(data != null) {
try {
data = (IBusinessObject)data.clone();
}catch(Exception e) {
try {
data = data.clone(data);
}catch(Exception ex) {
logger.warn("load error " );
data = null;
}
}
}
return data;
}
public List query() throws BusinessException {
return getBasicDAO().select();
}
public List query(Criterion[] criterionArray, Order[] orderArray) throws BusinessException {
return query(criterionArray, orderArray, null);
}
public List query(Criterion[] criterionArray, Order[] orderArray, PageAgent pageAgent) throws BusinessException {
List result = getBasicDAO().select(criterionArray, orderArray, pageAgent);
return result;
}
public List query(List criterionList, List orderList) throws BusinessException {
return query(criterionList, orderList, null);
}
public List query(List criterionList, List orderList, PageAgent pageAgent) throws BusinessException {
return getBasicDAO().select(criterionList, orderList, pageAgent);
}
public List query(String hql) throws BusinessException {
return getBasicDAO().selectByHQL(hql, null);
}
public List query(String hql,Collection criteria,PageAgent pageAgent) throws BusinessException {
return getBasicDAO().selectByHQL(hql, criteria,pageAgent);
}
public IBusinessObject saveObject(IBusinessObject data) throws BusinessException {
if (data.getId() == null) {
throw new BusinessException("primary key [id] is empty!");
}
/*if(data.getVersion() == null) {
data.setVersion(Constant.DEFAULT_VERSION);
}*/
getBasicDAO().insert(data);
return data;
}
public IBusinessObject saveOrUpdateObject(IBusinessObject data) throws BusinessException {
getBasicDAO().insertOrUpdate(data);
return data;
}
public IBusinessObject updateObject(IBusinessObject data) throws BusinessException {
if (data.getId() == null) {
throw new BusinessException("primary key [id] is empty!");
}
getBasicDAO().update(data);
return data;
}
public IBusinessObject mergeObject(IBusinessObject data) throws BusinessException {
if (data.getId() == null) {
throw new BusinessException("primary key [id] is empty!");
}
getBasicDAO().merge(data);
return data;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -