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

📄 u01mhtypebo.java

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

import java.util.Iterator;
import java.util.List;

import net.sf.hibernate.HibernateException;

import org.apache.log4j.Logger;

import cn.hope.mana.pojo.MHelp;
import cn.hope.mana.pojo.MHtype;
import cn.hope.mana.pojo.dao.MHelpDAO;
import cn.hope.mana.pojo.dao.MHtypeDAO;

public class U01MHTypeBO {
	public static void main(String[] args) {
		U01MHTypeBO U01MHTypeBO=new U01MHTypeBO();
		try {
			U01MHTypeBO.delete(new Integer(1));
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	Logger log = Logger.getLogger(U01MHTypeBO.class.getName());
	
	/**
	 * 查询数据方法
	 * 
	 * @param  
	 * @return List
	 * @throws HibernateException
	 */
	public List searchAll() throws HibernateException {
		try {
			return new MHtypeDAO().searchMHtype();
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		}
	}
	/**
	 * 查询数据方法
	 * 
	 * @param  
	 * @return MHtype
	 * @throws HibernateException
	 */
	public MHtype find(Integer htId) throws HibernateException {
		try {
			return new MHtypeDAO().load(htId);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		}
	}

	/**
	 * 修改数据方法
	 * 
	 * @param  MHtype
	 * @return void
	 * @throws HibernateException
	 */
	public boolean update(MHtype mHtype) throws HibernateException {
		MHtypeDAO htDAO = new MHtypeDAO();
		String htName = mHtype.getHtName().trim();
		mHtype.setHtName(htName);
		int count = 0;
		try {
			count = htDAO.searchByName(htName);
			if (count == 0) {
				htDAO.update(mHtype);
				return true;
			}
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		}
		return false;
	}
	/**
	 * 删除数据方法
	 * 
	 * @param  Integer
	 * @return void
	 * @throws HibernateException
	 */
	public void delete(Integer htId) throws HibernateException {
		MHtypeDAO htDAO = new MHtypeDAO();
		MHelpDAO hDAO = new MHelpDAO();
		MHtype ht = new MHtype();
		List list = null;
		try {			
			ht = htDAO.searchByKey(htId);
			/**先删除帮助**/
			list = hDAO.search(ht);
			Iterator it = list.iterator();
			while (it.hasNext()){
				MHelp h = (MHelp) it.next();
				h.setFlag("1");
				hDAO.update(h);
			}
			/*********/
			ht.setFlag("1");
			htDAO.update(ht);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		}
	}
}

⌨️ 快捷键说明

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