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

📄 shopcartdao.java

📁 struts1 hibernate3 电子购物商城源码 加上了ANT编译.
💻 JAVA
字号:
package dream.ourshopping.persistence;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;

import dream.ourshopping.domain.Shopcart;

/**
 * Data access object (DAO) for domain model class Shopcart.
 * 
 * @see com.study.hibernate.Shopcart
 * @author MyEclipse - Hibernate Tools
 */
public class ShopcartDAO extends BaseHibernateDAO {

	private static Logger log = Logger.getLogger(ShopcartDAO.class.getName());

	// property constants
	public static final String USERID = "userid";

	public static final String PRODUCTID = "productid";

	public static final String COUNT = "count";

	public static final String PRICE = "price";

	public void save(Shopcart transientInstance) {
		log.debug("saving Shopcart instance");
		try {
			Transaction ts = getSession().beginTransaction();
			getSession().save(transientInstance);
			ts.commit();
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public int delete(Integer id) {
		log.debug("deleting Shopcart instance");
		try {
			String queryString = "delete Shopcart as model where model.id=?";
		Query queryObject = getSession().createQuery(queryString);
		queryObject.setParameter(0, id);
		return queryObject.executeUpdate();
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public int deleteByUserid(Integer id) {
		log.debug("deleting Shopcart instance");
		try {
			String queryString = "delete Shopcart as model where model.member.id=?";
		Query queryObject = getSession().createQuery(queryString);
		queryObject.setParameter(0, id);
		return queryObject.executeUpdate();
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Shopcart findById(java.lang.Integer id) {
		log.debug("getting Shopcart instance with id: " + id);
		try {
			Shopcart instance = (Shopcart) getSession().get(
					"dream.ourshopping.domain.Shopcart", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findMaxId() {
		log.debug("getting Sort instance All: ");
		try {

			Query q = getSession().createQuery("select max(id) from Shopcart ");
			List instance = q.list();
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Shopcart instance) {
		log.debug("finding Shopcart instance by example");
		try {
			List results = getSession().createCriteria(
					"dream.ourshopping.domain.Shopcart").add(
					Example.create(instance)).list();
			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 Shopcart instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Shopcart as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserid(Object userid) {
		log.debug("getting Shopcart instance with id: " + userid);
		try {
			Query q = getSession().createQuery(
					"from Shopcart p where p.member.id=" + userid);
			List instance = q.list();
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByProductid(Object productid) {
		return findByProperty(PRODUCTID, productid);
	}

	public List findByCount(Object count) {
		return findByProperty(COUNT, count);
	}

	public List findByPrice(Object price) {
		return findByProperty(PRICE, price);
	}

	public Shopcart merge(Shopcart detachedInstance) {
		log.debug("merging Shopcart instance");
		try {
			Shopcart result = (Shopcart) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Shopcart instance) {
		log.debug("attaching dirty Shopcart instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

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

⌨️ 快捷键说明

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