⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foodinfodao.java

📁 实现网上订餐系统
💻 JAVA
字号:
package com.eatery.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.eatery.po.FoodInfo;

/**
 * Data access object (DAO) for domain model class FoodInfo.
 * @see com.eatery.po.FoodInfo
 * @author MyEclipse - Hibernate Tools
 */
public class FoodInfoDAO extends HibernateDaoSupport {

    private static final Log log = LogFactory.getLog(FoodInfoDAO.class);

	//property constants
	public static final String _FNAME = "FName";
	public static final String _FPRICE = "FPrice";
	public static final String _FFROM = "FFrom";
	public static final String _FIMAGE = "FImage";

	protected void initDao() {
		//do nothing
	}
    
    public void save(FoodInfo transientInstance) {
        log.debug("saving FoodInfo instance");
        try {
            getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(FoodInfo persistentInstance) {
        log.debug("deleting FoodInfo instance");
        try {
            getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public FoodInfo findById( java.lang.Integer id) {
        log.debug("getting FoodInfo instance with id: " + id);
        try {
            FoodInfo instance = (FoodInfo) getHibernateTemplate()
                    .get("com.eatery.po.FoodInfo", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(FoodInfo instance) {
        log.debug("finding FoodInfo 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 FoodInfo instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from FoodInfo 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 findByFName(Object FName) {
		return findByProperty(_FNAME, FName);
	}
	
	public List findByFPrice(Object FPrice) {
		return findByProperty(_FPRICE, FPrice);
	}
	
	public List findByFFrom(Object FFrom) {
		return findByProperty(_FFROM, FFrom);
	}
	
	public List findByFImage(Object FImage){
		return findByProperty(_FIMAGE, FImage);
	}
	
    public FoodInfo merge(FoodInfo detachedInstance) {
        log.debug("merging FoodInfo instance");
        try {
            FoodInfo result = (FoodInfo) getHibernateTemplate()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(FoodInfo instance) {
        log.debug("attaching dirty FoodInfo instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(FoodInfo instance) {
        log.debug("attaching clean FoodInfo instance");
        try {
            getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

	public static FoodInfoDAO getFromApplicationContext(ApplicationContext ctx) {
    	return (FoodInfoDAO) ctx.getBean("FoodInfoDAO");
	}
	
	public List findAllFood(){
		return getHibernateTemplate().find("FROM FoodInfo as food order by food.FDate desc");
	}
	
	public List findFoodsByEnterId(int enterId){
		String hql="FROM FoodInfo as food WHERE food.enterpriseInfo.EId=? order by food.FDate desc";
		return getHibernateTemplate().find(hql,enterId);
	}
	public List findFoodsByType(int typeId){
		String hql="FROM FoodInfo as food WHERE food.foodSmallType.fstId=? order by food.FDate desc";
		return getHibernateTemplate().find(hql,typeId);
	}
	
	public List findFoodsByTerm(String hql,List args){
		Object []obj=new Object[args.size()];
		for(int i=0;i<args.size();i++){
			obj[i]=args.get(i);
		}
		return getHibernateTemplate().find(hql, obj);
	}
	
	public List findFoodsByState(int fstate){
		String hql="FROM FoodInfo as food WHERE food.FState=? order by food.FDate desc";
		return getHibernateTemplate().find(hql,fstate);
	}
	
//	public static void main(String[] args) {
//		String []cfg={"WebRoot/WEB-INF/spring_hibernate.xml","WebRoot/WEB-INF/spring_dao.xml"};
//		ApplicationContext context=new FileSystemXmlApplicationContext(cfg);
//		FoodInfoDAO dao=(FoodInfoDAO) context.getBean("FoodInfoDAO");
//		String hql="FROM FoodInfo as food WHERE food.FName=?";
//		List args2=new ArrayList();
//		args2.add("火腿汉堡");
//		List list=dao.findAllFood();
//		for(int i=0;i<list.size();i++){
//			System.out.println("fsdfdsaf="+((FoodInfo)list.get(i)).getFName());
//		}
//	
//	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -