📄 menuinfodao.java
字号:
package com.woyi.dao;
// default package
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.MenuInfo;
/**
* Data access object (DAO) for domain model class MenuInfo.
* @see .MenuInfo
* @author MyEclipse Persistence Tools
*/
public class MenuInfoDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(MenuInfoDAO.class);
//property constants
public static final String MENUID = "menuid";
public static final String MENUNAME = "menuname";
public static final String MENUACTION = "menuaction";
public static final String MENUVIEW = "menuview";
public static final String PARENTMENUID = "parentmenuid";
public static final String ISLEAF = "isleaf";
public static final String MENULEVEL = "menulevel";
public static final String DISPLAYORDER = "displayorder";
protected void initDao() {
//do nothing
}
public void save(MenuInfo transientInstance) {
log.debug("saving MenuInfo instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(MenuInfo persistentInstance) {
log.debug("deleting MenuInfo instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public MenuInfo findById( java.lang.Integer id) {
log.debug("getting MenuInfo instance with id: " + id);
try {
MenuInfo instance = (MenuInfo) getHibernateTemplate()
.get("MenuInfo", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(MenuInfo instance) {
log.debug("finding MenuInfo 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 MenuInfo instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from MenuInfo 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 findByMenuid(Object menuid) {
return findByProperty(MENUID, menuid);
}
public List findByMenuname(Object menuname) {
return findByProperty(MENUNAME, menuname);
}
public List findByMenuaction(Object menuaction) {
return findByProperty(MENUACTION, menuaction);
}
public List findByMenuview(Object menuview) {
return findByProperty(MENUVIEW, menuview);
}
public List findByParentmenuid(Object parentmenuid) {
return findByProperty(PARENTMENUID, parentmenuid);
}
public List findByIsleaf(Object isleaf) {
return findByProperty(ISLEAF, isleaf);
}
public List findByMenulevel(Object menulevel) {
return findByProperty(MENULEVEL, menulevel);
}
public List findByDisplayorder(Object displayorder) {
return findByProperty(DISPLAYORDER, displayorder);
}
public List findAll() {
log.debug("finding all MenuInfo instances");
try {
String queryString = "from MenuInfo";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public MenuInfo merge(MenuInfo detachedInstance) {
log.debug("merging MenuInfo instance");
try {
MenuInfo result = (MenuInfo) getHibernateTemplate()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(MenuInfo instance) {
log.debug("attaching dirty MenuInfo instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(MenuInfo instance) {
log.debug("attaching clean MenuInfo instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static MenuInfoDAO getFromApplicationContext(ApplicationContext ctx) {
return (MenuInfoDAO) ctx.getBean("MenuInfoDAO");
}
/**
* 获取菜单
* @param propertyName
* @param value
* @return
*/
public List fetchMenu(String roleid) {
log.debug("finding Optrinfo instance with property: " + roleid
);
try {
String queryString = "from MenuInfo as b where b.menuid in (select menuid from RolemenurelDao as a where a.roleid='"
+ roleid + "') order by b.menuid,b.displayorder";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
/**
* 获取菜单
* @param propertyName
* @param value
* @return
*/
public List fetchNoMenu(String roleid) {
log.debug("finding Optrinfo instance with property: " + roleid
);
try {
// String queryString = "from MenuInfo as a where a.menuid in (select menuid from MenuInfo b where not exists (select 1 from RolemenurelDao as c where c.menuid=b.menuid and c.roleid='"
// + roleid + "')) or a.parentmenuid in (select IFNULL(d.parentmenuid,'') parentmenuid from MenuInfo d where not exists (select 1 from RolemenurelDao e where e.menuid = d.menuid and e.roleid ='"+roleid+"')) order by a.menuid,a.displayorder";
String queryString = "from MenuInfo as a where a.menuid in (select menuid from MenuInfo b where not exists (select 1 from RolemenurelDao as c where c.menuid=b.menuid and c.roleid='"+roleid+"')) or exists (select 1 from MenuInfo d where d.parentmenuid=a.menuid and not exists (select 1 from RolemenurelDao as e where e.menuid=d.menuid and e.roleid='"+roleid+"' )) order by a.menuid,a.displayorder";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -