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

📄 crefourmdao.java

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

import java.util.List;

import org.apache.log4j.Logger;

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

import cn.hope.front.pojo.CRefourm;
import cn.hope.front.pojo.base.BaseCRefourmDAO;


public class CRefourmDAO extends BaseCRefourmDAO {
	Logger log = Logger.getLogger(CRefourmDAO.class.getName());
	/**
	 * Default constructor.  Can be used in place of getInstance()
	 */
	//=============zhang hong tao ===================
	public CRefourmDAO () {}
	
	public List U01D1000selec(String TTopicid) throws HibernateException {
		List list = null;
		String sqlStr = "from CRefourm c where c.flag='0' and c.CFourm.TTopicid='"+TTopicid+"'";
		try {
			
			initialize();
			list = this.getSession().find(sqlStr);
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
		return list;
	}
	private int zht = 0;
	
	public int getCount() {
		return this.zht;
	}
		public List D1000daosearch(String TTopicid, int start, int range, boolean isEq)
		throws HibernateException {
				List list = null;
					StringBuffer sqlCnt = new StringBuffer();// 取总记录数
					StringBuffer sqlStr = new StringBuffer();// 长字符串的拼合一定要用StringBuffer.append()
					StringBuffer condition = new StringBuffer();// 查询条件
					sqlCnt.append("select count(*) from CRefourm c where c.flag='0' and c.CFourm.TTopicid='"+TTopicid+"'");
					sqlStr.append("from CRefourm c where c.flag='0' and c.CFourm.TTopicid='"+TTopicid+"'");

/* 通过tFile中存储的条件组装HQL语句 */

		try {
			initialize();
			Query queryCnt = this.getSession().createQuery(
					sqlCnt.toString() + condition);// 通过hibernate的Query方法查询数据库(自己看文档)
			Integer zht = (Integer) queryCnt.uniqueResult();// 得到总记录数
			this.zht =zht.intValue();
			System.out.println(zht);
			condition.append(" order by c.CFourm.TTopicid desc");// 加入排序条件
			Query query = this.getSession().createQuery(
					sqlStr.toString() + condition);
			query.setFirstResult(start);// 设置查询起始记录数
			query.setMaxResults(range);// 设置查询总记录数
			list = query.list();
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
			}
			return list;
		}
		
		public Integer U01D10000insert(CRefourm crefourm) throws HibernateException {
			int falg=0;
			Integer in=new Integer(falg);
			try {
				initialize();// 初始化session
				in=this.save(crefourm);// 调用生成好的父类方法save(),返回被插入数据的主键
				
			} catch (HibernateException e) {
				log.error(e);
				e.printStackTrace();
				throw new HibernateException(e);
			} finally {
				closeCurrentThreadSessions();// 关闭当前session
			}
			return in;
		}


}

⌨️ 快捷键说明

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