categorydaoimpl.java

来自「Struts+Hibernate网络购物系统」· Java 代码 · 共 47 行

JAVA
47
字号
package com.netshop.domain.dao.hibernate;

import java.util.List;

import com.netshop.domain.dao.CategoryDao;
import com.netshop.domain.model.Category;
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 CategoryDAOImpl implements CategoryDao{

	private static Log log = LogFactory.getLog(CategoryDAOImpl.class);
	/* (non-Javadoc)
	 * @see org.digitstore.dao.CategoryDao#getCategory(java.lang.String)
	 */
	public Category getCategory(String categoryId) throws DataAccessException {
		// TODO Auto-generated method stub
		Session s = HibernateUtil.currentSession();
		try{
			HibernateUtil.beginTransaction();
			return (Category)s.load(Category.class,categoryId);
		}catch(HibernateException e){
			log.fatal(e);
		}
		return null;
	}
	/* (non-Javadoc)
	 * @see org.digitstore.dao.CategoryDao#getCategoryList()
	 */
	public List getCategoryList() throws DataAccessException {
		// TODO Auto-generated method stub
		try{
			Session s = HibernateUtil.currentSession();
			HibernateUtil.beginTransaction();
			String str = " from Category category ";
			Query query = s.createQuery(str);
			return query.list() ;
		}catch(HibernateException e){
			log.fatal(e);
		}
		return null;
	}
}

⌨️ 快捷键说明

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