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

📄 tblogtypedao.java

📁 持久层hibernate技术使用的一个例子
💻 JAVA
字号:
package cn.hope.mana.pojo.dao;

import java.util.List;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;

import org.apache.log4j.Logger;

import cn.hope.mana.pojo.TBlog;
import cn.hope.mana.pojo.TBlogtype;
import cn.hope.mana.pojo.base.BaseTBlogtypeDAO;


public class TBlogtypeDAO extends BaseTBlogtypeDAO {
	Logger log = Logger.getLogger(TBlogtypeDAO.class.getName());
	
	/**
	 * Default constructor.  Can be used in place of getInstance()
	 */
	public TBlogtypeDAO () {}

	/**
	 * 查询数据方法
	 * 
	 * @param  
	 * @return list
	 * @throws HibernateException
	 */
	public List search() throws HibernateException {
		String sql = "select tBlogtype from TBlogtype tBlogtype where tBlogtype.flag='0'";
		try {			
			initialize();
			return this.getSession().find(sql);			
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	
	/**
	 * 键查询数据方法
	 * 
	 * @param  dId 
	 * @return TBlogtype
	 * @throws HibernateException
	 */
	public TBlogtype search(Integer bId) throws HibernateException {
		try {			
			initialize();
			return this.load(bId);			
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 值查询数据方法
	 * 
	 * @param  dName 
	 * @return count
	 * @throws HibernateException
	 */
	public int search(String tTitle) throws HibernateException {
		String sqlCnt = "select count(tBlogtype.TTypeid) from TBlogtype tBlogtype where tBlogtype.flag='0' and tBlogtype.TTitle='"
			+tTitle+"'";
		try {
			initialize();
			Query queryCnt = this.getSession().createQuery(sqlCnt);
			return ((Integer)queryCnt.uniqueResult()).intValue();
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 添加数据方法
	 * 
	 * @param  tBlogtype 
	 * @return 
	 * @throws HibernateException
	 */
	public void insert(TBlogtype tBlogtype) throws HibernateException {
		try{
			initialize();
			this.save(tBlogtype);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 删除数据方法
	 * 
	 * @param  tBlogtype 
	 * @return 
	 * @throws HibernateException
	 */
	public void delete(TBlogtype tBlogtype) throws HibernateException {
		try{
			initialize();
			this.update(tBlogtype);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 修改数据方法
	 * 
	 * @param  tBlogtype 
	 * @return 
	 * @throws HibernateException
	 */
	public void update(TBlogtype tBlogtype) throws HibernateException {
		try{
			initialize();
			super.update(tBlogtype);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 修改blog数据方法
	 * 
	 * @param  tBlog
	 * @return 
	 * @throws HibernateException
	 */
	public void update(TBlog tBlog) throws HibernateException {
		try{
			initialize();
			new TBlogDAO().update(tBlog);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * blog分类查询blog数据方法
	 * 
	 * @param  tBlogtype 
	 * @return List
	 * @throws HibernateException
	 */
	public List searchBlog(Integer bId) throws HibernateException {
		String sql = "select tBlog from TBlog tBlog where tBlog.flag='0' and tBlog.TBlogtype.TTypeid="
			+bId;
		try {
			initialize();
			return this.getSession().find(sql);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
}

⌨️ 快捷键说明

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