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

📄 empinfodaoimpl.java

📁 struts的一些基本开发
💻 JAVA
字号:
package cn.com.csuinfosoft.dao.impl;

import java.sql.Date;
import java.util.List;

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

import cn.com.csuinfosoft.dao.DAOException;
import cn.com.csuinfosoft.dao.EmpInfoDAO;
import cn.com.csuinfosoft.entity.DeptInfoVO;
import cn.com.csuinfosoft.entity.EmpInfoVO;
import cn.com.csuinfosoft.hibernate.HibernateHelper;

public class EmpInfoDAOImpl implements EmpInfoDAO {

	public boolean addEmpInfo(EmpInfoVO empInfoVO) throws DAOException {
		Session session = HibernateHelper.getSessionObject();
		Transaction tran = null;
		boolean state = false;
		try {
			tran = session.beginTransaction();
			session.save(empInfoVO);
			tran.commit();
			state = true;
			session.clear();
		} catch (HibernateException e) {
			try {
				if(tran != null) {
					tran.rollback();
				}
			} catch (HibernateException e1) {
				e1.printStackTrace();
			}
			throw new DAOException(e);
		}
		return state;
	}

	public boolean delEmpInfo(Integer[] argEmpno) throws DAOException {
		Session session = HibernateHelper.getSessionObject();
		Transaction tran = null;
		boolean state = false;
		EmpInfoVO empInfoVO =null;
		try {
			tran = session.beginTransaction();
			for(int i = 0; i < argEmpno.length; i++) {
				empInfoVO = new EmpInfoVO();
				empInfoVO.setEmpNo(argEmpno[i]);
				session.delete(empInfoVO);
			}
			tran.commit();
			state = true;
		} catch (HibernateException e) {
			try {
				if(tran != null) {
					tran.rollback();
				}
			} catch (HibernateException e1) {
				e1.printStackTrace();
			}
			throw new DAOException(e);
		}
		return state;
	}

	public List queryEmpInfo() throws DAOException {
		Session session = HibernateHelper.getSessionObject();
		List result = null;
		try {
			Query query = session.createQuery("from EmpInfoVO");
			result = query.list();
		} catch (HibernateException e) {
			throw new DAOException(e);
		}
		return result;
	}
	
	
	public static void main(String[] args) {
		//添加员工信息
		EmpInfoVO empInfoVO = new EmpInfoVO();
		empInfoVO.setEname("彦彦");
		empInfoVO.setJob("程序员");
		empInfoVO.setHiredate(new Date(System.currentTimeMillis()));
		empInfoVO.setMgr(new Integer(7934));
		empInfoVO.setSal(new Double(760));
		empInfoVO.setComm(new Double(200));
		
		DeptInfoVO deptInfoVO = new DeptInfoVO();
		deptInfoVO.setDeptno(new Integer(41));
		empInfoVO.setDeptInfoVo(deptInfoVO);
		
		EmpInfoDAOImpl daoImpl = new EmpInfoDAOImpl();
		
		try {
			daoImpl.addEmpInfo(empInfoVO);
		} catch (DAOException e) {
			System.out.println(e);
		}
		HibernateHelper.closeSession();
	}
}

⌨️ 快捷键说明

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