package hibernate.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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
j2ee-struts2-Select_DoubleSelect.rar_struts2 doubleselect
共55个文件
java:11个
class:11个
jar:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2022-09-22
20:45:08
上传
评论
收藏 3.97MB RAR 举报
温馨提示
J2EE中使用struts2实现的select和doubleselect标签
资源推荐
资源详情
资源评论
收起资源包目录
j2ee-struts2-Select_DoubleSelect.rar (55个子文件)
j2ee-struts2-Select&DoubleSelect
.myhibernatedata 520B
.myumldata 66B
.settings
com.genuitec.eclipse.j2eedt.core.prefs 1KB
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.ltk.core.refactoring.prefs 137B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
src
struts.xml 771B
hibernate
dao
HibernateSessionFactory.java 3KB
DAOTest.java 541B
UserDAO.java 3KB
BaseHibernateDAO.java 310B
IBaseHibernateDAO.java 224B
config
User.hbm.xml 836B
vo
User.java 958B
hibernate.cfg.xml 929B
struts2
LoginAction.java 2KB
values
Province.java 660B
City.java 540B
Cities.java 1KB
Provinces.java 874B
LoginAction_zh_CN.properties 25B
.project 2KB
WebRoot
msg
loginSuc.jsp 690B
loginFail.jsp 309B
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 659B
classes
struts.xml 771B
hibernate
dao
DAOTest.class 1KB
BaseHibernateDAO.class 494B
IBaseHibernateDAO.class 178B
HibernateSessionFactory.class 2KB
UserDAO.class 4KB
config
User.hbm.xml 836B
vo
User.class 1KB
hibernate.cfg.xml 929B
struts2
LoginAction.class 3KB
values
Province.class 1KB
Provinces.class 2KB
City.class 982B
Cities.class 2KB
LoginAction_zh_CN.properties 25B
lib
commons-fileupload-1.2.1 - 复制.jar 56KB
xwork-core-2.2.1.jar 997KB
freemarker-2.3.16.jar 860KB
commons-fileupload-1.2.1.jar 56KB
ognl-3.0.jar 224KB
log4j-1.2.15.jar 383KB
javassist-3.7.ga.jar 531KB
struts2-core-2.2.1.jar 755KB
commons-io-1.3.2.jar 86KB
mysql-connector-java-5.0.7-bin.jar 524KB
index.jsp 2KB
.mymetadata 359B
.classpath 1KB
.myeclipse
共 55 条
- 1
资源评论
JonSco
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功