package dao;
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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ssh(dwr).rar_DWR SSH_dwr_java dwr_ssh_ssh dwr
共111个文件
jar:69个
xml:8个
tld:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 168 浏览量
2022-09-20
18:19:06
上传
评论
收藏 48.15MB RAR 举报
温馨提示
ssh整合的dwr例子 附带视频文件和源代码
资源详情
资源评论
资源推荐
收起资源包目录
ssh(dwr).rar_DWR SSH_dwr_java dwr_ssh_ssh dwr (111个子文件)
HibernateSessionFactory.class 2KB
UserInfoImpl.class 978B
UserInfoBiz.class 846B
UserInfo.class 776B
IUserInfo.class 185B
.classpath 5KB
.classpath 506B
jsp+Dwr2.exe 16.55MB
jsp+Dwr.exe 16.26MB
hibernate3.jar 1.88MB
aspectjweaver.jar 1.8MB
jasperreports-1.3.4.jar 1.61MB
itext-1.3.jar 1.09MB
xerces-2.6.2.jar 987KB
freemarker.jar 834KB
poi-2.5.1.jar 783KB
jxl.jar 597KB
c3p0-0.9.1.2.jar 596KB
sqljdbc2008.jar 570KB
dwr.jar 494KB
dwr.jar 494KB
antlr-2.7.6rc1.jar 434KB
velocity-1.5.jar 383KB
spring-beans.jar 381KB
log4j-1.2.14.jar 359KB
log4j-1.2.11.jar 342KB
cglib-nodep-2.1_3.jar 317KB
dom4j-1.6.1.jar 307KB
spring-aop.jar 301KB
spring-webmvc.jar 279KB
cglib-2.1.3.jar 276KB
commons-httpclient.jar 273KB
commons-lang.jar 237KB
spring-jdbc.jar 222KB
jaxen-1.1-beta-7.jar 222KB
spring-core.jar 178KB
commons-collections-2.1.1.jar 171KB
spring-context.jar 157KB
spring-web.jar 149KB
spring-jms.jar 136KB
spring-dao.jar 127KB
jotm.jar 121KB
xml-apis.jar 121KB
commons-dbcp.jar 119KB
spring-portlet.jar 115KB
velocity-tools-view-1.3.jar 105KB
spring-hibernate3.jar 105KB
jaas.jar 102KB
spring-jpa.jar 96KB
xapool.jar 90KB
commons-io.jar 82KB
persistence.jar 69KB
jakarta-oro-2.0.8.jar 64KB
spring-jdo.jar 61KB
commons-pool.jar 61KB
spring-toplink.jar 56KB
cos.jar 55KB
commons-fileupload.jar 52KB
commons-logging.jar 52KB
commons-logging.jar 52KB
ehcache-1.1.jar 46KB
commons-codec.jar 46KB
spring-jca.jar 45KB
commons-logging-1.0.4.jar 37KB
commons-attributes-api.jar 35KB
asm-util-2.2.3.jar 34KB
asm-2.2.3.jar 34KB
commons-attributes-compiler.jar 29KB
asm.jar 26KB
spring-struts.jar 25KB
spring-ibatis.jar 24KB
asm-attrs.jar 16KB
portlet-api.jar 15KB
jta.jar 9KB
jdbc2_0-stdext.jar 7KB
spring-tomcat-weaver.jar 5KB
aopalliance.jar 4KB
spring-agent.jar 1KB
HibernateSessionFactory.java 3KB
TransInfo.java 1KB
UserInfoImpl.java 521B
UserInfoBiz.java 448B
UserInfo.java 394B
IUserInfo.java 139B
index.jsp 1KB
index.jsp 1KB
.struts-config.mex 76B
MANIFEST.MF 39B
MANIFEST.MF 39B
.myhibernatedata 537B
.mymetadata 294B
.mymetadata 291B
.mystrutsdata 243B
.project 2KB
.project 1KB
.springBeans 467B
struts-html.tld 72KB
struts-nested.tld 70KB
spring-form.tld 51KB
struts-logic.tld 14KB
共 111 条
- 1
- 2
林当时
- 粉丝: 95
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0