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

📄 productdaoimpl.java

📁 本系统是网上购物的详细代码
💻 JAVA
字号:
package cn.com.tarena.ecport.dao.impl;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import cn.com.tarena.ecport.common.util.HibernateUtil;
import cn.com.tarena.ecport.dao.IProductDAO;
import cn.com.tarena.ecport.exception.ECPortException;
import cn.com.tarena.ecport.pojo.Product;

public class ProductDAOImpl implements IProductDAO {

	public void save(Product transientInstance) {
		try {
			HibernateUtil.getSessionFactory().getCurrentSession().save(transientInstance);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(Product persistentInstance) {
		try {
			HibernateUtil.getSessionFactory().getCurrentSession().delete(persistentInstance);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Product findById(java.lang.Long id) {
		try {
			Product instance = (Product) HibernateUtil.getSessionFactory().getCurrentSession().get(Product.class, id);
			return instance;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List findByExample(Product instance) {
		try {
			List results = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria("Product").add(
							Example.create(instance)).list();
			return results;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Product> findByProperty(String propertyName, Object value) {
		try {
			String queryString = "from Product as model where model."+ propertyName + "= ?";
			Query queryObject = HibernateUtil.getSessionFactory().getCurrentSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public Product merge(Product detachedInstance) {
		try {
			Product result = (Product) HibernateUtil.getSessionFactory().getCurrentSession().merge(detachedInstance);
			return result;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void saveOrUpdate(Product instance) {
		try {
			HibernateUtil.getSessionFactory().getCurrentSession().saveOrUpdate(instance);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void lock(Product instance) {
		try {
			HibernateUtil.getSessionFactory().getCurrentSession().lock(instance, LockMode.READ);
		} catch (RuntimeException e) {
			throw e;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Product> findAllProducts() throws ECPortException {
		try {
			Query queryObj = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("from Product as p order by p.productid asc");
			List<Product> list = queryObj.list();

			return list;
		} catch (RuntimeException re) {

			throw new ECPortException(re);
		}
	}
}

⌨️ 快捷键说明

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