package com.xh.sessionFactory;
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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java树形菜单或目录开发的源代码
共90个文件
jar:37个
gif:20个
xml:6个
1星 需积分: 25 64 下载量 172 浏览量
2010-03-14
23:24:20
上传
评论
收藏 11.29MB ZIP 举报
温馨提示
以树的形式将数据集合在页面上展现出来。我以前找了很久,最近花费了很大力气才找到。希望对各位有所帮助~!
资源推荐
资源详情
资源评论
收起资源包目录
java树形菜单或目录开发的源代码.zip (90个子文件)
Tree
src
com
xh
dao
Jdbc.java 762B
TreeNodeDAO.java 2KB
bean
TreeNode.java 975B
TreeNode.hbm.xml 966B
struts
action
TreeAction.java 741B
sessionFactory
HibernateSessionFactory.java 3KB
yourcompany
struts
ApplicationResources.properties 87B
hibernate.cfg.xml 954B
.classpath 3KB
.mystrutsdata 262B
.mymetadata 285B
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.jsdtscope 500B
.project 2KB
WebRoot
META-INF
MANIFEST.MF 36B
index.jsp 872B
dtree
dtree.js 12KB
dtree.css 795B
img
line.gif 66B
plusbottom.gif 88B
join.gif 69B
musicfolder.gif 633B
folderopen.gif 376B
plus.gif 89B
minus.gif 86B
imgfolder.gif 622B
cd.gif 239B
page.gif 582B
trash.gif 1KB
base.gif 1KB
nolines_plus.gif 870B
joinbottom.gif 66B
empty.gif 62B
nolines_minus.gif 861B
minusbottom.gif 85B
folder.gif 372B
question.gif 1KB
globe.gif 1KB
Thumbs.db 24KB
WEB-INF
classes
com
xh
dao
Jdbc.class 1KB
TreeNodeDAO.class 3KB
bean
TreeNode.class 2KB
TreeNode.hbm.xml 966B
struts
action
TreeAction.class 1KB
sessionFactory
HibernateSessionFactory.class 2KB
yourcompany
struts
ApplicationResources.properties 87B
hibernate.cfg.xml 954B
struts-config.xml 579B
.struts-config.mex 478B
lib
jta.jar 9KB
jaas.jar 102KB
swarmcache-1.0rc2.jar 30KB
javassist.jar 460KB
jboss-common.jar 570KB
connector.jar 18KB
dom4j-1.6.1.jar 307KB
c3p0-0.9.1.jar 594KB
concurrent-1.3.2.jar 167KB
commons-logging-1.0.4.jar 37KB
xerces-2.6.2.jar 987KB
jaxen-1.1-beta-7.jar 222KB
hibernate3.jar 2.15MB
log4j-1.2.11.jar 342KB
jboss-cache.jar 505KB
commons-collections-2.1.1.jar 171KB
jboss-jmx.jar 578KB
hibernate-entitymanager.jar 114KB
jacc-1_0-fr.jar 24KB
ehcache-1.2.3.jar 203KB
asm-attrs.jar 16KB
jboss-system.jar 218KB
antlr-2.7.6.jar 433KB
xml-apis.jar 121KB
hibernate-commons-annotations.jar 65KB
jgroups-2.2.8.jar 1.54MB
postgresql-8.0-311.jdbc3.jar 323KB
mysql-connector-java-5.0.8-bin.jar 528KB
hibernate-validator.jar 60KB
asm.jar 26KB
hibernate-annotations.jar 259KB
ejb3-persistence.jar 49KB
proxool-0.8.3.jar 465KB
jdbc2_0-stdext.jar 7KB
jboss-archive-browsing.jar 404KB
cglib-2.1.3.jar 276KB
oscache-2.1.jar 112KB
web.xml 1KB
tree_node.sql 3KB
.myhibernatedata 554B
共 90 条
- 1
资源评论
- kalin5202012-10-29是struts1的,代码有点乱,没怎么看得懂
huanggua111
- 粉丝: 4
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功