📄 roledao.java
字号:
package com.woyi.dao;
// default package
import java.util.Date;
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.woyi.dto.Organization;
import com.woyi.dto.Role;
import com.woyi.dto.Sequence;
import com.woyi.page.PageInfo;
import com.woyi.page.Pagination;
/**
* Data access object (DAO) for domain model class Role.
*
* @see .Role
* @author MyEclipse Persistence Tools
*/
public class RoleDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(RoleDAO.class);
// property constants
public static final String ROLEINFO_NAME = "roleinfoName";
public static final String ROLEID = "roleid";
public static final String ROLENAME = "rolename";
public static final String VALIDFLAG = "validflag";
public static final String ROLEDESC = "roledesc";
public static final String OPTRID = "optrid";
public static final String REMARK = "remark";
public static final int pagesize = 10;
public Pagination pagination;
public SequenceDAO sequenceDAO;
protected void initDao() {
// do nothing
}
public void save(Role transientInstance) {
log.debug("saving Role instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public boolean delete(Role persistentInstance) {
log.debug("deleting Role instance");
boolean isFlag=false;
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
isFlag=true;
return isFlag;
} catch (RuntimeException re) {
log.error("delete failed", re);
return isFlag;
}
}
public Role findById(java.lang.Integer id) {
log.debug("getting Role instance with id: " + id);
Role pageInfo;
try {
String queryString = "from Role as b where b.roleinfoId ="
+ id ;
List departList = getHibernateTemplate().find(queryString);
pageInfo=(Role) departList.get(0);
return pageInfo;
} catch (RuntimeException re) {
log.error("find by property name failed", re);
System.out.println("=====:"+re);
throw re;
}
}
public List findByExample(Role instance) {
log.debug("finding Role 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) {
log.debug("finding Role instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Role 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 findByRoleinfoName(Object roleinfoName) {
return findByProperty(ROLEINFO_NAME, roleinfoName);
}
public List findByRoleid(Object roleid) {
return findByProperty(ROLEID, roleid);
}
public List findByRolename(Object rolename) {
return findByProperty(ROLENAME, rolename);
}
public List findByValidflag(Object validflag) {
return findByProperty(VALIDFLAG, validflag);
}
public List findByRoledesc(Object roledesc) {
return findByProperty(ROLEDESC, roledesc);
}
public List findByOptrid(Object optrid) {
return findByProperty(OPTRID, optrid);
}
public List findByRemark(Object remark) {
return findByProperty(REMARK, remark);
}
public List findAll() {
log.debug("finding all Role instances");
try {
String queryString = "from Role as b where b.validflag='1'";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Role merge(Role detachedInstance) {
log.debug("merging Role instance");
try {
Role result = (Role) getHibernateTemplate().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public boolean attachDirty(Role instance) {
log.debug("attaching dirty Role instance");
boolean isflag = false;
try {
getHibernateTemplate().saveOrUpdate(instance);
isflag = true;
log.debug("attach successful");
return isflag;
} catch (RuntimeException re) {
log.error("attach failed", re);
return isflag;
}
}
public void attachClean(Role instance) {
log.debug("attaching clean Role instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static RoleDAO getFromApplicationContext(ApplicationContext ctx) {
return (RoleDAO) ctx.getBean("RoleDAO");
}
/**
* 获取角色信息
* @param value
* @return
*/
public PageInfo fetchRole(String rolename,String validflag,int pageNo) {
log.debug("finding Optrinfo instance with property: " + rolename
);
try {
String queryString = "from Role as b where b.rolename like '%"
+ rolename + "%' and validflag='"+validflag+"' order by b.rolename";
String count = "select count(*) from Role as b where b.rolename like '%"
+ rolename + "%' and validflag='"+validflag+"' order by b.rolename";
PageInfo pageInfo = pagination.page(pageNo, pagesize, queryString, count);
return pageInfo;
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
/**
* 获取单个角色信息
* @param value
* @return
*/
public Role fetchRole(String roleid) {
log.debug("finding Optrinfo instance with property: " + roleid
);
Role pageInfo;
try {
String queryString = "from Role as b where b.roleinfoId ='"
+ roleid + "'";
List departList = getHibernateTemplate().find(queryString);
pageInfo=(Role) departList.get(0);
return pageInfo;
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public Pagination getPagination() {
return pagination;
}
public void setPagination(Pagination pagination) {
this.pagination = pagination;
}
public SequenceDAO getSequenceDAO() {
return sequenceDAO;
}
public void setSequenceDAO(SequenceDAO sequenceDAO) {
this.sequenceDAO = sequenceDAO;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -