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

📄 cdutycondao.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.CDutycon;
import cn.hope.mana.pojo.base.BaseCDutyconDAO;


public class CDutyconDAO extends BaseCDutyconDAO {

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

	/**
	 * 查询数据方法
	 * 
	 * @param  
	 * @return list
	 * @throws HibernateException
	 */
	public List search() throws HibernateException {
		try {			
			initialize();
			return this.findAll();			
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 通过名字查询数据方法
	 * 
	 * @param  
	 * @return CDutycon
	 * @throws HibernateException
	 */
	public int searchByName(String cdName) throws HibernateException {
		String sqlCnt = "select count(cDutycon.cdId) from CDutycon cDutycon where cDutycon.cdName='"
			+cdName+"'";
		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  CDutycon
	 * @return 
	 * @throws HibernateException
	 */
	public void insert(CDutycon cDutycon) throws HibernateException {
		try {			
			initialize();
			this.save(cDutycon);			
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}
	/**
	 * 修改数据方法
	 * 
	 * @param  CDutycon
	 * @return 
	 * @throws HibernateException
	 */
	public void update(CDutycon cDutycon) throws HibernateException {
		try {			
			initialize();
			super.update(cDutycon);			
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
	}

}

⌨️ 快捷键说明

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