动态更改会话工厂和Txm Manager以支持I18N [英] Dynamically changing session factory and Txm Manager for I18N support

查看:114
本文介绍了动态更改会话工厂和Txm Manager以支持I18N的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们正在构建的Spring-GWT应用程序中,我有一个特殊的问题。我们有一个不支持UTF-8的WE8ISO8859P1字符集编码的oracle数据库。因此,我们正在AL32UTF8字符集中构建一个新的数据库。不幸的是,数据库管理员不想将现有的数据库迁移到新的数据库中,我们必须到达旧数据库的英文数据和新数据库的拉丁数据。



我们在方法/类级别具有@Transactional注释,并将sessionFactory注入到DAO中以连接到休眠。我想在用户选择拉丁类似的东西时重用这些东西,比如

@Transactional(changeThisDynamically)

即TransactionManager而当用户在拉丁/英语之间切换时,注入的SessionFactory应该通过Ajax调用动态更改。



可以这样做吗?解决这个问题的最好方法是什么?

第二个想法是,我可以通过创建Bean ApplicationContextAware来获得拉丁会话工厂,并将其设置为dao但是这是一个好方法?我该如何处理TransactionManager?



谢谢,

解决方案

感谢您的帮助。我真正需要的是一个'AbstractRoutingDataSource' - 我通过执行以下操作来解决这个问题:

 < bean id =dataSourceclass = com.myPackage.CustomRoutingDataSource > 
< property name =targetDataSources>
< map key-type =com.myPackage.DBLocaleEnum>
< entry key =Englishvalue-ref =defaultDataSource/>
< entry key =Spanishvalue-ref =latinDataSource/>
< / map>
< / property>
< property name =defaultTargetDataSourceref =defaultDataSource/>
< / bean>

public class CustomRoutingDataSource extends AbstractRoutingDataSource {
$ b @Override
protected Object determineCurrentLookupKey(){

DBLocaleEnum localeType = LocaleContextHolder.getLocaleType() ;
返回localeType;
}

判断当前的方法的返回类型可以帮助我确定应该使用哪个数据源。

I have a peculiar issue here in the Spring-GWT application we are building. We have an oracle DB encoded in WE8ISO8859P1 character set which doesn't support UTF-8 . Hence we are building a new DB in AL32UTF8 char set . Unfortunately the DBAs do not want to migrate the existing DB to the new DB and we have to reach the old DB for the English data and the new DB for the Latin data .

We have @Transactional annotations at method/class level and the sessionFactory is injected into the DAO to connect to hibernate. I want to reuse these when user selects latin something like

@Transactional(changeThisDynamically)

i.e, the TransactionManager and SessionFactory injected should change dynamically via an Ajax call when the user switches between Latin/English.

Can this be done? What is is the best approach to resolve this ?

On second thought, I could get the Latin session factory by making the bean ApplicationContextAware and set this in the dao but but is this a good approach ? and what do I do with the TransactionManager ?

Thanks,

解决方案

Thanks for all your help. What I really needed was an 'AbstractRoutingDataSource' - I fixed this by doing the following

    <bean id="dataSource" class="com.myPackage.CustomRoutingDataSource">
   <property name="targetDataSources">
      <map key-type="com.myPackage.DBLocaleEnum">
         <entry key="English" value-ref="defaultDataSource"/>
         <entry key="Spanish" value-ref="latinDataSource"/>
      </map>
   </property>
   <property name="defaultTargetDataSource" ref="defaultDataSource"/>
</bean>

public class CustomRoutingDataSource extends AbstractRoutingDataSource {

@Override
protected Object determineCurrentLookupKey() {

    DBLocaleEnum localeType = LocaleContextHolder.getLocaleType();
    return localeType;
}

The return type of determineCurrentLookupKey method helps me determine which datasource I should be using .

这篇关于动态更改会话工厂和Txm Manager以支持I18N的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆