📄 newstypeutil.java
字号:
/*
* NewstypeUtil.java
*
* Created on 2006年6月1日, 上午7:05
*
* 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.HashSet;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
/**
*
* @author Administrator
*/
public class NewstypeUtil {
public static boolean insert(Newstype type) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
type.setNewspresses(new HashSet());
session.save(type);
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, Newstype type) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Newstype nt = new Newstype();
session.load(nt, Byte.valueOf(id));
nt.setRemarks(type.getRemarks());
nt.setName(type.getName());
session.update(nt);
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 Newstype find(String id) {
Newstype type = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
type = new Newstype();
session.load(type, Byte.valueOf(id));
transaction.commit();
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
type = null;
}
catch (Exception e) {
e.printStackTrace();
type = null;
}
finally {
HibernateService.closeSession(session);
return type;
}
}
public static boolean delete(String id) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Newstype type = new Newstype();
session.load(type, Byte.valueOf(id));
type.getNewspresses().clear();
session.delete(type);
transaction.commit();
b = true;
}
catch (HibernateException he) {
he.printStackTrace();
b = false;
}
catch (Exception e) {
e.printStackTrace();
b = false;
}
finally {
HibernateService.closeSession(session);
return b;
}
}
public static boolean addNewspresses(String id, Newspress press) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Newstype type = new Newstype();
session.load(type, Byte.valueOf(id));
press.setNewstype(type);
session.update(type);
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 + -