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

📄 foodinfodao.java

📁 SSH 开发网上订餐系统。由于SSH相关包太大不方便上传。请自行导入。
💻 JAVA
字号:
package com.web.model;

import java.sql.SQLException;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.web.modelIntef.FoodInfoDAO_Intef;

/**
 * A data access object (DAO) providing persistence and search support for
 * FoodInfo 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.web.model.FoodInfo
 * @author MyEclipse Persistence Tools
 */

public class FoodInfoDAO extends HibernateDaoSupport implements FoodInfoDAO_Intef{
	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 _FSMALLIMAGE = "FSmallimage";
	public static final String _FLARGEIMAGE = "FLargeimage";
	public static final String _FSTATE = "FState";
	public static final String _FTOTAL = "FTotal";
	public static final String _FMEMO = "FMemo";

	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.String id) {
		log.debug("getting FoodInfo instance with id: " + id);
		try {
			FoodInfo instance = (FoodInfo) getHibernateTemplate().get(
					"com.web.model.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 findByFSmallimage(Object FSmallimage) {
		return findByProperty(_FSMALLIMAGE, FSmallimage);
	}

	public List findByFLargeimage(Object FLargeimage) {
		return findByProperty(_FLARGEIMAGE, FLargeimage);
	}

	public List findByFState(Object FState) {
		return findByProperty(_FSTATE, FState);
	}

	public List findByFTotal(Object FTotal) {
		return findByProperty(_FTOTAL, FTotal);
	}

	public List findByFMemo(Object FMemo) {
		return findByProperty(_FMEMO, FMemo);
	}

	public List findAll() {
		log.debug("finding all FoodInfo instances");
		try {
			String queryString = "from FoodInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	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 getListForPage(final String hql, final int offset,
			 final int length) {

			List list = getHibernateTemplate().executeFind(new HibernateCallback() {
			 public Object doInHibernate(Session session)
			 throws HibernateException, SQLException {
			 Query query = session.createQuery(hql);
			 query.setFirstResult(offset);
			 query.setMaxResults(length);
			 List list = query.list();
			 return list;
			 }
			});
			return list;
			}
	public void updata(FoodInfo instance) {
		log.debug("attaching clean FoodInfo instance");
		try {
			getHibernateTemplate().update(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}

⌨️ 快捷键说明

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