📄 storeinutil.java
字号:
/*
* StoreinUtil.java
*
* Created on 2006年5月21日, 下午2:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package model.store.hibernate;
import dbservice.hibernate.HibernateService;
import java.util.List;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.HibernateException;
/**
*
* @author Administrator
*/
public class StoreinUtil {
public static boolean insert(String clientId, String productId, String roomId, Storein storein) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
ClientUtil.addStoreins(clientId, storein);
ProductUtil.addStoreins(productId, storein);
StoreroomUtil.addStoreins(roomId, storein);
session.save(storein);
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;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
list = HibernateService.execQuery("from Storein");
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 Storein find(String id) {
Storein storein = null;
Transaction transaction = null;
Session session = null;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
storein = new Storein();
session.load(storein, Integer.valueOf(id));
transaction.commit();
}
catch (HibernateException he) {
he.printStackTrace();
HibernateService.rollbackTransaction(transaction);
storein = null;
}
catch (Exception e) {
e.printStackTrace();
storein = null;
}
finally {
HibernateService.closeSession(session);
return storein;
}
}
public static boolean update(String id, String clientId, String productId, String storeroomId, Storein s) {
Transaction transaction = null;
Session session = null;
boolean b = false;
try {
session = HibernateService.getSession();
transaction = session.beginTransaction();
Storein storein = new Storein();
session.load(storein, Integer.valueOf(id));
storein.setName(s.getName());
storein.setIntime(s.getIntime());
storein.setRemarks(s.getRemarks());
ClientUtil.addStoreins(clientId, storein);
ProductUtil.addStoreins(productId, storein);
StoreroomUtil.addStoreins(storeroomId, storein);
session.update(storein);
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 + -