📄 productdaoimpl.java
字号:
package cn.com.tarena.ecport.dao.impl;
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.hibernate.criterion.Example;
import business.impl.test.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;
}
}
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;
}
}
public List 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) {
}
public void lock(Product instance) {
}
public List findAllProducts() throws ECPortException {
try {
Query queryObj = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("from Product");
List list = queryObj.list();
return list;
} catch (RuntimeException re) {
throw new ECPortException(re);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -