powerutil.java

来自「J2EE电子商务系统开发从入门到精通---基于Struts和Hibernate技」· Java 代码 · 共 80 行

JAVA
80
字号
/*
 * PowerUtil.java
 *
 * Created on 2006年6月10日, 下午11:05
 *
 * 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 net.sf.hibernate.*;
/**
 *
 * @author Administrator
 */
public class PowerUtil {
    public static boolean insert(Power power) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            session.save(power);
            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 List findAll() {
        List list = null;
        list = HibernateService.execQuery("from Power");
        return list;
    }
    
    public static boolean addEmployees(String id, Employee employee) {
        Transaction transaction = null;
        Session session = null;
        boolean b = false;
        try {
            session = HibernateService.getSession();
            transaction = session.beginTransaction();
            Power power = new Power();
            session.load(power, Byte.valueOf(id));
            employee.setPower(power);
            session.update(power);
            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;
        }
    }
}

⌨️ 快捷键说明

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