当前位置:网站首页>基于SSH+Bootstrap+MySQL的高校论坛博客系统
基于SSH+Bootstrap+MySQL的高校论坛博客系统
2022-07-19 15:04:00 【2016855150】
首页
浏览
帖子查看
分类查看
分类信息
热门帖子
精华帖子
注册
登陆
发布帖子
我的帖子
资料修改
请求
技术描述
开发工具: Idea/Eclipse
数据库: mysql
Jar包仓库: Jar包
前段框架:jquery/Jsp
后端框架: Spring+Structs2+Hibernate
资料说明
基于SSH+Bootstrap+MySQL的高校论坛博客系统,分为普通用户,管理员。发布公告,资料修改,帖子管理,讨论区管理,登陆注册,发布帖子,评论等。
package com.bbs.hibernate.factory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
/**
* 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 final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static org.hibernate.SessionFactory sessionFactory;
private static Configuration configuration = new Configuration();
private static ServiceRegistry serviceRegistry;
static {
try {
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} 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;
// if (sessionFactory == null){
// rebuildSessionFactory();
// }
// return sessionFactory.openSession();
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} 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 hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}
边栏推荐
- OCR series training notes (I)
- lc marathon 7.19
- Generalized odin: Detecting out-of-distribution image without learning from out-of-distribution data
- Wechat authorized login
- 入职开发环境配置
- 携手紫光展锐,与德通讯借道与展微电子杀入物联网芯片市场
- Five ways to obtain database connection
- Distance-Based Background Class Regularization for Open-Set Recognition
- idea读取配置文件如ValidationMessages.properties中文乱码
- D2 principle of multilayer neural network / principle of automatic derivation of neural network
猜你喜欢
Towards Open World Object Detection
D2-多层神经网络的原理/神经网络自动求导的原理
XML file fuzzy query writing method SQL function find_ in_ set
Set the default value in the database to prevent the added record from becoming null
Runtime.getRuntime().addShutdownHook(new Thread())用法
UML-idea
sql优化 limit1
Paper reading - temporary fusion transformers for interpretable multi horizon time series forecasting
TCGA中RNA-counts数据中ensemble_ID转换成gene_ID的方法
Review the first time, 220619, data warehouse DWB layer dimensionality reduction, video,
随机推荐
Dahua Haikang camera video streaming
消息中间件
Shadow Detection
Why must the hashcode method be overridden when overriding the equals method
二叉树的深度优先和广度优先遍历方式的实现
浏览器的事件循环(Event Loop)
idea启动项目失败 YAMLException 中文文件编码格式
公式编辑==
发现增长新动力,企业到底需要一朵什么样的云?
OCR series training notes (I)
12. Timing, switching, process and mode of process scheduling
数据库持久化+JDBC数据库连接
Embracing capital and accelerating forward, China micro semiconductor has submitted IPO guidance for filing
青花瓷Charles使用
BERT 详解
review第2遍,220614,视频,Day03_数据仓库设计,
Examples of requests module usage
华为5G欧洲遇阻,又一国家宣布考虑禁用!
SQL判断是否是今天 昨天 本月 上个月
Practice of data storage scheme in distributed system