package tarena.util;
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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jquery异步提交例子
共48个文件
tld:15个
java:7个
class:7个
4星 · 超过85%的资源 需积分: 9 62 下载量 137 浏览量
2010-10-15
08:55:35
上传
评论
收藏 389KB RAR 举报
温馨提示
jquery 异步提交的例子。使用的是jquery + servlet 。使用jquery $.get() $.post() 提交请求道servlet 页面
资源推荐
资源详情
资源评论
收起资源包目录
ajax02.rar (48个子文件)
ajax02
hibernate.reveng.xml 413B
.myhibernatedata 481B
src
hibernate.cfg.xml 911B
tarena
dao
IBookDAO.java 373B
Test.java 468B
BookDAO.java 2KB
book
Books.java 2KB
Books.hbm.xml 1KB
servlet
BookFindServlet.java 2KB
PublisherFindServlet.java 1015B
util
HibernateSessionFactory.java 3KB
.project 1KB
WebRoot
AjaxBookList.jsp 495B
META-INF
MANIFEST.MF 39B
WEB-INF
scriptfree.tld 2KB
c-1_0.tld 11KB
fmt-1_0.tld 12KB
fn.tld 7KB
web.xml 971B
fmt.tld 19KB
x.tld 12KB
x-1_0-rt.tld 7KB
fmt-1_0-rt.tld 11KB
x-1_0.tld 7KB
sql.tld 8KB
classes
hibernate.cfg.xml 911B
tarena
dao
Test.class 2KB
IBookDAO.class 550B
BookDAO.class 3KB
book
Books.hbm.xml 1KB
Books.class 2KB
servlet
PublisherFindServlet.class 2KB
BookFindServlet.class 3KB
util
HibernateSessionFactory.class 2KB
sql-1_0.tld 6KB
sql-1_0-rt.tld 5KB
lib
standard.jar 343KB
jstl.jar 17KB
c-1_0-rt.tld 11KB
permittedTaglibs.tld 1KB
c.tld 16KB
js
jquery-1.3.2.js 118KB
AjaxPublisherList.jsp 322B
BookFind.html 3KB
index.jsp 834B
Test1.html 845B
.mymetadata 291B
.classpath 649B
.myeclipse
共 48 条
- 1
资源评论
- kkkey1102015-04-02简单实用的例子,现在就需要这种能看懂的例子
- handinhand13142013-09-18在其中找到了我需要的内容,不错。
LIU471697737
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功