rightsdaoimpl.java
来自「基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰」· Java 代码 · 共 183 行
JAVA
183 行
package com.yuanchung.sales.dao.admin;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.yuanchung.sales.exception.IllegalParameterException;
import com.yuanchung.sales.exception.SystemException;
import com.yuanchung.sales.model.admin.Rights;
import com.yuanchung.sales.model.admin.position.PositionRights;
import com.yuanchung.sales.util.Constants;
/**
* A data access object (DAO) providing persistence and search support for
* Rights entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see com.yuanchung.sales.model.admin.Rights
* @author MyEclipse Persistence Tools
*/
public class RightsDAOImpl extends HibernateDaoSupport implements RightsDAO {
private static final Log log = LogFactory.getLog(RightsDAOImpl.class);
// property constants
public static final String RIGHTS_NAME = "rightsName";
public static final String PARENT_ID = "parentId";
protected void initDao() {
// do nothing
}
public void save(Rights transientInstance) throws SystemException {
log.debug("saving Rights instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Rights persistentInstance) throws SystemException {
log.debug("deleting Rights instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Rights findById(java.lang.Integer id) throws SystemException {
log.debug("getting Rights instance with id: " + id);
try {
Rights instance = (Rights) getHibernateTemplate().get(
"com.yuanchung.sales.model.admin.Rights", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Rights instance) throws SystemException {
log.debug("finding Rights instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value)
throws SystemException {
log.debug("finding Rights instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Rights as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value, String where) {
String queryString = "from Rights as model where model." + propertyName
+ " " + where + " ?";
return getHibernateTemplate().find(queryString, value);
}
public List findByRightsName(Object rightsName) throws SystemException {
return findByProperty(RIGHTS_NAME, rightsName);
}
public List findByParentId(Object parentId) throws SystemException {
return findByProperty(PARENT_ID, parentId);
}
public List findAll() throws SystemException {
log.debug("finding all Rights instances");
try {
String queryString = "from Rights";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Rights merge(Rights detachedInstance) throws SystemException {
log.debug("merging Rights instance");
try {
Rights result = (Rights) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Rights instance) throws SystemException {
log.debug("attaching dirty Rights instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Rights instance) throws SystemException {
log.debug("attaching clean Rights instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static RightsDAOImpl getFromApplicationContext(ApplicationContext ctx) {
return (RightsDAOImpl) ctx.getBean("RightsDAO");
}
/**
*
*/
public List findByIds(List idList) {
if (idList.size() > 0) {
StringBuffer hql = new StringBuffer("");
hql.append("from Rights as model where model.id in (");
for (int i = 0; i < idList.size(); i++) {
if (i != (idList.size() - 1)) {
hql.append(idList.get(i).toString() + ",");
} else {
hql.append(idList.get(i).toString() + ")");
}
}
hql.append(" order by model.parentId");
return getHibernateTemplate().find(hql.toString());
}else{
return null;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?