首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Liferay同时连接多个数据库及其事务有关问题

2012-10-31 
Liferay同时连接多个数据库及其事务问题????Liferay运用的是spring框架,从早期版本开始,就可以同时连接多

Liferay同时连接多个数据库及其事务问题
????Liferay运用的是spring框架,从早期版本开始,就可以同时连接多个数据库应用,但是在Liferay的文档还是代码中都没有关于同时连接多个数据库的说明,从<st1:chsdate isrocdate="False" w:st="on" year="1899" day="30" islunardate="False" month="12">4.2.0</st1:chsdate>的版本开始出现了连接多个数据库的文档(请参照liferay wiki:http://wiki.liferay.com/index.php/Connecting_to_Another_Datasource/Database),代码中也有相应的明确定义。<o:p></o:p>

    ?????? 指定了多个不同的数据库,取得了不同的connection,那从不同的sessionfactory得到了不同的transaction instance,大家担心的就是分段式事务问题,而liferay的事务处理是由spring support的,我们可以先看看spring中的PlatformTransactionManager

      当程序由于事务问题抛出异常的时候,spring文档是这样描述的:
      ?

      Again in keeping with Spring's philosophy, the TransactionException that can be thrown by any of the<o:p></o:p>

      PlatformTransactionManager interface's methods is unchecked (i.e. it extends the<o:p></o:p>

      java.lang.RuntimeException class). Transaction infrastructure failures are almost invariably fatal. In rare<o:p></o:p>

      cases where application code can actually recover from a transaction failure, the application developer can still<o:p></o:p>

      choose to catch and handle TransactionException. The salient point is that developers are not forced to do so.

      ?

      <property name="jndiName">
      <value>jdbc/ErpBoPool</value>
      </property>
      </bean>
      <bean id="ErpBoDataSource" lazy-init="true">
      <property name="targetDataSource">
      <ref bean="ErpBoDataSourceTarget" />
      </property>
      </bean>
      <bean id="ErpBoSessionFactory" lazy-init="true">
      <property name="dataSource">
      <ref bean="ErpBoDataSource" />
      </property>
      </bean>
      接下去就不用多说了吧。早在以前的版本就可以实现的。如果大家有更好的办法请赐教!

      jotm咯 6 楼 devilbaby 2007-03-26   jotm可以是可以,但是不建议引入,因为引入一个开源项目有一定的风险,要考虑他的活动性,稳定性,还有兼容性等等,而且要考虑他对性能的影响,所以我觉得首先应该从设计上避免两个不同数据库间的交互,如果不能避免的话,我觉得还是用app server也不愿意引入一个新的开源项目

热点排行