?? 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 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;
}
}
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 + -