?? productdaoimpl.java
字號:
package com.netshop.domain.dao.hibernate;
import java.util.List;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.ListIterator;
import com.netshop.domain.dao.*;
import com.netshop.domain.model.Item;
import com.netshop.domain.model.Product;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;
import net.sf.hibernate.*;
import com.netshop.util.*;
public class ProductDAOImpl implements ProductDao{
private static Log log = LogFactory.getLog(ProductDAOImpl.class);
/* (non-Javadoc)
* @see org.digitstore.dao.ProductDao#getProduct(java.lang.String)
*/
public Product getProduct(String productId) throws DataAccessException {
// TODO Auto-generated method stub
Session s = HibernateUtil.currentSession();
try{
HibernateUtil.beginTransaction();
return (Product)s.load(Product.class,productId);
}catch(HibernateException e){
log.fatal(e);
}
return null;
}
/* (non-Javadoc)
* @see org.digitstore.dao.ProductDao#getProductListByCategory(java.lang.String)
*/
public List getProductListByCategory(String categoryId)
throws DataAccessException {
// TODO Auto-generated method stub
try{
Session s = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
String str = " from Product pro where pro.categoryId = '" + categoryId + "'";
Query query = s.createQuery(str);
HibernateUtil.commitTransaction();
return query.list() ;
}catch(HibernateException e){
log.fatal(e);
}
return null;
}
/* (non-Javadoc)
* @see org.digitstore.dao.ProductDao#searchProductList(java.lang.String)
*/
public List searchProductList(String keywords) throws DataAccessException {
// TODO Auto-generated method stub
try{
Session s = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
String str = this.getSearchSql(keywords);
Query query = s.createQuery(str);
return query.list() ;
}catch(HibernateException e){
log.fatal(e);
}
return new ArrayList();
}
public String getSearchSql(String keyword){
String key = "%" + keyword + "%";
StringBuffer buff = new StringBuffer();
buff.append("from Product p where ");
buff.append(" p.name like ");
buff.append(key);
buff.append(" or p.description like ");
buff.append(key);
return buff.toString();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -