}catch(Exception e){
throw new DaoException("根据传入对象更新记录异常,请联系管理员!");
}
}
/**
*
*
Description:根据传入的实体修改数据库中一条记录,返回更新记录的主键
*
* @author Eric
* @param obj
* @return
* @throws DaoException
*/
public String updateObjectPK(Object obj) throws DaoException{
log.debug("BaseDao updateObjectPK object " + obj);
String id = null;
try{
id = this.addObjectPK(obj);
}catch(Exception e){
throw new DaoException("根据传入对象更新记录异常,请联系管理员!",e);
}
return id;
}
/**
*
*
Description:根据传入的实体添加或修改数据库中一条记录
*
* @author Eric
* @param obj
* @throws DaoException
*/
public void addOrUpdate(Object obj) throws DaoException{
log.debug("BaseDao updateObjectPK object " + obj);
try{
sessionFactory.getCurrentSession().saveOrUpdate(obj);
}catch(Exception e){
throw new DaoException("根据传入对象保存数据异常,请联系管理员!",e);
}
}
/**
*
*
Description:根据ID返回一个对象
*
* @author Eric
* @param cls
* @param id
* @return
* @throws DaoException
*/
@SuppressWarnings({"rawtypes"})
public Object findObjectById(Class cls,Serializable id) throws DaoException{
log.debug("BaseDao findObjectById Class " + cls.getName() + " id " + id.toString());
Object obj = null;
try{
obj = sessionFactory.getCurrentSession().get(cls,id);
}catch(Exception e){
throw new DaoException("根据对象及ID查询记录异常,请联系管理员!",e);
}
}
/**
*
*
Description:根据实体返回一个集合
*
* @author Eric
* @param cls
* @return
* @throws DaoException
*/
@SuppressWarnings({"rawtypes"})
public List findAllData(Class cls) throws DaoException{
log.debug("BaseDao findAllData Class " + cls.getName());
List list = null;
try{
list = sessionFactory.getCurrentSession().createQuery(" from " + cls.getName() + "").list();
}catch(Exception e){
throw new DaoException("根据对象查询记录异常,请联系管理员!",e);
}
return list;
}
/**
*
*
Description:根据传入HQL语句返回一个集合(供DAO使用)
*
* @author Eric
* @param hql
* @return
* @throws DaoException
*/
@SuppressWarnings("rawtypes")
public List findHQLObject(String hql) throws DaoException{
try{
return sessionFactory.getCurrentSession().createQuery(hql).list();
}catch(Exception e){
throw new DaoException("根据传入条件语句查询记录异常,请联系管理员!");
}
}
/**
*
*
Description:按HQL提供者别名与条件查询集合
*
* @author Eric
* @param hqlProviderSet
* @param queryName
* @param paramMap
* @return
* @throws DaoException
*/
@SuppressWarnings("rawtypes")
public List findListByHqlName(IHqlProviderSet hqlProviderSet,String queryName,Map paramMap) throws DaoException{
String hql;
try{
hql = hqlProviderSet.getHqlByQryName(queryName);
Query query = sessionFactory.getCurrentSession().createQuery(hql);
if(paramMap != null){
hqlArgs(paramMap,query);