📄 assetutil.java
字号:
/*
* AssetUtil.java
*
* Created on 2006年6月10日, 上午10:52
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package model.asset.hibernate;
import dbservice.hibernate.HibernateService;
import java.util.HashSet;
import java.util.List;
import model.hr.hibernate.*;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
*
* @author Administrator
*/
public class AssetUtil {
private static byte STATUS_INIT = 0;
private static byte STATUS_AUDIT = 1;
public static boolean insert(String typeId, String depId, Asset asset) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
AssettypeUtil.addAssets(typeId, asset);
DepartmentUtil.addAssets(depId, asset);
asset.setStatus(STATUS_INIT);
session.save(asset);
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 update(String id, String typeId, String depId, Asset asset) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Asset a = new Asset();
session.load(a, id);
a.setName(asset.getName());
a.setPrice(asset.getPrice());
a.setRemarks(asset.getRemarks());
a.setStatus(STATUS_INIT);
AssettypeUtil.addAssets(typeId, a);
DepartmentUtil.addAssets(depId, a);
session.update(a);
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 audit(String id) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Asset a = new Asset();
session.load(a, id);
a.setStatus(STATUS_AUDIT);
session.update(a);
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 Asset");
return list;
}
public static Asset find(String id) {
Asset asset = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
asset = new Asset();
session.load(asset, id);
transaction.commit();
HibernateService.closeSession(session);
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
asset = null;
}
catch (Exception e) {
e.printStackTrace();
asset = null;
}
finally {
HibernateService.closeSession(session);
return asset;
}
}
public static List findAll(String column, String keyword) {
String hql = null;
if (keyword == null || keyword.equals("")) {
keyword = "%";
}
if (column.equals("id") ) {
hql = "from Asset asset where asset.id like '%" + keyword + "%'";
}
else if (column.equals("name") || column.equals("price")) {
hql = "from Asset asset where asset." + column + " like '%" + keyword + "%'";
}
else if (column.equals("typeId")) {
hql = "from Asset asset where asset.assettype.name like '%" + keyword + "%'";
}
else if (column.equals("departmentId")) {
hql = "from Asset asset where asset.department.name like '%" + keyword + "%'";
}
else {
hql = "from Asset";
}
List list = HibernateService.execQuery(hql);
return list;
}
public static boolean delete(String id) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Asset asset = new Asset();
session.load(asset, id);
session.delete(asset);
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 + -