📄 hibsessionfactory.java
字号:
/*
* Created on 2006-1-11
*
*/
package com.bOS.bUtil.db;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
/**
* @author BWeiMing
*
*/
public class HibSessionFactory{
private static SessionFactory sf=null;
public static final ThreadLocal session = new ThreadLocal();
private HibSessionFactory() {
}
private static SessionFactory getSession() throws HibernateException {
if (sf == null) {
return new Configuration().configure().buildSessionFactory();
}else{
return sf;
}
}
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
s = HibSessionFactory.getSession().openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -