package com;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ajax+hibernate
共38个文件
jar:17个
class:5个
java:5个
需积分: 9 8 下载量 108 浏览量
2008-06-13
17:46:45
上传
评论
收藏 5.49MB RAR 举报
温馨提示
ajax+hibernate实现类似于google的输入提示功能..
资源推荐
资源详情
资源评论
收起资源包目录
ajax_tip.rar (38个子文件)
ajax_tip
.project 1KB
.mymetadata 297B
WebRoot
WEB-INF
web.xml 691B
lib
log4j-1.2.11.jar 342KB
antlr-2.7.5H3.jar 423KB
jta.jar 9KB
hibernate3.jar 1.88MB
jaxen-1.1-beta-7.jar 222KB
commons-logging-1.0.4.jar 37KB
xml-apis.jar 121KB
jdbc2_0-stdext.jar 7KB
commons-collections-2.1.1.jar 171KB
jaas.jar 102KB
ehcache-1.1.jar 46KB
dom4j-1.6.1.jar 307KB
asm.jar 26KB
classes12.jar 1.14MB
xerces-2.6.2.jar 987KB
cglib-2.1.3.jar 276KB
asm-attrs.jar 16KB
classes
com
SuggestInfoDAO.class 2KB
HibernateSessionFactory.class 2KB
SuggestInfo.class 870B
Test.class 772B
ServletTip.class 2KB
SuggestInfo.hbm.xml 680B
hibernate.cfg.xml 923B
META-INF
MANIFEST.MF 39B
suggest.html 5KB
.myeclipse
src
com
SuggestInfoDAO.java 984B
ServletTip.java 1KB
Test.java 284B
SuggestInfo.java 763B
SuggestInfo.hbm.xml 680B
HibernateSessionFactory.java 3KB
hibernate.cfg.xml 923B
.classpath 2KB
.myhibernatedata 439B
共 38 条
- 1
资源评论
kunmingkunlun
- 粉丝: 21
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功