- 浏览: 1169567 次
- 性别:
- 来自: 火星郊区
-
博客专栏
-
-
OSGi
浏览量:0
文章分类
- 全部博客 (695)
- 项目管理 (48)
- OSGi (122)
- java (79)
- Vaadin (5)
- RAP (47)
- mysql (40)
- Maven (22)
- SVN (8)
- 孔雀鱼 (10)
- hibernate (9)
- spring (10)
- css (3)
- 年审 (6)
- ant (1)
- jdbc (3)
- FusionCharts (2)
- struts (4)
- 决策分析 (2)
- 生活 (10)
- 架构设计 (5)
- 破解 (2)
- 狼文化 (4)
- JVM (14)
- J2EE (1)
- 应用服务器 (1)
- 我的链接 (5)
- 数学 (2)
- 报表 (1)
- 百科 (6)
- Flex (7)
- log4j (2)
- PHP (1)
- 系统 (2)
- Web前端 (7)
- linux (6)
- Office (1)
- 安全管理 (5)
- python (2)
- dom4j (1)
- 工作流 (3)
- 养生保健 (4)
- Eclipse (8)
- 监控开发 (1)
- 设计 (3)
- CAS (1)
- ZK (41)
- BluePrint (3)
- 工具 (1)
- SWT (7)
- google (2)
- NIO (1)
- 企业文化 (2)
- Windoes (0)
- RCP (7)
- JavaScript (10)
- UML (1)
- 产品经理 (2)
- Velocity (10)
- C (1)
- 单元测试 (1)
- 设计模式 (2)
- 系统分析师 (2)
- 架构 (4)
- 面试 (2)
- 代码走查 (1)
- MongoDB (1)
- 企业流程优化 (1)
- 模式 (1)
- EJB (1)
- Jetty (1)
- Git (13)
- IPV6 (1)
- JQuery (8)
- SSH (1)
- mybatis (10)
- SiteMesh (2)
- JSTL (1)
- veloctiy (1)
- Spring MVC (1)
- struts2 (3)
- Servlet (1)
- 权限管理 (1)
- Java Mina (1)
- java 系统信息 (6)
- OSGi 基础 (3)
- html (1)
- spring--security (6)
- HTML5 (1)
- java爬虫搜索 (1)
- mvc (3)
最新评论
-
Tom.X:
http://osgia.com/
将web容器置于OSGi框架下进行web应用的开发 -
chenyuguxing:
你好, 为什么我的bundle export到felix工程中 ...
在Apache Felix中运行bundle -
string2020:
<niceManifest>true</ni ...
Bundle Plugin for Maven -
jsonmong:
OSGI,是未来的主流,目前已相当成熟。应用OSGI比较好的, ...
基于OSGi的声明式服务 -
zyhui98:
貌似是翻译过来的,有很少人在linux上做开发吧
如何成为“10倍效率”开发者
Spring+Hibernate实现动态SessionFactory切换(改进版)
- 博客分类:
- spring
前面写了一篇关于动态切换Hibernate SessionFactory的文章,原文地址:http://tangyanbo.iteye.com/admin/blogs/1717402
发现存在一些问题:
需要配置多个HibernateTransactionManager和多个Spring 切面
这样带来两个问题
1. 程序效率降低,因为Spring进行多次Advice的拦截
2. 如果其中一个SessionFactory连接出现问题,会导致整个系统无法工作
今天研究出一种新的方法来解决此类问题
1. 数据源及Hibernate SessionFactory配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- FOR SqlServer-->
<bean id="SqlServer_DataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url"
value="url" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
<bean id="SqlServer_SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:mappingLocations="classpath:/com/entity/*.hbm.xml">
<property name="dataSource" ref="SqlServer_DataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<!-- FOR Oracle -->
<bean id="Oracle _DataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521/orcl" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
<bean id="Oracle_SessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:mappingLocations="classpath:/com/entity/*.hbm.xml">
<property name="dataSource" ref="Oracle_DataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
</beans>
2. 定义扩展接口DynamicSessionFactoryInf继承SessionFactory
- import org.hibernate.SessionFactory;
- public interface DynamicSessionFactoryInf extends SessionFactory {
- public SessionFactory getHibernateSessionFactory();
- }
3. 定义DynamicSessionFactory实现DynamicSessionFactoryInf
- public class DynamicSessionFactory implements DynamicSessionFactoryInf ,ApplicationContextAware{
- private static final long serialVersionUID = 1L;
- private ApplicationContext applicationContext;
- //动态调用SessionFactory
- private SessionFactory getHibernateSessionFactory(String name) {
- return (SessionFactory) applicationContext.getBean(name);
- }
- //实现DynamicSessionFactoryInf 接口的方法
- public SessionFactory getHibernateSessionFactory() {
- return getHibernateSessionFactory(ThreadLocalUtil.getCurrentITAsset()
- .getSessionFactoryName());
- }
- //以下是实现SessionFactory接口的方法,并对当前的SessionFactory实体进行代理
- public Reference getReference() throws NamingException {
- return getHibernateSessionFactory().getReference();
- }
- public Session openSession() throws HibernateException {
- return getHibernateSessionFactory().openSession();
- }
- public Session openSession(Interceptor interceptor)
- throws HibernateException {
- return getHibernateSessionFactory().openSession(interceptor);
- }
- public Session openSession(Connection connection) {
- return getHibernateSessionFactory().openSession(connection);
- }
- public Session openSession(Connection connection, Interceptor interceptor) {
- return getHibernateSessionFactory().openSession(connection,interceptor);
- }
- public Session getCurrentSession() throws HibernateException {
- return getHibernateSessionFactory().getCurrentSession();
- }
- public StatelessSession openStatelessSession() {
- return getHibernateSessionFactory().openStatelessSession();
- }
- public StatelessSession openStatelessSession(Connection connection) {
- return getHibernateSessionFactory().openStatelessSession(connection);
- }
- public ClassMetadata getClassMetadata(Class entityClass) {
- return getHibernateSessionFactory().getClassMetadata(entityClass);
- }
- public ClassMetadata getClassMetadata(String entityName) {
- return getHibernateSessionFactory().getClassMetadata(entityName);
- }
- public CollectionMetadata getCollectionMetadata(String roleName) {
- return getHibernateSessionFactory().getCollectionMetadata(roleName);
- }
- public Map getAllClassMetadata() {
- return getHibernateSessionFactory().getAllClassMetadata();
- }
- public Map getAllCollectionMetadata() {
- return getHibernateSessionFactory().getAllCollectionMetadata();
- }
- public Statistics getStatistics() {
- return getHibernateSessionFactory().getStatistics();
- }
- public void close() throws HibernateException {
- getHibernateSessionFactory().close();
- }
- public boolean isClosed() {
- return getHibernateSessionFactory().isClosed();
- }
- public Cache getCache() {
- return getHibernateSessionFactory().getCache();
- }
- public void evict(Class persistentClass) throws HibernateException {
- getHibernateSessionFactory().evict(persistentClass);
- }
- public void evict(Class persistentClass, Serializable id)
- throws HibernateException {
- getHibernateSessionFactory().evict(persistentClass, id);
- }
- public void evictEntity(String entityName) throws HibernateException {
- getHibernateSessionFactory().evictEntity(entityName);
- }
- public void evictEntity(String entityName, Serializable id)
- throws HibernateException {
- getHibernateSessionFactory().evictEntity(entityName, id);
- }
- public void evictCollection(String roleName) throws HibernateException {
- getHibernateSessionFactory().evictCollection(roleName);
- }
- public void evictCollection(String roleName, Serializable id)
- throws HibernateException {
- getHibernateSessionFactory().evictCollection(roleName, id);
- }
- public void evictQueries(String cacheRegion) throws HibernateException {
- getHibernateSessionFactory().evictQueries(cacheRegion);
- }
- public void evictQueries() throws HibernateException {
- getHibernateSessionFactory().evictQueries();
- }
- public Set getDefinedFilterNames() {
- return getHibernateSessionFactory().getDefinedFilterNames();
- }
- public FilterDefinition getFilterDefinition(String filterName)
- throws HibernateException {
- return getHibernateSessionFactory().getFilterDefinition(filterName);
- }
- public boolean containsFetchProfileDefinition(String name) {
- return getHibernateSessionFactory().containsFetchProfileDefinition(name);
- }
- @Override
- public void setApplicationContext(ApplicationContext applicationContext)
- throws BeansException {
- this .applicationContext = applicationContext;
- }
- }
4. 配置动态SessionFactory
5. 定义DynamicTransactionManager继承HibernateTransactionManager
- public class DynamicTransactionManager extends HibernateTransactionManager {
- private static final long serialVersionUID = 1047039346475978451L;
- //重写getDataSource方法,实现动态获取
- public DataSource getDataSource() {
- DataSource sfds = SessionFactoryUtils.getDataSource(getSessionFactory());
- return sfds;
- }
- //重写getSessionFactory方法,实现动态获取SessionFactory
- public SessionFactory getSessionFactory() {
- DynamicSessionFactoryInf dynamicSessionFactory = (DynamicSessionFactoryInf) super
- .getSessionFactory();
- SessionFactory hibernateSessionFactory = dynamicSessionFactory
- .getHibernateSessionFactory();
- return hibernateSessionFactory;
- }
- //重写afterPropertiesSet,跳过数据源的初始化等操作
- public void afterPropertiesSet() {
- return ;
- }
- }
6. 配置dynamicTransactionManager
<bean id="dynamicTransactionManager" class="com.hp.it.qdpadmin.common.DynamicTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean>
7. 为SessionFactory配置事务切面
<tx:advice id="dynamicTxAdvice" transaction-manager="dynamicTransactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="*" propagation="REQUIRED" rollback-for="Exception" /> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:pointcut id="txPointcut" expression="execution(* com.service.*.*(..))"/> <aop:advisor advice-ref="dynamicTxAdvice" pointcut-ref="txPointcut" /> </aop:config>
发表评论
-
深入理解Spring MVC 3(三)
2013-07-20 19:30 1502十二、如何把全局异常记录到日志中? 在 前的配置中,其中有 ... -
深入理解Spring MVC 3(二)
2013-07-20 19:29 1336要写在DispatcherServlet的前面, 让 def ... -
深入理解Spring MVC 3(一)
2013-07-20 19:28 1733一、前言: 大家好,Spring3 MVC是非常优秀的MV ... -
Spring2.5中使用注解装配属性and组件自动扫描
2012-10-18 11:22 1103Spring2.5中使用注解装配属性 可在Jav ... -
spring中加载Bean配置文件的常用方式
2012-10-18 09:07 1263Spring中加载Bean配置文件的常用方式有两种,一种是通过 ... -
Spring常用注解,自动扫描装配Bean
2012-10-16 08:40 20251 引入context命名空间(在Spring的配置文件中), ... -
Spring Bean的5种作用域
2012-10-16 08:40 1125Spring Bean的5种作用域 ... -
初识 Spring 框架,进入Spring的世界
2012-10-19 10:15 1063一、SpringSource公司 S ... -
spring各jar包相着依赖关系
2011-03-25 08:21 1214spring.jar是包含有完整发布的单个jar包,s ...
相关推荐
在Spring4中集成Hibernate4和JPA,可以实现强大的数据持久化能力。Spring通过其声明式事务管理,使得事务处理变得简单。同时,Spring的JPA支持提供了Repository接口,使得数据访问如同操作普通的Java对象一样方便。...
在实际集成过程中,开发者需要配置Spring的Hibernate模板或JPA支持,创建SessionFactory或EntityManagerFactory,然后定义数据访问对象(DAO),并利用Spring的依赖注入将它们注入到业务服务(Service)中。...
在权限管理系统中,frameset常用来分割页面,如顶部导航、左侧菜单和主要内容区域,通过改变不同框架的内容来实现动态页面切换。 在本实例中,"purview_control"可能代表权限控制相关的类或配置文件。这通常涉及到...
7. 兼容性:Hibernate 3.2.6版本兼容Java 5及更高版本,并且可以与Spring框架等其他Java企业级开发工具集成,以实现更复杂的应用场景。 8. 性能优化:在3.2.6版本中,Hibernate已经进行了大量的性能优化,包括查询...
街道级行政区划shp矢量数据,wgs84坐标系,下载直接使用
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
街道级行政区划shp矢量数据,wgs84坐标系,下载直接使用
轻量级密码算法LBlock的FPGA优化实现.docx
街道级行政区划shp矢量数据,wgs84坐标系,下载直接使用
Git 资料 progit-zh-v2.1.1.pdf
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
篮球计分器FPGA附程序..doc
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
内容概要:本文档全面介绍了Linux开发的基础知识、应用场景、环境搭建、常用命令、Shell脚本编程以及C/C++和Python开发等内容。首先阐述了Linux开发的重要性及其在服务器端开发、嵌入式开发和系统运维等领域的广泛应用。接着详细讲解了如何选择合适的Linux发行版并安装系统,配置开发环境,包括安装必要的开发工具和配置SSH服务。文档还深入讲解了Linux基础命令,如文件和目录操作、文件内容查看与编辑、进程管理和权限管理。此外,介绍了Shell脚本编程的基本语法,包括变量、条件语句、循环语句和函数定义。针对C/C++和Python开发,文档分别讲解了编译器安装、程序编写与编译、调试方法及使用虚拟环境等内容。最后,简要介绍了Linux内核开发的相关知识,包括下载编译内核、内核模块开发等,并推荐了相关学习资源。 适合人群:对Linux开发感兴趣的初学者及有一定经验的研发人员,尤其是希望深入掌握Linux开发技能的开发者。 使用场景及目标:①掌握Linux开发环境的搭建与配置;②熟悉Linux基础命令和Shell脚本编程;③学习C/C++和Python在Linux下的开发流程;④了解Linux内核开发的基本概念和技术。 阅读建议:此文档内容丰富,涵盖面广,建议读者根据自身需求选择性阅读,并结合实际操作进行练习。特别是对于初学者,应先掌握基础命令和开发环境的搭建,再逐步深入到编程语言和内核开发的学习。
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
街道级行政区划shp数据,wgs84坐标系,直接使用。
内容概要:本文档《word练习题.docx》是一份详细的Word操作练习指南,涵盖了从基础到高级的各种功能。文档分为三个主要部分:内容编辑、页面布局和高效文档。内容编辑部分包括文本格式化、段落设置、项目编号、制表位、边框与底纹等练习;页面布局部分涉及分节符、分栏、页眉页脚、水印等设置;高效文档部分则聚焦于样式管理、导航窗格、题注、书签、超级链接、脚注与尾注、交叉引用等功能。每个练习都有具体的操作步骤,帮助用户掌握Word的各种实用技巧。 适合人群:适用于Word初学者及希望提高Word技能的中级用户,尤其是需要频繁使用Word进行文档编辑和排版的办公人员。 使用场景及目标:①帮助用户熟悉Word的基本操作,如文本编辑、格式设置等;②提升用户的文档排版能力,学会设置复杂的页面布局;③提高工作效率,掌握高效文档管理技巧,如样式应用、题注和交叉引用等。 其他说明:此文档不仅提供了具体的练习题目,还附带了详细的步骤说明,用户可以根据指引逐步完成每个练习。此外,文档中的一些练习涉及到智能文档和Office智能客户端的应用,有助于用户了解Word在企业级应用中的潜力。建议用户按照章节顺序逐步学习,实践每一个练习,以达到最佳的学习效果。
街道级行政区划shp数据,wgs84坐标系,直接下载使用。
全球腐败感知数据(2000-2023)——3000行 33个指标 关于数据集 该数据集包含3000行和33列,涵盖了2000年至2023年的腐败感知指数(CPI)数据和各种治理指标。它包括国家排名、分数和其他指标,如公共部门腐败、司法腐败、贿赂指数、商业道德、民主指数、法治、政府效率、经济指标和人类发展指数。 这些数据可用于: 腐败趋势分析 腐败对GDP、人类发展指数和治理的影响 跨国比较 数据可视化和机器学习模型 该数据集对研究人员、数据分析师、政策制定者和对研究全球腐败趋势非常有用。