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

📄 u01cdeptbo.java

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

import java.util.List;

import net.sf.hibernate.HibernateException;

import org.apache.log4j.Logger;

import cn.hope.mana.pojo.CDept;
import cn.hope.mana.pojo.dao.CDeptDAO;

public class U01CDeptBO {
	Logger log = Logger.getLogger(U01CDeptBO.class.getName());
	
	private CDeptDAO deptDAO = new CDeptDAO();
	public List search() throws HibernateException {
		try {			
			return deptDAO.search();
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} 
	}
	public CDept search(Integer dId) throws HibernateException {
		try {			
			return deptDAO.search(dId);
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} 
	}
	public boolean insert(CDept cDept) throws HibernateException {
		int count = 0;
		String dName = cDept.getDName().trim();
		try {
			count = deptDAO.search(dName);
			if (count == 0) {
				cDept.setFlag("0");
				cDept.setDName(dName);
				deptDAO.insert(cDept);
				return true;
			}
			return false;
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} 
	}
	public boolean delete(CDept cDept) throws HibernateException {
		String[] dids = cDept.getDIds();
		try {
			for (int i = 0 ; i < dids.length ; i ++) {
				Integer did = new Integer(dids[i]);
				List listC = deptDAO.searchClass(did);
				List listT = deptDAO.searchTInfo(did);
				if (listC.size()>0 || listT.size()>0){
					return false;
				}
			}
			for (int i = 0 ; i < dids.length ; i ++) {
				CDept cd = deptDAO.search(new Integer(dids[i]));
				cd.setFlag("1");
				deptDAO.delete(cd);
			}
			return true;
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} 
	}
	public boolean update(CDept cDept) throws HibernateException {
		int count = 0;
		String dName = cDept.getDName().trim();
		try {
			count = deptDAO.search(dName);
			if (count == 0) {
				cDept.setFlag("0");
				cDept.setDName(dName);
				deptDAO.update(cDept);
				return true;
			}
			return false;
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} 
	}
}

⌨️ 快捷键说明

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