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

📄 sblogtypedao.java

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




import java.util.List;

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

import org.apache.log4j.Logger;

import cn.hope.front.pojo.SBlogtype;
import cn.hope.front.pojo.base.BaseSBlogtypeDAO;



public class SBlogtypeDAO extends BaseSBlogtypeDAO {
	Logger log = Logger.getLogger(TFileDAO.class.getName());
	/**
	 * Default constructor.  Can be used in place of getInstance()
	 */
	public SBlogtypeDAO () {}
	
	/**
	 * 查找所有类型
	 */
	/*
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SBlogtypeDAO sb=new SBlogtypeDAO();
		try {
			sb.searchBlogtype();
			System.out.println(sb);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	*/
	public List searchBlogtype(Integer sbId) throws HibernateException {
		List list=null;
		String sqlStr = "select sblogtype from SBlogtype sblogtype where sblogtype.flag='0' ";
		try {
			initialize();
		    list= this.getSession().find(sqlStr);

		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
		return list;
	}
	
	public SBlogtype load(Integer stId) throws HibernateException {
		
		try {
			initialize();
			return super.load(stId);
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 添加数据方法
	 * 
	 * @param  MHtype
	 * @return int
	 * @throws HibernateException
	 */
	public Integer insert(SBlogtype sblogtype) throws HibernateException {
		
		try {
			initialize();
			if (searchByName(sblogtype) == null){
				this.save(sblogtype);
			}
			return searchByName(sblogtype);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	public Integer searchByName(SBlogtype sblogtype) throws HibernateException {
		String sqlKey = "select sblogtype.stId from SBlogtype sblogtype where sblogtype.flag='0' and sblogtype.stTitle='"
			+sblogtype.getStTitle()+"'";
		try {
			initialize();			
			Query queryCnt = this.getSession().createQuery(
					sqlKey.toString());
			Integer i = (Integer)queryCnt.uniqueResult();			
			return i;
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}	
}

⌨️ 快捷键说明

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