empbargaindaoimpl.java

来自「用jsp,servlet实现人力资源管理系统」· Java 代码 · 共 111 行

JAVA
111
字号
package com.dao.impl;

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 com.dao.EmpBargainDAO;
import com.entity.EmpBargain;
import com.entity.EmpRecord;
import com.hibernate.HibernateSessionFactory;

public class EmpBargainDAOImpl implements EmpBargainDAO {

	public boolean addEmpBargain(EmpBargain empBargain) {

		Session session = HibernateSessionFactory.openHibernateSession();
		boolean state = false;
		try {
			Transaction tran = session.beginTransaction();
			//System.out.print(empBargain.getEmpName());
			session.save(empBargain);
			tran.commit();
			state = true;
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		return state;
	}

	public boolean delEmpBargain(int barId) {

		EmpBargain empBargain = null;
		Session session = HibernateSessionFactory.openHibernateSession();
		boolean state = false;
		try {
			Transaction tran = session.beginTransaction();
			
			empBargain = queryEmpBargainByBarId(barId);
				
				session.delete(empBargain);
			
			tran.commit();
			state = true;
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		return state;
	}

	public List queryEmpBargain() {

		Session session = HibernateSessionFactory.openHibernateSession();
		Query query = null;
		List result = null;
		try {
			query = session.createQuery("from EmpBargain");
			result = query.list();
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		return result;
	}

	public EmpBargain queryEmpBargainByBarId(int barId) {

		Session session = HibernateSessionFactory.openHibernateSession();
		EmpBargain empBargain = null;
		try {
			empBargain = (EmpBargain) session.get(EmpBargain.class, barId);
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		return empBargain;
	}

	public EmpBargain queryEmpBargainByEmpId(int empId) {

		Session session = HibernateSessionFactory.openHibernateSession();
		EmpBargain empBargain = null;
		Query query = null;
		List list = null;
		try {
			query = session.createQuery("from EmpBargain e where e.empId="+empId+"");
			list = query.list();
			empBargain = (EmpBargain) list.get(0);
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		return empBargain;
	}

	public boolean updateEmpBargain(EmpBargain empBargain) {

		Session session = HibernateSessionFactory.openHibernateSession();
		boolean state = false;
		try {
			Transaction tran = session.beginTransaction();
			session.update(empBargain);
			tran.commit();
			state = true;
		} catch (HibernateException e) {
			e.printStackTrace();
		}	
		return state;
	}

}

⌨️ 快捷键说明

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