<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Connect to second database in Liferay(連接第二個(gè)數(shù)據(jù)庫(kù))

    同時(shí)連接兩個(gè)數(shù)據(jù)庫(kù),連接多個(gè)數(shù)據(jù)庫(kù)

    這是我自己研究出來(lái)的,真的可以說(shuō)是世界首發(fā)了,網(wǎng)上也有一些例子,都要么就是老版本,要么就特復(fù)雜。我的這個(gè)方法特簡(jiǎn)單,希望對(duì)大家有用,也希望大家珍惜

    因?yàn)楣镜男枰苯訉懙挠⑽陌娴模幌朐俜g回來(lái)了。都不難理解,一看就能明白。不懂的請(qǐng)留言

    Introduction

                    First of all, I should say that setting liferay to connect to another database is very easy. Certainty, all of things to make easy always after numerous attempts . I searched several solutions from website before. But, not only for old version but also too complex.  As my understand  According to original source, and several trial. I found the way. And I think that it is the World Premiere.^_^

     

    Prerequisites

    You should know how to create services with Service Builder, Also You should know how to create new portlet. how to link to database and  how it is used inside programming language code.

    The steps described here were performed over Liferay 6.0.6.

     

     

    Let us Beginning

    1.       Create a file named portal-ext.properties in {WEBSERVER-HOME}\webapps\ROOT\WEB-INF\classes. And type the following code:

        #
        # MySQL
        #
        jdbc.default.driverClassName
    =com.mysql.jdbc.Driver
        jdbc.default.url
    =jdbc:mysql://localhost/lfportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
        jdbc.default.username
    =root
        jdbc.default.password
    =root  
      
        #
        # This is the second connection
        #
        jdbc.second.driverClassName
    =net.sourceforge.jtds.jdbc.Driver
        jdbc.second.url
    =jdbc:jtds:sqlserver://localhost:1433/extraDB
        jdbc.second.username
    =sa
        jdbc.second.password
    =test

     

    2.       Create a service.xml file. And type the following code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
    <service-builder package-path="com.test">
        
    <author>noah.xiang</author>
        
    <namespace>nx</namespace>

        
    <entity name="MyTable" local-service="true" remote-service="false" table="myTable" data-source="secondDataSource" session-factory="secondSessionFactory" tx-manager="secondTransactionManager">
            
    <!-- PK fields -->

            
    <column name="id" type="int" primary="true" />

            
    <!-- Audit fields -->

            
    <column name="jahr" type="Date" mapping-key="[Jahr]"/>
            
    <column name="beschaffungsstrategie" type="String"  mapping-key="[Beschaffungsstrategie]"/>
            
    <column name="buchVon" type="String" mapping-key="[Buch von]"/>
            
        
    </entity>
    </service-builder>

     

    3.       Ant build-service.xml, let liferay to generate code.

    4.       Create a new file named ext-spring.xml in src\META-INF folder. And copy the following code:

     

    <?xml version="1.0"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        
    <bean id="secondDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" lazy-init="true">
            
    <property name="targetDataSource">
                
    <bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
                    
    <property name="propertyPrefix" value="jdbc.second." />
                
    </bean>
            
    </property>
        
    </bean>
        
    <bean id="secondHibernateSessionFactory" class="com.liferay.portal.spring.hibernate.PortalHibernateConfiguration" lazy-init="true">
            
    <property name="dataSource">
                
    <ref bean="secondDataSource" />
            
    </property>
            
    <property name="mappingResources">
                
    <list>
                    
    <value>META-INF/portlet-hbm.xml</value>
                
    </list>
            
    </property>
        
    </bean>
        
    <bean id="secondSessionFactory" class="com.liferay.portal.dao.orm.hibernate.SessionFactoryImpl" lazy-init="true">
            
    <property name="sessionFactoryImplementor">
                
    <ref bean="secondHibernateSessionFactory" />
            
    </property>
        
    </bean>
        
    <bean id="secondTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
            
    <property name="dataSource">
                
    <ref bean="secondDataSource" />
            
    </property>
            
    <property name="sessionFactory">
                
    <ref bean="secondHibernateSessionFactory" />
            
    </property>
        
    </bean>
    </beans>

     

    5.       No more. So easy right? About how to call and deploy it. I believe that you can do.

     



    眼鏡蛇

    posted on 2011-10-27 17:56 眼鏡蛇 閱讀(1434) 評(píng)論(6)  編輯  收藏 所屬分類: Liferay

    評(píng)論

    # re: Connect to second database in Liferay(連接第二個(gè)數(shù)據(jù)庫(kù)) 2012-03-01 14:31 彭維

    234148464 qq求助!實(shí)在是運(yùn)行不通。。。  回復(fù)  更多評(píng)論   

    # re: Connect to second database in Liferay(連接第二個(gè)數(shù)據(jù)庫(kù)) 2012-03-02 12:24 Noah

    哪里不通  回復(fù)  更多評(píng)論   

    # re: Connect to second database in Liferay(連接第二個(gè)數(shù)據(jù)庫(kù)) 2012-03-05 10:45 彭維

    研究了一天,完全讓你的做的,不過(guò)板本是6.1,行不通,求大神賜教。。。I need your help,service builder的時(shí)候不能夠生成表,跟本連不到另一個(gè)數(shù)據(jù)源上面去。。  回復(fù)  更多評(píng)論   

    # re: Connect to second database in Liferay(連接第二個(gè)數(shù)據(jù)庫(kù)) 2012-03-05 10:51 彭維

    I am so sad! for a long time ,just bcz of this porblem.....,  回復(fù)  更多評(píng)論   

    # re: Connect to second database in Liferay(連接第二個(gè)數(shù)據(jù)庫(kù)) 2012-03-20 21:50 Noah

    @彭維
    如果是6.1的話,需要修改 com.liferay.portal.spring.hibernate.PortalHibernateConfiguration

    com.liferay.portal.spring.hibernate.PortletHibernateConfiguration  回復(fù)  更多評(píng)論   

    # re: Connect to second database in Liferay(連接第二個(gè)數(shù)據(jù)庫(kù))[未登錄](méi) 2013-01-30 18:08 Owen

    跨兩個(gè)db要怎樣做transaction

    按照你這樣的寫法,如果拋出exception,只會(huì)有其中一個(gè)DB ROLLBACK,另一個(gè)db不會(huì)rollback,有什麼好解法嗎?

    jta or jotm,這兩個(gè)還要研究看看怎樣用在liferay上面  回復(fù)  更多評(píng)論   

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产线视频精品免费观看视频| 亚洲国产成+人+综合| 毛片亚洲AV无码精品国产午夜| 亚洲成在人线aⅴ免费毛片| 最近中文字幕免费2019| 日产乱码一卡二卡三免费| 中国china体内裑精亚洲日本| 57PAO成人国产永久免费视频| 亚洲白色白色在线播放| 国产精品69白浆在线观看免费 | a级毛片免费全部播放无码| 一本色道久久综合亚洲精品高清| 欧洲美女大片免费播放器视频| 亚洲国产人成精品| 一边摸一边爽一边叫床免费视频 | 精品亚洲麻豆1区2区3区| 午夜免费1000部| 亚洲欧美成aⅴ人在线观看| 精品久久洲久久久久护士免费| 日韩成人精品日本亚洲| 亚洲电影日韩精品| 久久免费国产精品一区二区| 亚洲一区二区电影| 黄瓜视频高清在线看免费下载| 亚洲日韩AV一区二区三区四区| 亚洲精品无码久久久久AV麻豆| 国产线视频精品免费观看视频| 亚洲人成影院午夜网站| 国产真人无遮挡作爱免费视频| 亚洲视频小说图片| 最新69国产成人精品免费视频动漫| 十八禁的黄污污免费网站| 久久精品亚洲综合| 永久免费看bbb| 拍拍拍无挡视频免费观看1000| 亚洲国产精品日韩在线观看| 热99re久久免费视精品频软件| 精品无码一级毛片免费视频观看| 亚洲女人影院想要爱| 亚洲国产精品无码久久久久久曰| 99久热只有精品视频免费观看17|