TempDao文件

    xiaoxiao2021-03-25  124

    package com.qw.dao; import java.math.BigDecimal; import java.sql.SQLException; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.qw.entity.TEmp; /** * A data access object (DAO) providing persistence and search support for TEmp * 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.qw.entity.TEmp * @author MyEclipse Persistence Tools */ public class TEmpDAO extends HibernateDaoSupport { private static final Logger log = LoggerFactory.getLogger(TEmpDAO.class); // property constants public static final String _ELOGINNAME = "ELoginname"; public static final String _EPSW = "EPsw"; public static final String _EIMG = "EImg"; public static final String _ESEX = "ESex"; public static final String _EREMARK = "ERemark"; public static final String _ETRUENAME = "ETruename"; protected void initDao() { // do nothing } //添加 public void save(TEmp transientInstance) { log.debug("saving TEmp instance"); try { getHibernateTemplate().save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } //得到登录名字 public int getLoginName(String name){ List ar = getHibernateTemplate().find("from TEmp where ELoginname = ?",name); return ar.size(); } //登录查询 public List getLoginCount(final TEmp emp) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { List ar = session.createQuery(" from TEmp t where t.ELoginname = ? and t.EPsw =?").setString(0, emp.getELoginname()).setString(1, emp.getEPsw()).list(); return ar; } }); } //模糊查询(百度) public List getByNameLike(final String name){ return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { List ar = session.createQuery("from TEmp e inner join fetch e.TPart where e.ETruename like ?").setString(0,'%'+name+'%').list(); return ar; } }); } //查询一个 public List getIs(final int partId){ return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { return session.createQuery("from TEmp a where a.TPart.PId=?").setInteger(0, partId).list(); } }); } /** * 查询所有正常员工的数量 * @return */ public List getAllCount(){ return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { return session.createQuery("from TEmp a where a.EIs=1").list(); } }); } /** * 分页查询所有状态正常的员工 * @param begin * @param page * @return */ public List getAllPageTEmp(final int begin, final int page){ return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { return session.createQuery("from TEmp a inner join fetch a.TPart where a.EIs=1").setFirstResult((begin-1)*page).setMaxResults(page).list(); } }); } //分页查询## public List getAllEmpPage(final int begin,final int page,final int pis){ return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { List ar = session.createQuery("from TEmp e inner join fetch e.TPart where e.EIs=? order by e.EId desc").setInteger(0, pis).setFirstResult((begin-1)*page).setMaxResults(page).list(); return ar; } }); } //分页查询## public List getAllEmpPage1(final int begin,final int page){ return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { List ar = session.createQuery("from TEmp e inner join fetch e.TPart order by e.EId desc").setFirstResult((begin-1)*page).setMaxResults(page).list(); return ar; } }); } /** * 判断员工登陆名是否唯一 * @param name * @return */ public List getIsRepeat(final String name){ return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { return session.createQuery("from TEmp a where a.ELoginname=?").setString(0, name).list(); } }); } /** * 判断员工登陆名是否唯一 * @param name * @return */ public List gettiaojcx(final int begin,final int pages,final String name,final String sex,final String pid) { return this.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session arg0) throws HibernateException, SQLException { return arg0.createQuery("from TEmp e inner join fetch e.TPart p where e.ETruename like ? and e.ESex like ? " + "and p.PId like ? order by e.EId desc").setFirstResult((begin-1)*pages).setMaxResults(pages). setString(0,'%'+name+'%').setString(1, '%'+sex+'%').setString(2, '%'+pid+'%').list(); } }); } public void delete(TEmp persistentInstance) { log.debug("deleting TEmp instance"); try { getHibernateTemplate().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public TEmp findById(java.lang.Integer id) { log.debug("getting TEmp instance with id: " + id); try { TEmp instance = (TEmp) getHibernateTemplate().get( "com.qw.entity.TEmp", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } public List findByExample(TEmp instance) { log.debug("finding TEmp 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 TEmp instance with property: " + propertyName + ", value: " + value); try { String queryString = "from TEmp 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 findByELoginname(Object ELoginname) { return findByProperty(_ELOGINNAME, ELoginname); } public List findByEPsw(Object EPsw) { return findByProperty(_EPSW, EPsw); } public List findByEImg(Object EImg) { return findByProperty(_EIMG, EImg); } public List findByESex(Object ESex) { return findByProperty(_ESEX, ESex); } public List findByERemark(Object ERemark) { return findByProperty(_EREMARK, ERemark); } public List findByETruename(Object ETruename) { return findByProperty(_ETRUENAME, ETruename); } //查全部 public List findAll() { log.debug("finding all TEmp instances"); try { String queryString = "from TEmp"; return getHibernateTemplate().find(queryString); } catch (RuntimeException re) { log.error("find all failed", re); throw re; } } public TEmp merge(TEmp detachedInstance) { log.debug("merging TEmp instance"); try { TEmp result = (TEmp) getHibernateTemplate().merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public void attachDirty(TEmp instance) { log.debug("attaching dirty TEmp instance"); try { getHibernateTemplate().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } //修改 public void attachClean(TEmp instance) { log.debug("attaching clean TEmp instance"); try { getHibernateTemplate().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public static TEmpDAO getFromApplicationContext(ApplicationContext ctx) { return (TEmpDAO) ctx.getBean("TEmpDAO"); } public int getCount(int pis) { List ar = getHibernateTemplate().find("from TEmp e inner join fetch e.TPart where e.EIs=?",pis); return ar.size(); } }
    转载请注明原文地址: https://ju.6miu.com/read-8324.html

    最新回复(0)