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

📄 bbsinfomanagedaospringhibernateimple.java

📁 hibernate项目实践
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.px1987.webbbs.dao;
import java.util.*;
import com.px1987.webbbs.exception.WebBBSException;
import org.hibernate.*;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.dao.DataAccessException;
public class BBSInfoManageDAOSpringHibernateImple extends HibernateDaoSupport  implements BBSInfoManageDAOInterface 
{

	public BBSInfoManageDAOSpringHibernateImple() 
	{
		// TODO 自动生成构造函数存根
	}

	public boolean deleteOneBBSInfo(int bbsID) throws WebBBSException 
	{
		boolean OKOrNot=false;
		Session session=null;
		Transaction tx=null;
		try
		{
			session =this.getSession();
			tx = session.beginTransaction();
			BBSInfoPO oneBBSPOTODeleted=(BBSInfoPO)session.get(BBSInfoPO.class,new Integer(bbsID));
			if(oneBBSPOTODeleted==null)
			{
				throw new WebBBSException("在数据库表中不存在指定bbsID="+bbsID+"的数据顶目!");
			}
			session.delete(oneBBSPOTODeleted);
			tx.commit();
			OKOrNot=true;
		}
		catch (DataAccessException he)
		{
			throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的DeleteOneBBSInfo方法出现了HibernateException异常");
		}		
		return OKOrNot;
	}
	public boolean deleteOneRoleInfo(int roleID) throws WebBBSException 
	{
		boolean OKOrNot=false;
		Session session=null;
		Transaction tx=null;
		try
		{
			session =this.getSession();
			tx = session.beginTransaction();
			RoleInfoPO oneRoleInfoPOTODeleted=(RoleInfoPO)session.get(RoleInfoPO.class,new Integer(roleID));
			if(oneRoleInfoPOTODeleted==null)
			{
				throw new WebBBSException("在数据库表中不存在指定bbsID="+roleID+"的数据顶目!");
			}
			session.delete(oneRoleInfoPOTODeleted);
			tx.commit();
			OKOrNot=true;
		}
		catch (DataAccessException he)
		{
			throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的DeleteOneRoleInfo方法出现了HibernateException异常");
		}		
		return OKOrNot;
	}
	public boolean insertBBSInfo(BBSInfoPO oneBBSInfoPO) throws WebBBSException 
	{
		  boolean OKOrNot=false;
		  Session session=null;
		  Transaction tx=null;
		  try
		  {
		    session =this.getSession();
		    tx = session.beginTransaction();
		    session.save(oneBBSInfoPO);
		    tx.commit();
		    OKOrNot=true;
		  }
		  catch (DataAccessException he)
		  {
		    throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的insertOneUserInfo方法出现了HibernateException异常");
		  }		
		  return OKOrNot;
	}
	public boolean insertRoleInfo(RoleInfoPO oneRoleInfoPO)	throws WebBBSException 
	{
		  boolean OKOrNot=false;
		  Session session=null;
		  Transaction tx=null;
		  try
		  {
		    session =this.getSession();
		    tx = session.beginTransaction();
		    session.save(oneRoleInfoPO);
		    tx.commit();
		    OKOrNot=true;
		  }
		  catch (DataAccessException he)
		  {
		    throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的insertRoleInfoInfo方法出现了HibernateException异常");
		  }		
		  return OKOrNot;
	}
	public ArrayList pageSelectDBData(String hqlSelect, int firstResult,int maxResults) throws WebBBSException 
	{
	    List selectResult = null;
	    ArrayList allBBSInfoPO = new ArrayList();
	    Session session = null;
	    Transaction tx = null;
	    Query query =null;
	    try
	    {
	      session = this.getSession();

	      tx = session.beginTransaction();
	      query = session.createQuery(hqlSelect);
	      query.setCacheable(true);      //激活查询缓存
	      query.setFirstResult(firstResult);    //设置希望开始的行数---开始的行号从0 计数
	      query.setMaxResults(maxResults);      //设置希望返回的最大行数
	      selectResult=query.list();
	      Iterator allBBSInfoPOItem=selectResult.iterator();
	      	 while(allBBSInfoPOItem.hasNext())
	      	 {
	      		BBSInfoPO oneBBSInfoPO=(BBSInfoPO)allBBSInfoPOItem.next();
	      		allBBSInfoPO.add(oneBBSInfoPO);
	      	 }
	      tx.commit();
	    }
	    catch (DataAccessException he)
	    {
		    throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的pageSelectDBData方法出现了HibernateException异常");	    
		}	
	    return allBBSInfoPO;
	}
	public ArrayList selectSomeBBSInfo(String HQLSelect) throws    WebBBSException
	{
	    List selectResult = null;
	    ArrayList allBBSInfoPO = new ArrayList();
	    Session session = null;
	    Transaction tx = null;
	    Query query =null;
	    try
	    {
	      session =this.getSession();

	      tx = session.beginTransaction();
	      query = session.createQuery(HQLSelect);
	      query.setCacheable(true);      //激活查询缓存
	      selectResult=query.list();
	      Iterator allBBSInfoPOItem=selectResult.iterator();
	      	 while(allBBSInfoPOItem.hasNext())
	      	 {
	      		BBSInfoPO oneBBSInfoPO=(BBSInfoPO)allBBSInfoPOItem.next();
	      		allBBSInfoPO.add(oneBBSInfoPO);
	      	 }
	      tx.commit();
	    }
	    catch (DataAccessException he)
	    {
		    throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的selectBBSInfoByBBSAuthor方法出现了HibernateException异常");	    
		}	  
	    return allBBSInfoPO;		
	}
	public ArrayList selectBBSInfoByBBSAuthor(String authorName)	throws WebBBSException 
	{
		String HQLQuery="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc where oneBBSInfoPO.author='"+authorName+"'";
		return selectSomeBBSInfo(HQLQuery);
	}

	public ArrayList selectBBSInfoByBBSHits(int bbsHitsCounte)	throws WebBBSException 
	{
		String HQLQuery="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO where oneBBSInfoPO.hits="+bbsHitsCounte;
		return selectSomeBBSInfo(HQLQuery);
	}

	public ArrayList selectBBSInfoByBBSHits(int firstResult, int maxResults)	throws WebBBSException 
	{
		String hqlSelect="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc";
		return pageSelectDBData(hqlSelect, firstResult,maxResults);
	}

	public ArrayList selectBBSInfoByBBSHits() throws WebBBSException 
	{
		String HQLQuery="from com.px1987.webbbs.dao.BBSInfoPO as oneBBSInfoPO order by oneBBSInfoPO.hits desc";
		return selectSomeBBSInfo(HQLQuery);
	}
	ArrayList allBbsReplyInfosByOneBBS=null;
	public ArrayList getAllBbsReplyInfosByOneBBS() 
	{
		return allBbsReplyInfosByOneBBS;
	}
	public BBSInfoPO selectBBSInfoByBBSID(int bbsID) throws WebBBSException 
	{
		BBSInfoPO oneBBSInfoPO=null;
		Session session=null;
		Transaction tx=null;
		try
		{
			session = this.getSession();
			tx = session.beginTransaction();

			oneBBSInfoPO = (BBSInfoPO) session.get(BBSInfoPO.class, new Integer(bbsID));
			if(oneBBSInfoPO==null)
			{
				throw new WebBBSException("在数据库表中不存在指定bbsID="+bbsID+"的数据顶目!");
			}

⌨️ 快捷键说明

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