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

📄 employeeutil.java

📁 J2EE电子商务系统开发从入门到精通---基于Struts和Hibernate技术实现
💻 JAVA
字号:
/*
 * EmployeeUtil.java
 *
 * Created on 2006年5月6日, 下午10:38
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package model.hr.hibernate;

import dbservice.hibernate.HibernateService;
import java.util.*;
import model.vote.hibernate.Result;
import net.sf.hibernate.*;
import model.bbs.hibernate.*;
/**
 *
 * @author Administrator
 */
public class EmployeeUtil {
    
    public static boolean insert(String powerId, Employee employee) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            PowerUtil.addEmployees(powerId, employee);
            session.save(employee);
            transaction.commit();
            b = true;
        }
        catch (HibernateException he) {
            he.printStackTrace();
            b = false;
            HibernateService.rollbackTransaction(transaction);
        } 
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        } 
        finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
    
    public static boolean update(String id, String departmentId, String jobId, String cultureId, String maritalId, String nationalityId, Employee employee) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Employee emp = (Employee)session.load(Employee.class, id);
            emp.setAge(employee.getAge());
            emp.setBirthday(employee.getBirthday());
            emp.setExperience(employee.getExperience());
            emp.setIdcard(employee.getIdcard());
            emp.setMobile(employee.getMobile());
            emp.setName(employee.getName());
            emp.setPwd(employee.getPwd());
            emp.setSex(employee.getSex());
            
            DepartmentUtil.addEmployees(departmentId, emp);
            
            JobUtil.addEmployees(jobId, emp);
            
            CultureUtil.addEmployees(cultureId, emp);
            
            MaritalUtil.addEmployees(maritalId, emp);
            
            NationalityUtil.addEmployees(nationalityId, emp);
            
            session.update(emp);
            transaction.commit();
            
            b = true;           
        }
        catch (HibernateException he) {
            he.printStackTrace();
            b = false;
            HibernateService.rollbackTransaction(transaction);
        } 
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        } 
        finally {
            HibernateService.closeSession(session);
            return b;
        }        
    }
    
    public static boolean updatePower(String id, String powerId) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Employee emp = (Employee)session.load(Employee.class, id);
            
            PowerUtil.addEmployees(powerId, emp);
            
            session.update(emp);
            transaction.commit();
            b = true;
        }
        catch (HibernateException he) {
            he.printStackTrace();
            b = false;
            HibernateService.rollbackTransaction(transaction);
        } 
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        } 
        finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
    
    public static Employee find(String id) {
        Employee employee = null;
        Transaction transaction = null;
        Session session = null;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            employee = (Employee)session.load(Employee.class, id);
            transaction.commit();
        }
        catch (HibernateException he) {
            he.printStackTrace();
            employee = null;
            HibernateService.rollbackTransaction(transaction);
        } 
        catch (Exception e) {
            e.printStackTrace();
            employee = null;
        }
        finally {
            HibernateService.closeSession(session);
            return employee;
        }
    }
    
    public static boolean addArticles(String id, Article article) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Employee employee = new Employee();
            session.load(employee, id);
            article.setEmployee(employee);
            session.update(employee);
            transaction.commit();
            b = true;
        }
        catch (HibernateException he) {
            he.printStackTrace();
            b = true;
            HibernateService.rollbackTransaction(transaction);
        }
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        }
        finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
    
    public static boolean addArticleresponses(String id, Articleresponse response) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Employee employee = new Employee();
            session.load(employee, id);
            response.setEmployee(employee);
            session.update(employee);
            transaction.commit();
            b = true;
        } 
        catch (HibernateException he) {
            he.printStackTrace();
            HibernateService.rollbackTransaction(transaction);
            b = false;
        }
        catch (Exception e) {
            e.printStackTrace();
            b = false;
        }
        finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
     
    public static boolean addResults(String id, Result result) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Employee employee = new Employee();
            session.load(employee, id);
            result.setEmployee(employee);
            session.update(employee);
            transaction.commit();
            b = true;
        } catch (HibernateException he) {
            he.printStackTrace();
            b = false;
            HibernateService.rollbackTransaction(transaction);
        } catch (Exception e) {
            e.printStackTrace();
            b = false;
        } finally {
            HibernateService.closeSession(session);
            return b;
        }
    }
}

⌨️ 快捷键说明

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