BEA Aqualogic DSP實踐

 http://blog.csdn.net/wanbin021614/archive/2007/09/04/1771432.aspx

 

先介紹一下BEA的DSP,所謂DSP就是data service platform,是BEA近幾年推出的一個新產品,跟SOA架構有很緊密的聯繫,說簡單點就是SOA的獲取數據的那一層,這一層負責收集數據、整理數據並對外發布接口。

關於DSP其實BEA的DEV2DEV上有一個比較好的例子,但它的例子是基於weblogic自帶的pointbase內存數據庫爲基礎的,而實際中的數據源基本不可能使用pointbase,於是我個人最近兩天做了一個基於mysql的demo,更貼近實際一點。

下面就來就一步一步介紹創建和部署這個demo。

順便說一句,運行dsp至少要512M內存,推薦1G以上。

mysql的準備工作,新建一個schema名字叫VLS,然後新建幾張表:
emailTemplate(emailTemplateID int(PK), emailTemplateName varchar)
emailTemplatePack(emailTemplatePackID int(PK), emailTemplatePackName varchar)
emailTemplateBridge(emailTemplateID int, emailTemplatePackID int)
其中emailTemplate就是一個郵件的內容定義,emailTemplatePack就是定義一組郵件,在我的項目中就是定義一個課程全過程中的郵件,包括課程創建提醒,課程確認,課程時間提醒1、2、3之類的,emailTemplateBridge是定義兩張表的多對多的關係。兩個ID都是FK。數據自己隨便輸點。

下載bea weblogic 8.1.6 platform並安裝到默認目錄。
下載data service platform並安裝,目前的版本是2.5。
這兩個下載的地址在[url=http://dev2dev.bea.com]http://dev2dev.bea.com[/url] 自己去找吧。
下載mysql的driver,並複製到C:/bea/weblogic81/server/lib中。這步是一定要有的,很奇怪的是BEA並沒有在自己的lib目錄裏面附帶對應數據庫的driver文件,或許是我沒有找到。

設置環境變量,修改C:/bea/weblogic81/common/bin/commEnv.cmd,找到這句設置WEBLOGIC_CLASSPATH的環境變量
set WEBLOGIC_CLASSPATH=%JAVA_HOME%/lib/tools.jar;%WL_HOME%/server/lib/weblogic_sp.jar;
在後面加上%WL_HOME%/server/lib/weblogic.jar;%WL_HOME%/server/lib/mysql-connector-java-3.0.15-ga-bin.jar
(我下載的mysql driver是mysql-connector-java-3.0.15-ga-bin.jar),當然,你可以把這個driver放到其他classpath中。
保存並關閉文件。

打開bea workshop,新建一個data service application,使用默認的weblogic server,名字叫VLS,我是根據我手上的一個項目來作例子,名字也就使用原來項目的名字了。建好以後,會自動建一個dataservices的項目。
一般情況下可以使用這個默認的ds項目,但個人更喜歡建一個新的項目。鼠標右鍵點擊VLS也就是最頂層的application,彈出菜單中有一個new,二級菜單中單擊project,彈出菜單如圖。

修改名字爲EmailTemplate,這個DS項目依照VLS項目中的郵件功能部分作爲原型。
右鍵EmailTemplate這個DS項目然後新建兩個文件夾,一個叫DS,一個叫Model。建好以後的項目結構圖如下:

右鍵DS這個文件夾,然後選擇Import Source Meta這個項目。如圖:

點擊後彈出的頁面如圖:

點next按鈕,如果在開始沒有啓動weblogic server,這個時候會彈出一個對話框讓你啓動weblogic server,點確定就可以了。這個時候就會啓動server,過程比較長,慢慢等吧。

當彈出的dos窗口中出現這樣的文字
server started in running mode的時候,server就啓動成功了。

下一個頁面就是選擇你要import的data source,默認的一般是pointbase自帶的cgDataSource這個pool

點擊頁面上的new按鈕,會彈出data source viewer來查看現有的已經配置好的data source pool和pool中的data source

點擊當前頁面的左下角的New data source按鈕,彈出一個新建data source的對話框

在Pool的下拉菜單中選擇<Create new pool>來新建一個pool,然後下面的這些Pool Name, Driver等就會被激活,可以進行修改,在Driver下面選擇com.mysql.jdbc.Driver這個,然後URL就會出現一個template: jdbc:mysql://<localhost>:3306/<databasename>,把IP地址和數據庫名字填寫好以後就可以使用了。

新建好以後,就可以在第一個select data source中選擇剛剛建立好的data source了。

 data service分成兩種,一種是物理意義上的數據服務,就像email template這種直接從數據庫獲取數據的服務。還有一種是邏輯服務。我們接下來作的就是根據物理數據服務定製自己想要的邏輯服務。

在model文件夾裏新建一個Model Diagram,名字叫EmailTemplate.md

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="" src="http://lh3.google.com/wanbin021614/RtKBsAT4wQI/AAAAAAAABUI/1KteRvV_AkM/create%20model%20diagram.JPG?imgmax=800" οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0>



然後把emailTemplate那三個DS都拖入到這個model diagram裏面來,就可以一次性看到三者的關係

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="Click here to open new window CTRL+Mouse wheel to zoom in/out" src="http://lh4.google.com/wanbin021614/RtKBsQT4wRI/AAAAAAAABUQ/cBe_U6eVE00/email%20tempalte%20model%20diagram.JPG?imgmax=800" width=716 οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0 resized="true">

右鍵EmailTemplate,然後新建一個DS,名字叫emailTemplateList
screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="" src="http://lh5.google.com/wanbin021614/RtKBsgT4wSI/AAAAAAAABUY/x7BbTfOQDec/create%20new%20ds.JPG?imgmax=800" οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0>


右鍵空白區域,選擇Create xml type,會彈出一個菜單,點擊create就可以。然後彈出一個對話框:

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="" src="http://lh6.google.com/wanbin021614/RtKBswT4wTI/AAAAAAAABUg/MfeiI5fTU68/create%20new%20schema%20file.JPG?imgmax=800" οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0>

如果emailTemplateList.xsd不在schemas文件夾裏,就把它拖進去。

雙擊emailTempalteList.ds,裏面只有一個root元素emailTemplateList,需要我們自己來修改xsd文件從而來獲得想要的數據格式。

右鍵點擊emailTemplate這個根元素,然後選擇Add Child--->Element,這樣添加三個element,分別是emailTemplatePackID和emailTemplatePackName還有emailTemplateList,然後右鍵點擊emailTemplateList再以它爲父結點加入幾個新element,這些element名字可以參考emailTemplate的定義。簡單一點就直接把emailTemplate下面的東西複製過去。

這樣新建好的emailTemplateList.ds就是這個樣子的

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="" src="http://lh4.google.com/wanbin021614/RtLfwQT4wZI/AAAAAAAABVo/FgWDicqPVXI/email%20pack%20design.JPG?imgmax=800" οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0>

而emailTemplateList.xsd的內容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema targetNamespace="ld:EmailTemplate/emailtemplatelist" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  
<xs:element name="emailtemplatelist">
    
<xs:complexType>
      
<xs:sequence>
        
<xs:element name="emailTemplatePackID"/>
        
<xs:element name="emailTemplatePackName"/>
        
<xs:element name="EmailTemplateList">
          
<xs:complexType>
            
<xs:sequence>
              
<xs:element name="emailTemplate" minOccurs="0" maxOccurs="unbounded">
                
<xs:complexType>
                  
<xs:sequence>
                    
<xs:element name="emailTemplateID" type="xs:int"/>
                    
<xs:element name="emailTemplateTriggerName" type="xs:string" minOccurs="0"/>
                    
<xs:element name="emailTemplateSendMode" type="xs:int"/>
                    
<xs:element name="emailTemplateSubject" type="xs:string" minOccurs="0"/>
                    
<xs:element name="emailTemplateText" type="xs:string" minOccurs="0"/>
                    
<xs:element name="emailTemplateDaysThreshold" type="xs:int" minOccurs="0"/>
                    
<xs:element name="emailTemplateCCAddress" type="xs:string" minOccurs="0"/>
                    
<xs:element name="emailTemplateBCCAddress" type="xs:string" minOccurs="0"/>
                  
</xs:sequence>
                
</xs:complexType>
              
</xs:element>
            
</xs:sequence>
          
</xs:complexType>
        
</xs:element>
      
</xs:sequence>
    
</xs:complexType>
  
</xs:element>
</xs:schema>


還記得如何建一個新的函數吧,不記得了就看上面的步驟,在emailTemplateList.ds裏新建一個函數名叫getEmailTemplatePack,這次我們要不光返回一個emailTemplatePack,還要把它所有包含的emailTemplate全部返回。

建好函數以後,單擊函數,進入XQuery Editor View,最原始的是隻有return

接下來幾步是拖動DS到這個editor裏。

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="" src="http://lh6.google.com/wanbin021614/RtLfuwT4wWI/AAAAAAAABVQ/yJEuEP56v_4/ds%20palette%20final.JPG?imgmax=800" οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0>

先把emailTemplatePack裏的emailTemplatePack()函數拖入到這個窗口裏面,然後把emailTemplatePackID和emailTemplatePackName對應。記得是從For往return裏面拖。
然後把emailTemplate這個DS裏的emailTemplate()函數拖入這個窗口裏面,把emailTemplate裏面的元素一一對應
最後把emailTemplateBridge的emailTemplateBridge()拖入窗口裏。

把emailTemplateBridge/emailTemplatePackID和return 裏面的emailTemplatePackID對應。
把emailTemplatePack/emailTemplatePackID和emailTemplateBridge/emailTemplatePackID對應
把emailTemplateBridge/emailTemplateID和emailTemplate/emailTemplateID對應。

這幾個步驟可能比較煩,細心點。然後檢查下源代碼,代碼應該跟下面的一樣,不一樣的可以自己手動修改一下

declare namespace ns17="ld:EmailTemplate/emailtemplatebridge";
declare namespace ns16="ld:EmailTemplate/emailtemplate";
declare namespace ns15="ld:EmailTemplate/emailtemplatepack";
import schema namespace ns11="ld:EmailTemplate/emailtemplatelist" at "ld:EmailTemplate/schemas/emailtemplatelist.xsd";
declare namespace ns14="ld:EmailTemplate/emailtemplatelist";
...
declare function ns14:getEmailTemplatePack() as element(ns11:emailtemplatelist)* {
    
for $emailtemplatepack in ns15:emailtemplatepack()
return
<ns11:emailtemplatelist>
        
<emailTemplatePackID>{fn:data($emailtemplatepack/emailTemplatePackID)}</emailTemplatePackID>
        
<emailTemplatePackName>{fn:data($emailtemplatepack/emailTemplatePackName)}</emailTemplatePackName>
        
<EmailTemplateList>
            {
                for $emailtemplatebridge in ns17:emailtemplatebridge()
                where $emailtemplatepack/emailTemplatePackID = $emailtemplatebridge/emailTemplatePackID
                for $emailtemplate in ns16:emailtemplate()
                where $emailtemplatebridge/emailTemplateID = $emailtemplate/emailTemplateID
                return
                
<emailTemplate?>
                    
<emailTemplateID>{fn:data($emailtemplate/emailTemplateID)}</emailTemplateID>
                    
<emailTemplateTriggerName?>{fn:data($emailtemplate/emailTemplateTriggerName)}</emailTemplateTriggerName>
                    
<emailTemplateSendMode>{fn:data($emailtemplate/emailTemplateSendMode)}</emailTemplateSendMode>
                    
<emailTemplateSubject?>{fn:data($emailtemplate/emailTemplateSubject)}</emailTemplateSubject>
                    
<emailTemplateText?>{fn:data($emailtemplate/emailTemplateText)}</emailTemplateText>
                    
<emailTemplateDaysThreshold?>{fn:data($emailtemplate/emailTemplateDaysThreshold)}</emailTemplateDaysThreshold>
                    
<emailTemplateCCAddress?>{fn:data($emailtemplate/emailTemplateCCAddress)}</emailTemplateCCAddress>
                    
<emailTemplateBCCAddress?>{fn:data($emailtemplate/emailTemplateBCCAddress)}</emailTemplateBCCAddress>
                
</emailTemplate>
            }
        
</EmailTemplateList>
    
</ns11:emailtemplatelist>

這個是標準的XQuery的程序,前幾步是聲名namespace,函數裏面首先對emailTemplatePack進行循環,在第二級對emailTemplateBridge進行循環,如果兩個packID相等就得到emailTemplateID,然後循環完畢就組成一個新的xml文件。

修改好源代碼後再返回xquery editor view,頁面顯示如下:

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="Click here to open new window CTRL+Mouse wheel to zoom in/out" src="http://lh3.google.com/wanbin021614/RtLfwAT4wYI/AAAAAAAABVg/iJkb62mH3-4/XQuery%20Editor%20final.JPG?imgmax=800" width=716 οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0 resized="true">


最後進入Test View,點擊execute,顯示結果,我的結果如下:

screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open(this.src);}" alt="Click here to open new window CTRL+Mouse wheel to zoom in/out" src="http://lh5.google.com/wanbin021614/RtLfvgT4wXI/AAAAAAAABVY/eOV6SDYS4QU/email%20pack%20result.JPG?imgmax=800" width=716 οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" border=0 resized="true">

可以看到每個emailTemplatePack根據多對多的關係建立起一個email group


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章