hibernatebase.java
来自「java实现的可配置的工作流引擎,采用jsp+javabean实现」· Java 代码 · 共 62 行
JAVA
62 行
/*
* Created on 2004-10-12 TODO To change the template for this generated file go to Window - Preferences - Java - Code
* Style - Code Templates
*/
package com.hongsoft.agile.hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.apache.log4j.xml.DOMConfigurator;
import com.hongsoft.agile.*;
import java.io.*;
public class HibernateBase {
private static SessionFactory sessionFactory; // 会话工厂
protected final static String CONFIG_FILE = Global.getConfPath() + "hibernate.cfg.xml";
protected final static String PROCESS_DEFINE = Global.getConfPath() + "agile.hbm.xml";
protected final static String BUSINESS_DEFINE = Global.getConfPath() + "business.hbm.xml";
protected final static String RES_DEFILE = Global.getConfPath() + "res.hbm.xml";
public static final ThreadLocal session = new ThreadLocal();
static {// init
synchronized (CONFIG_FILE) {
if (sessionFactory == null) {
DOMConfigurator.configure(Global.getConfPath() + "log4j.xml");
try {
Configuration conf = new Configuration().addFile(PROCESS_DEFINE).addFile(BUSINESS_DEFINE).addFile(
RES_DEFILE);
conf.configure(new File(CONFIG_FILE));
sessionFactory = conf.buildSessionFactory();
} catch (HibernateException e) {
e.printStackTrace();
}
}
}
}
public static Session getSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
s = sessionFactory.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 + =
减小字号Ctrl + -
显示快捷键?