?? hibsessionfactory.java
字號:
package com.bOS.bUtil.db;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.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 + -