⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookhibernatedao.java

📁 在线图书管理系统,所有框架struts2,hibernate,spring 希望有所帮助!
💻 JAVA
字号:
/**
 * 
 */
package com.ascent.dao.hibernate;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.ascent.bean.Book;
import com.ascent.dao.IBookDAO;


public class BookHibernateDAO extends HibernateDaoSupport implements IBookDAO {

	private static final Logger LOGGER = LogManager.getLogger(BookHibernateDAO.class);
	
	private static final String LOAD_ALL = "from Book book order by book.bookId desc";

	private static final String LOAD_BY_AUTHOR = "from Book book where book.bookAuthor = ? order by book.bookId desc";

	private static final String LOAD_BY_NAME = "from Book book where book.bookName = ? order by book.bookId desc";

	public BookHibernateDAO() {
		super();
	}

	/**
	 * 
	 * @param book
	 * @return Book
	 * @todo Implement this com.ascent.dao.IBookDAO method
	 */
	public Book saveBook(Book book) {
		try {
			this.getHibernateTemplate().saveOrUpdate(book);
			LOGGER.debug("保存书籍成功!");
			return book;
		} catch (Exception ex) {
			LOGGER.error("保存图书失败!",ex);
			ex.printStackTrace();
			return null;
		}
	}

	/**
	 * 
	 * @param id
	 * @return Book
	 * @todo Implement this com.ascent.dao.IBookDAO method
	 */
	public Book getBook(Integer id) {
		LOGGER.debug("根据图书ID得到一个图书对象!");
		return (Book)this.getHibernateTemplate().get(Book.class,id);

	}

	/**
	 * @return List
	 * @todo Implement this com.ascent.dao.IBookDAO method
	 */
	public List findBookAll() {
		try{
			return this.getHibernateTemplate().find(LOAD_ALL);
		}catch(Exception ex){
			LOGGER.error("未能得到所有图书列表!",ex);
			ex.printStackTrace();
			return new ArrayList();
		}

	}

	/**
	 * 
	 * @param author
	 *            String
	 * @return List
	 * @todo Implement this com.ascent.dao.IBookDAO method
	 */
	public List findBookByAuthor(String author) {
		try{
			LOGGER.debug("按作者取得图书列表");
			return this.getHibernateTemplate().find(LOAD_BY_AUTHOR,author);
		}catch(Exception ex){
			LOGGER.error("未能按作者取得图书列表!");
			ex.printStackTrace();
			return new ArrayList();
		}

	}
	
	/**
	 * 
	 * @param author
	 *            String
	 * @return List
	 * @todo Implement this com.ascent.dao.IBookDAO method
	 */
	public List findBookByName(String name) {
		try{
			return this.getHibernateTemplate().find(LOAD_BY_NAME,name);
		}catch(Exception ex){
			LOGGER.error("未能按书名得到图书列表!");
			ex.printStackTrace();
			return new ArrayList();
		}

	}

	/**
	 * 
	 * @param book
	 *            Book
	 * @todo Implement this com.ascent.dao.IBookDAO method
	 */
	public void removeBook(Book book) {
	   LOGGER.debug("从数据库中删除指定图书");
       this.getHibernateTemplate().delete(book);
	}

	
}

⌨️ 快捷键说明

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