<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(連接第二個數據庫)

    同時連接兩個數據庫,連接多個數據庫

    這是我自己研究出來的,真的可以說是世界首發了,網上也有一些例子,都要么就是老版本,要么就特復雜。我的這個方法特簡單,希望對大家有用,也希望大家珍惜

    因為公司的需要,直接寫的英文版的,不想再翻譯回來了。都不難理解,一看就能明白。不懂的請留言

    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 眼鏡蛇 閱讀(1420) 評論(6)  編輯  收藏 所屬分類: Liferay

    評論

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

    234148464 qq求助!實在是運行不通。。。  回復  更多評論   

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

    哪里不通  回復  更多評論   

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

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

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

    I am so sad! for a long time ,just bcz of this porblem.....,  回復  更多評論   

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

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

    com.liferay.portal.spring.hibernate.PortletHibernateConfiguration  回復  更多評論   

    # re: Connect to second database in Liferay(連接第二個數據庫)[未登錄] 2013-01-30 18:08 Owen

    跨兩個db要怎樣做transaction

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

    jta or jotm,這兩個還要研究看看怎樣用在liferay上面  回復  更多評論   

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 激情五月亚洲色图| 亚洲第一成年人网站| 老司机亚洲精品影院在线观看| 成人福利免费视频| 欧洲 亚洲 国产图片综合| 毛片免费全部播放一级| 亚洲精品av无码喷奶水糖心| 日韩免费电影在线观看| 特级毛片A级毛片100免费播放| 国产在线播放免费| 一区二区三区免费视频播放器| 亚洲天堂在线视频| 日本高清免费观看| 91亚洲自偷在线观看国产馆| 我要看免费的毛片| 乱淫片免费影院观看| 亚洲国产精品无码久久久秋霞2| 亚洲免费在线播放| 亚洲第一成人在线| 天堂亚洲免费视频| 毛片在线全部免费观看| 亚洲av日韩av综合| 五月天婷亚洲天综合网精品偷| 在线观看免费视频网站色| 久久久久久亚洲AV无码专区| 99久久久国产精品免费无卡顿| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 亚洲国产高清在线| 久久天天躁狠狠躁夜夜免费观看| 亚洲欧美日韩中文字幕在线一区| 免费观看午夜在线欧差毛片 | sss在线观看免费高清| 亚洲一本综合久久| 午夜dj免费在线观看| 国产特黄一级一片免费| 亚洲在成人网在线看| 亚洲不卡AV影片在线播放| 91av视频免费在线观看| 曰批全过程免费视频免费看| 亚洲一区二区三区夜色| 在线观看亚洲免费|