📄 departmentutil.java
字号:
/*
* DepartmentUtil.java
*
* Created on 2006年5月6日, 下午10:30
*
* 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.HashSet;
import java.util.List;
import model.asset.hibernate.Asset;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
*
* @author Administrator
*/
public class DepartmentUtil {
public static boolean insert(Department department) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
session.save(department);
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 Department");
return list;
}
public static Department find(String id) {
Department dep = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
dep = new Department();
session.load(dep, Byte.valueOf(id));
transaction.commit();
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
dep = null;
}
catch (Exception e) {
e.printStackTrace();
dep = null;
}
finally {
HibernateService.closeSession(session);
return dep;
}
}
public static boolean addEmployees(String id, Employee employee) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Department department = new Department();
session.load(department, Byte.valueOf(id));
employee.setDepartment(department);
session.update(department);
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 addAssets(String id, Asset asset) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Department department = new Department();
session.load(department, Byte.valueOf(id));
asset.setDepartment(department);
session.update(department);
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -