package com.xyc.dwr;
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;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
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 dwr 框架实现二级联动下拉列表源码
共51个文件
jar:12个
xml:11个
tld:6个
4星 · 超过85%的资源 需积分: 9 138 下载量 5 浏览量
2008-10-10
16:32:36
上传
评论
收藏 1.71MB RAR 举报
温馨提示
dwr实现的完整的二级下拉联动列表,里面有说明,源代码。
资源推荐
资源详情
资源评论
收起资源包目录
dwrtest.rar (51个子文件)
dwrtest
.project 1KB
.settings
org.eclipse.core.resources.prefs 109B
.mymetadata 294B
WebRoot
WEB-INF
struts-tiles.tld 8KB
dwr.xml 625B
.struts-config.mex 135B
web.xml 2KB
struts-config.xml 556B
struts-bean.tld 9KB
struts-nested.tld 63KB
struts-html.tld 65KB
struts-template.tld 2KB
struts-logic.tld 14KB
validator-rules.xml 41KB
lib
commons-logging.jar 27KB
commons-digester.jar 96KB
commons-fileupload.jar 19KB
mysql-connector-java-3.1.11-bin.jar 430KB
commons-beanutils.jar 100KB
commons-lang.jar 53KB
struts.jar 428KB
commons-validator.jar 40KB
struts-legacy.jar 9KB
dwr.jar 491KB
jakarta-oro.jar 62KB
commons-collections.jar 160KB
classes
com
yourcompany
struts
ApplicationResources.properties 90B
xyc
dwr
HibernateSessionFactory.class 2KB
DwrManagerTest.class 2KB
DwrTest.class 961B
domain
DwrCity.hbm.xml 797B
DwrProvince.hbm.xml 678B
DwrCity.class 1KB
DwrProvince.class 909B
hibernate.cfg.xml 912B
index.jsp 1KB
META-INF
MANIFEST.MF 39B
getCityDynamicList.js 527B
.myeclipse
src
com
yourcompany
struts
ApplicationResources.properties 90B
xyc
dwr
DwrManagerTest.java 877B
DwrTest.java 523B
domain
DwrCity.hbm.xml 797B
DwrCity.java 1KB
DwrProvince.java 807B
DwrProvince.hbm.xml 678B
HibernateSessionFactory.java 3KB
hibernate.cfg.xml 912B
hibernate.reveng.xml 582B
.mystrutsdata 262B
.classpath 2KB
.myhibernatedata 465B
共 51 条
- 1
资源评论
- xuthus_sxs2012-08-10相对来讲,项目就是标题党,程序没有很完整的逻辑
- selfimpl2013-08-05项目就是标题党,程序没有很完整的逻辑
- jiadong19782012-06-22很好,很实用,对于我这种入门者很有提示作用.
xieyunchao
- 粉丝: 35
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功