📄 newspressutil.java
字号:
/*
* NewspressUtil.java
*
* Created on 2006年6月1日, 上午7:00
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package model.newspress.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 NewspressUtil {
public static boolean insert(String typeId, Newspress press) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
NewstypeUtil.addNewspresses(typeId, press);
session.save(press);
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, Newspress press) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Newspress np = new Newspress();
session.load(np, Integer.valueOf(id));
np.setAuthor(press.getAuthor());
np.setContent(press.getContent());
np.setPresstime(press.getPresstime());
np.setTitle(press.getTitle());
NewstypeUtil.addNewspresses(typeId, np);
session.update(np);
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 sql, int firstPage, int maxSize) {
List list = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
list = HibernateService.execQuery(sql, 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 Newspress find(String id) {
Transaction transaction = null;
Session session = null;
Newspress press = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
press = new Newspress();
session.load(press, Integer.valueOf(id));
transaction.commit();
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
press = null;
}
catch (Exception e) {
e.printStackTrace();
press = null;
}
finally {
HibernateService.closeSession(session);
return press;
}
}
public static List findAll() {
List list = null;
list = HibernateService.execQuery("from Newspress ");
return list;
}
public static boolean delete(String id) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Newspress press = new Newspress();
session.load(press, Integer.valueOf(id));
session.delete(press);
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 + -