📄 documentutil.java
字号:
/*
* DocumentUtil.java
*
* Created on 2006年9月6日, 上午4:04
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package model.library.hibernate;
import dbservice.hibernate.HibernateService;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
*
* @author Administrator
*/
public class DocumentUtil {
public static boolean insert(Document doc) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
session.save(doc);
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, Document document) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Document doc = new Document();
session.load(doc, Integer.valueOf(id));
doc.setName(document.getName());
doc.setSummary(document.getSummary());
doc.setContent(document.getContent());
doc.setRemarks(document.getRemarks());
session.update(doc);
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 find(String hql, int firstPage, int maxSize) {
List list = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
list = HibernateService.execQuery(hql, firstPage, maxSize);
transaction.commit();
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
list = null;
}
catch (Exception e) {
e.printStackTrace();
list = null;
}
finally {
HibernateService.closeSession(session);
return list;
}
}
public static List findAll() {
List list = null;
list = HibernateService.execQuery("from Document");
return list;
}
public static Document find(String id) {
Document doc = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
doc = new Document();
session.load(doc, Integer.valueOf(id));
transaction.commit();
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
doc = null;
}
catch (Exception e) {
e.printStackTrace();
doc = null;
}
finally {
HibernateService.closeSession(session);
return doc;
}
}
public static boolean delete(String id) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Document doc = new Document();
session.load(doc, Integer.valueOf(id));
doc.getHistories().clear();
session.delete(doc);
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 + -