package com.green.dao; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.LockMode; import org.hibernate.Query; import org.springframework.context.ApplicationContext; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.transaction.annotation.Transactional; import com.green.vo.Orders; /** * A data access object (DAO) providing persistence and search support for * Orders 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.green.vo.Orders * @author MyEclipse Persistence Tools */ @Transactional public class OrdersDAO extends HibernateDaoSupport { private static final Log log = LogFactory.getLog(OrdersDAO.class); // property constants public static final String GIMAGE = "gimage"; public static final String GPRICE = "gprice"; public static final String GAMOUNT = "gamount"; public static final String GSTATES = "gstates"; public static final String TEL = "tel"; public static final String EMAIL = "email"; public static final String ORDERTIME = "ordertime"; public static final String MESSAGE = "message"; public static final String PAYWAY = "payway"; public static final String TOTALPRICE = "totalprice"; public static final String NAME = "name"; public static final String NUM = "num"; public static final String GNAME = "gname"; protected void initDao() { // do nothing } public void editorder(Orders orders) { String hql="update Orders set name=?,tel=?,email=?,gstates=?,message=?,gamount=? where id =?"; Query query=this.getSession().createQuery(hql); query.setParameter(0, orders.getName()); query.setParameter(1, orders.getTel()); query.setParameter(2, orders.getEmail()); query.setParameter(3, orders.getGstates()); query.setParameter(4, orders.getMessage()); query.setParameter(5, orders.getGamount()); query.setParameter(6, orders.getId()); query.executeUpdate(); } public void deleteorder(String ids) { String hql="delete from Orders where id in ("+ids+")"; Query query=this.getSession().createQuery(hql); query.executeUpdate(); } public void updateorder(String ids,String dowhat) { String hql="update Orders set gstates=? where id in ("+ids+")"; Query query=this.getSession().createQuery(hql); query.setParameter(0, dowhat); query.executeUpdate(); } public void cancelorder(String ids,String dowhat) { String hql="update Orders set gstates=? where id in ("+ids+")"; Query query=this.getSession().createQuery(hql); query.setParameter(0, dowhat); query.executeUpdate(); } public int gettotalCount() { String hql="select count(*) from Orders"; Query query=this.getSession().createQuery(hql); Integer it=(Integer)query.list().get(0); return it.intValue(); } public int gettotalPage(int totalCount,int prePage) { int totalPage=0; if(totalCount%prePage==0) { totalPage=totalCount/prePage; } else totalPage=totalCount/prePage+1; return totalPage; } public List getlistshowall(int currentPage,int prePage) { String hql="from Orders "; Query query=this.getSession().createQuery(hql); query.setFirstResult((currentPage-1)*prePage); query.setMaxResults(prePage); return query.list(); } public void save(Orders transientInstance) { log.debug("saving Orders instance"); try { getHibernateTemplate().save(transientInstance); log.debug("save successful"); } catch (RuntimeException re) { log.error("save failed", re); throw re; } } public void delete(Orders persistentInstance) { log.debug("deleting Orders instance"); try { getHibernateTemplate().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public Orders findById(java.lang.Long id) { log.debug("getting Orders instance with id: " + id); try { Orders instance = (Orders) getHibernateTemplate().get( "com.green.vo.Orders", id); return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } public List findByExample(Orders instance) { log.debug("finding Orders 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 Orders instance with property: " + propertyName + ", value: " + value); try { String queryString = "from Orders 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 findByGimage(Object gimage) { return findByProperty(GIMAGE, gimage); } public List findByGprice(Object gprice) { return findByProperty(GPRICE, gprice); } public List findByGamount(Object gamount) { return findByProperty(GAMOUNT, gamount); } public List findByGstates(Object gstates) { return findByProperty(GSTATES, gstates); } public List findByTel(Object tel) { return findByProperty(TEL, tel); } public List findByEmail(Object email) { return findByProperty(EMAIL, email); } public List findByOrdertime(Object ordertime) { return findByProperty(ORDERTIME, ordertime); } public List findByMessage(Object message) { return findByProperty(MESSAGE, message); } public List findByPayway(Object payway) { return findByProperty(PAYWAY, payway); } public List findByTotalprice(Object totalprice) { return findByProperty(TOTALPRICE, totalprice); } public List findByName(Object name) { return findByProperty(NAME, name); } public List findByNum(Object num) { return findByProperty(NUM, num); } public List findByGname(Object gname) { return findByProperty(GNAME, gname); } public List findAll() { log.debug("finding all Orders instances"); try { String queryString = "from Orders"; return getHibernateTemplate().find(queryString); } catch (RuntimeException re) { log.error("find all failed", re); throw re; } } public Orders merge(Orders detachedInstance) { log.debug("merging Orders instance"); try { Orders result = (Orders) getHibernateTemplate().merge( detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public void attachDirty(Orders instance) { log.debug("attaching dirty Orders instance"); try { getHibernateTemplate().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(Orders instance) { log.debug("attaching clean Orders instance"); try { getHibernateTemplate().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public static OrdersDAO getFromApplicationContext(ApplicationContext ctx) { return (OrdersDAO) ctx.getBean("OrdersDAO"); } }
最近下载更多
孤独的根号三 LV1
5月8日
微信网友_6508798513811456 LV5
2023年6月17日
ming_123_9715 LV23
2022年12月15日
2548143780 LV2
2022年12月1日
陈小小 LV3
2022年5月31日
17787885952 LV3
2022年5月5日
YYYUIDJIOJS LV1
2021年12月7日
ly010812 LV1
2021年11月24日
caodehao1 LV3
2021年11月16日
dyfvtsgf LV5
2021年6月28日
最近浏览更多
火心人 LV2
11月1日
微信网友_7208643230158848 LV2
10月13日
Peny_ZH LV5
9月20日
lyt010628 LV4
7月9日
阿九11111 LV4
5月14日
孤独的根号三 LV1
5月8日
pangzhihui LV14
4月17日
liiiyou LV1
1月27日
仙女山的月亮 LV2
2023年11月27日
微信网友_6567487389290496
2023年7月18日
暂无贡献等级