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

📄 bbstitleinfomanagedaospringhibernateimple.java

📁 hibernate项目实践
💻 JAVA
字号:
package com.px1987.webbbs.dao;
import java.util.*;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.px1987.webbbs.exception.WebBBSException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.dao.DataAccessException;
public class BBSTitleInfoManageDAOSpringHibernateImple extends HibernateDaoSupport  implements
		BBSTitleInfoManageDAOInterface 
{

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

	public boolean deleteOneBBSTitleInfo(int bbsTitleID) throws WebBBSException 
	{
		boolean OKOrNot=false;
		Session session=null;
		Transaction tx=null;
		try
		{
			session =this.getSession();
			tx = session.beginTransaction();
			BBSTitleInfoPO oneBBSTitlePOTODeleted=(BBSTitleInfoPO)session.get(BBSTitleInfoPO.class,new Integer(bbsTitleID));
			if(oneBBSTitlePOTODeleted==null)
			{
				throw new WebBBSException("在数据库表中不存在指定bbsTitleID="+bbsTitleID+"的数据顶目!");
			}
			session.delete(oneBBSTitlePOTODeleted);
			tx.commit();
			OKOrNot=true;
		}
		catch (DataAccessException he)
		{
			throw new WebBBSException("在BBSTitleInfoManageDAOHibernateImple类中的deleteOneBBSTitleInfo方法出现了HibernateException异常");
		}	
		return OKOrNot;
	}

	public boolean insertBBSTitleInfo(BBSTitleInfoPO oneBBSTitleInfo)	throws WebBBSException 
	{
		  boolean OKOrNot=false;
		  Session session=null;
		  Transaction tx=null;
		  try
		  {
		    session =this.getSession();
		    tx = session.beginTransaction();
		    session.save(oneBBSTitleInfo);
		    tx.commit();
		    OKOrNot=true;
		  }
		  catch (DataAccessException he)
		  {
				throw new WebBBSException("在BBSTitleInfoManageDAOHibernateImple类中的insertBBSTitleInfo方法出现了HibernateException异常");
		  }		
		  return OKOrNot;

	}
	ArrayList allBBSInfoSByOneBBSTitle=null;
	public ArrayList getAllBBSInfoSByOneBBSTitle() 
	{
		return allBBSInfoSByOneBBSTitle;
	}
	public BBSTitleInfoPO selectBBSTitleByBBSTitleID(int bbsTitleID)
			throws WebBBSException 
	{
	
		BBSTitleInfoPO oneBBSTitleInfoPO=null;
		Session session=null;
		Transaction tx=null;
		try
		{
			session =this.getSession();
			tx = session.beginTransaction();

			oneBBSTitleInfoPO = (BBSTitleInfoPO) session.get(BBSTitleInfoPO.class, new Integer(bbsTitleID));
			if(oneBBSTitleInfoPO==null)
			{
				throw new WebBBSException("在数据库表中不存在指定bbsTitleID="+bbsTitleID+"的数据顶目!");
			}
			allBBSInfoSByOneBBSTitle=oneBBSTitleInfoPO.getBBSInfoSByBBSTitle();   //只能在同一Session中获得对应的O/R Mapping对象

			
			tx.commit();
		}
		catch (DataAccessException he)
		{
			throw new WebBBSException("在BBSTitleInfoManageDAOHibernateImple类中的selectBBSTitleByBBSTitleID方法出现了HibernateException异常");
		}	
		return oneBBSTitleInfoPO;

	}
	public ArrayList selectSomeBBSInfoTitle(String HQLSelect) throws    WebBBSException
	{
	    List selectResult = null;
	    ArrayList allBBSTitleInfoPOs = 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 allBBSTitleInfoPOItem=selectResult.iterator();
	      	 while(allBBSTitleInfoPOItem.hasNext())
	      	 {
	      		BBSTitleInfoPO oneBBSTitleInfoPO=(BBSTitleInfoPO)allBBSTitleInfoPOItem.next();
	      		allBBSTitleInfoPOs.add(oneBBSTitleInfoPO);
	      	 }
	      tx.commit();
	    }
	    catch (DataAccessException he)
	    {
			throw new WebBBSException("在BBSTitleInfoManageDAOHibernateImple类中的selectSomeBBSInfoTitle方法出现了HibernateException异常");	    
		}	
	    return allBBSTitleInfoPOs;		
	}
	public ArrayList getAllBbsTitleInfos() throws WebBBSException 
	{
		String HQLQuery="from com.px1987.webbbs.dao.BBSTitleInfoPO as oneBBSTitleInfoPO order by oneBBSTitleInfoPO.id desc";
		return selectSomeBBSInfoTitle(HQLQuery);
	}

	public int getBBSTitleInfoTotalCounter() throws WebBBSException 
	{
		String HQLQuery="select count(*) from com.px1987.webbbs.dao.BBSTitleInfoPO";
		return  getBBSTitleInfoTotalCounter(HQLQuery);
	}
	public int getBBSTitleInfoTotalCounter(String HQLQuery) throws WebBBSException 
	{
		int totalBBStitleInfoCounter;
	    Session session=null;
	    Transaction tx=null;
	    Query query =null;
	    try
	    {
	    	session = this.getSession();
	    	tx = session.beginTransaction();
	    	query = session.createQuery(HQLQuery);
	      	Integer objectCounter=(Integer)query.uniqueResult();
	      	totalBBStitleInfoCounter=objectCounter.intValue();

	      	tx.commit();
	    }
	    catch (DataAccessException he)
	    {
			throw new WebBBSException("在BBSTitleInfoManageDAOHibernateImple类中的getBBSTitleInfoTotalCounter方法出现了HibernateException异常");
	    }	 
	    return totalBBStitleInfoCounter;
	}
	public boolean updateBBTitleCounterByBbsTitleID(int bbsTitleID,String bbsAuthorID,String bbsAuthorName) throws WebBBSException 
	{
		
	     boolean OKOrNot=false;
	     Session session=null;
	     Transaction tx=null;
		 Date nowDate=new Date();
		 String todayDateString=(nowDate.getYear()+1900)+"-"+(nowDate.getMonth()+1)+"-"+nowDate.getDate();

	     String HQLQuery="update com.px1987.webbbs.dao.BBSTitleInfoPO as oneBBSTitleInfoPO set oneBBSTitleInfoPO.totalTopicNumber=oneBBSTitleInfoPO.totalTopicNumber+1 "+
	     			",oneBBSTitleInfoPO.todayTopicNumber=oneBBSTitleInfoPO.todayTopicNumber+1,"+
	     			"oneBBSTitleInfoPO.lastSendTime='"+todayDateString+"',"+
	     			"oneBBSTitleInfoPO.lastTopicAuthor='"+bbsAuthorName+"'"+
	     			" where oneBBSTitleInfoPO.id="+bbsTitleID+" and oneBBSTitleInfoPO.userID='"+bbsAuthorID+"'";
	     try
	     {
	       session = this.getSession();
	       tx = session.beginTransaction();
	       Query query = session.createQuery(HQLQuery);
	       query.executeUpdate();
	       
	       tx.commit();
	       OKOrNot=true;
	     }
	     catch (DataAccessException he)
	     {
		       throw new WebBBSException("在BBSInfoManageDAOHibernateImple类中的updateBBSReplyCounterByBBSID方法出现了HibernateException异常");
	     }
	     return OKOrNot;
	}

}

⌨️ 快捷键说明

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