📄 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 org.springframework.orm.hibernate3.HibernateTemplate;
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 {
private HibernateTemplate template;
public void setTemplate(HibernateTemplate template){
this.template = template;
}
public void save(Product transientInstance) {
try {
template.save(transientInstance);
} catch (RuntimeException re) {
throw re;
}
}
public void delete(Product persistentInstance) {
try {
template.delete(persistentInstance);
} catch (RuntimeException re) {
throw re;
}
}
public Product findById( java.lang.Long id) {
try {
Product instance = (Product) template.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;
// }
return null;
}
public List findByProperty(String propertyName, Object value) {
try {
String queryString = "from Product as model where model."
+ propertyName + "= ?";
return template.find(queryString,new Object[]{value});
} 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;
// }
return null;
}
public void saveOrUpdate(Product instance) {
}
public void lock(Product instance) {
}
public List findAllProducts() throws ECPortException {
try {
String query = "from Product";
List list = template.find(query);
return list;
} catch (RuntimeException re) {
throw new ECPortException(re);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -