




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、成成 都都 信信 息息 工工 程程 學(xué)學(xué) 院院 學(xué)學(xué) 位位 論論 文文 面向?qū)ο蟮臄?shù)據(jù)建模面向?qū)ο蟮臄?shù)據(jù)建模 數(shù)據(jù)篩選接口的設(shè)計(jì)數(shù)據(jù)篩選接口的設(shè)計(jì) 論文作者姓名:論文作者姓名: 申請(qǐng)學(xué)位專業(yè):申請(qǐng)學(xué)位專業(yè): 申請(qǐng)學(xué)位類別:申請(qǐng)學(xué)位類別: 指指導(dǎo)導(dǎo)教教師師姓姓名名(職職稱稱) : 論文提交日期:論文提交日期: 面向?qū)ο蟮臄?shù)據(jù)建模面向?qū)ο蟮臄?shù)據(jù)建模 數(shù)據(jù)篩選接口的設(shè)計(jì)數(shù)據(jù)篩選接口的設(shè)計(jì) 摘摘 要要 wise 系統(tǒng)是一個(gè)功能強(qiáng)大的數(shù)據(jù)處理系統(tǒng)。它應(yīng)用于某公司,此公 司由于行業(yè)的關(guān)系需要它去處理龐大的數(shù)據(jù),這些數(shù)據(jù)每天都在以上百萬(wàn)條甚 至上億條的數(shù)量在增加。因此它需要處理海量的數(shù)據(jù),它的其中一個(gè)比較重
2、要 的功能是根據(jù)復(fù)雜并且靈活的條件篩選出適當(dāng)?shù)臄?shù)據(jù)返回給客戶。本論文主要 講述了如何針對(duì)數(shù)據(jù)篩選條件比較復(fù)雜并且比較靈活這一需求,在做了詳盡的 需求分析之后,進(jìn)行了一系列的設(shè)計(jì),包括解決方案的設(shè)計(jì),數(shù)據(jù)建模, pl/sql 程序設(shè)計(jì),最終完成整個(gè)數(shù)據(jù)篩選接口的設(shè)計(jì)。在整個(gè)數(shù)據(jù)篩選接口的 設(shè)計(jì)中,在傳統(tǒng)的關(guān)系性數(shù)據(jù)庫(kù)的基礎(chǔ)上,會(huì)嘗試著應(yīng)用一些面向?qū)ο蟮乃枷?去設(shè)計(jì)。尤其在數(shù)據(jù)建模階段,通過(guò)傳統(tǒng)的數(shù)據(jù)模型之間的關(guān)系,例如主外鍵關(guān)系,實(shí) 現(xiàn)了一些重要的面向?qū)ο蟮乃枷搿?關(guān)鍵字關(guān)鍵字:數(shù)據(jù)篩選;面向?qū)ο?;?shù)據(jù)建模;pl/sql implement the object oriented thinkin
3、g in the project to data modeling the design about the api to filter data abstract the wise system is a powerful system for data processing .it is applied in a company which needs to use this system to process huge amount data. and these data will be increased by millions or hundreds millions. so it
4、 needs to process the huge amount data .one of its important function is return the right data to client filtered by some complex and flexible conditions. the most content of the paper talks about how to finish the total design for the requirement which is the conditions to filter data can be comple
5、x and flexible. the entire design will include the design of project to solve problem, the design about data modeling, and the design about pl/sql program. finally the all designs to implement the interface for filtering the data are finished .we will try implementing the object oriented thinking to
6、 design on the base of the relational database in the process to finish all the design. especially in the process to implement data modeling, we will implement some important object oriented thinking by some relations among traditional data models, such as pk or fk relationship. key words: data filt
7、ration;object oriented;data modeling;pl/sql 目目 錄錄 論文總頁(yè)數(shù):24 頁(yè) 1 引 言.1 2 開(kāi)發(fā)概述.1 3 需求分析.1 31 需求調(diào)研.1 32 開(kāi)發(fā)運(yùn)行環(huán)境.3 4 解決方案的設(shè)計(jì).3 5 數(shù)據(jù)建模.8 5.1 數(shù)據(jù)模型的建立.8 5.2 數(shù)據(jù)庫(kù)表結(jié)構(gòu)的設(shè)計(jì).9 5.3 數(shù)據(jù)庫(kù)基礎(chǔ)視圖的設(shè)計(jì).11 6 pl/sql 程序設(shè)計(jì).12 結(jié) 論.22 參考文獻(xiàn).22 致 謝.23 聲 明.24 1 1 引引 言言 當(dāng)今社會(huì),某些行業(yè)的數(shù)據(jù)量越來(lái)越龐大,每天都在以上百萬(wàn)條甚至上億 條的數(shù)量在增加,因此對(duì)這些行業(yè)的數(shù)據(jù)處理系統(tǒng)的性能要求也越來(lái)越高。
8、這 些要求不但包括處理速度盡可能快,系統(tǒng)可維護(hù)性盡可能高等傳統(tǒng)需求,而且 增加了對(duì)數(shù)據(jù)的處理盡可能的靈活等一些新的需求。要滿足這些新的需求,我 們需要研究這些新需求的特性,挖掘一些解決辦法。面向?qū)ο蟮臄?shù)據(jù)建模是我 們研究的一個(gè)重要方向。 引用言論:steve hoberman 所提出的“抽象組件”的概念和面向?qū)ο笤O(shè)計(jì) 中的“設(shè)計(jì)模式”非常類似。即數(shù)據(jù)庫(kù)專家在多次的數(shù)據(jù)建模后,將各個(gè)項(xiàng)目 中的類似部分抽象化,提取出特定的建模模型片段,以后只需在新的項(xiàng)目中對(duì) 這些模型片段細(xì)化派生,即可快速構(gòu)建出適合于該項(xiàng)目的數(shù)據(jù)庫(kù)架構(gòu)。 2 2 開(kāi)發(fā)概述開(kāi)發(fā)概述 wise 系統(tǒng)是一個(gè)功能強(qiáng)大的數(shù)據(jù)處理系統(tǒng)。由于業(yè)
9、務(wù)的關(guān)系,它需要 處理海量的數(shù)據(jù),它的比較重要的一個(gè)功能是根據(jù)復(fù)雜并且靈活的條件篩選出 適當(dāng)?shù)臄?shù)據(jù)返回給客戶。 針對(duì)這一數(shù)據(jù)篩選功能,開(kāi)發(fā)的目標(biāo)是設(shè)計(jì)一個(gè)合理的數(shù)據(jù)篩選接口。接 口能做到便于動(dòng)態(tài)控制,便于動(dòng)態(tài)修改,以及便于維護(hù)。 開(kāi)發(fā)的過(guò)程包括需求分析,解決方案的設(shè)計(jì),數(shù)據(jù)建模,pl/sql 程序設(shè)計(jì), 最終完成整個(gè)數(shù)據(jù)篩選接口的設(shè)計(jì)。 3 3 需求分析需求分析 3 31 1 需求調(diào)研需求調(diào)研 wise 系統(tǒng)是某公司的數(shù)據(jù)處理系統(tǒng),它的一個(gè)主要功能是每天根據(jù)復(fù)雜并 且靈活的條件篩選出適當(dāng)?shù)臄?shù)據(jù)返回給客戶。所篩選的數(shù)據(jù)都來(lái)自于一張表, 這張表的字段有 260 個(gè),這些字段中有超過(guò) 250 個(gè)字段
10、需要作為篩選字段,它 們通常互為組合去篩選出客戶需要的數(shù)據(jù),根據(jù)客戶的需要它們的組合又是多 變的。這張表的數(shù)據(jù)量通常在一千萬(wàn)到一億條記錄之間。值得注意的是,篩選 條件需要去匹配的值是具有特定意義的,盡管這些值數(shù)目眾多,但它們的數(shù)量 不是隨意增長(zhǎng)的。而且這些值是根據(jù)客戶的需求可以去定制的。 表 1 復(fù)雜表 complexity 字段名數(shù)據(jù)類型說(shuō)明 c_id 數(shù)字主鍵 c_u1 文本 c_u2 文本 c_u13 文本 c_u4 貨幣 c_u5 數(shù)字 c_u6 貨幣 c_u7 文本 c_u8 貨幣 c_u9 文本 c_u10 貨幣 c_u11 文本 c_u12 文本 c_u13 日期/時(shí)間 c_u1
11、4 日期/時(shí)間 c_u15 數(shù)字 c_u16 數(shù)字 c_u17 文本 c_u18 文本 c_u19 文本 c_u20 貨幣 c_u21 數(shù)字 c_u22 貨幣 c_u23 文本 c_u24 貨幣 c_u25 文本 等等一共 260 個(gè)字段 因此對(duì)數(shù)據(jù)篩選的需求特點(diǎn)主要有: 數(shù)據(jù)篩選需求特點(diǎn) 數(shù)據(jù)量龐大 來(lái)自于一張表,表的字段較多,大多 數(shù)為篩選字段 篩選字段通常組合,組合較為靈活 篩選列去需要去匹配的值,有特定 意義,客戶可以定制 圖 1 需求特點(diǎn)分析圖 數(shù)據(jù)量龐大在這里不是本次設(shè)計(jì)的研究重點(diǎn),后三個(gè)特點(diǎn)是本次設(shè)計(jì)要解 決好的需求。 3 32 2 開(kāi)發(fā)運(yùn)行環(huán)境開(kāi)發(fā)運(yùn)行環(huán)境 開(kāi)發(fā)所需的基本軟、硬
12、件環(huán)境為: windows 2003 或者 windows xp。 oracle 10 g r2。 cpu 2.40ghz 1g 以上內(nèi)存。 2g 以上可用硬盤(pán)空間。 在 windows 2003 操作系統(tǒng)下,以 toad for oracle xpert v 為開(kāi) 發(fā)工具,用 oracle 10 g r2 為后臺(tái)數(shù)據(jù)庫(kù)。 4 4 解決方案的設(shè)計(jì)解決方案的設(shè)計(jì) 在這里來(lái)逐步分析需求應(yīng)該通過(guò)怎樣的方式來(lái)實(shí)現(xiàn),進(jìn)行一些解決方案的 設(shè)計(jì)。 方案方案 1 1 :直接寫(xiě)過(guò)程來(lái)實(shí)現(xiàn)。 根據(jù)不同的篩選條件,寫(xiě)不同的過(guò)程來(lái)實(shí)現(xiàn)數(shù)據(jù)篩選。 問(wèn)題:很顯然,這種方案是行不通的。由于篩選字段數(shù)量達(dá)兩百多
13、個(gè),而 且相互之間可以互為組合,所以是不應(yīng)該寫(xiě)過(guò)程來(lái)實(shí)現(xiàn)的。即便把目前需求要 求的篩選條件通過(guò)寫(xiě)過(guò)程來(lái)實(shí)現(xiàn)了(暫不考慮開(kāi)發(fā)人員的頭疼) ,如果需要添加 一些新的篩選,那將是非常麻煩的。再則,如果所寫(xiě)過(guò)程中出現(xiàn)一些問(wèn)題,也 是難以維護(hù)的。 所以考慮到開(kāi)發(fā)的質(zhì)量與代碼的可維護(hù)性,是不可能采用此方案的。 方案方案 2 2:結(jié)合數(shù)據(jù)建模與程序設(shè)計(jì)來(lái)實(shí)現(xiàn)。 由于篩選條件數(shù)量眾多,但是條件之間的很多部分相互重合,從面向?qū)ο?的角度出發(fā),這些條件間存在繼承的關(guān)系,如果能采用面向?qū)ο蟮姆椒ǎ蛟S 能做到重用條件。 假設(shè)一共有 250 個(gè)獨(dú)立的篩選條件,也即表中的 250 個(gè)字段單獨(dú)作為條件 時(shí)的情況。這些條件
14、能相互組合,組合后的條件越發(fā)復(fù)雜,寫(xiě)程序時(shí)如果按照 方案 1 要想做到很好的代碼重用是不可能實(shí)現(xiàn)的。 所以根據(jù)方案 1 的失敗,要想很好的做到代碼重用,就很有必要引入面向 對(duì)象的思想,采用繼承的方法,做到條件組合,就好像類與類之間的繼承。作 為表中列名出現(xiàn)的字段,是不可能相互組合的。但是換個(gè)角度,大膽的設(shè)想, 如果把這些字段不作為列名,能不能做到相互組合呢?如果把這些字段轉(zhuǎn)換成 變量,對(duì)變量一一賦值,和作為字段相比并沒(méi)有做到很大的改善。 如果把這些字段轉(zhuǎn)換成表中的記錄值呢?試想一下,似乎看到一線光明, 因?yàn)樵?pl/sql 里,可以用到動(dòng)態(tài) sql 的方法,這樣可以所需要的條件動(dòng)態(tài)的組 合了。
15、 但是能不能真正達(dá)到便于動(dòng)態(tài)控制,便于動(dòng)態(tài)修改,以及便于維護(hù)呢?我 們需要一步一步去研究,以及測(cè)試。 根據(jù)目前得出的結(jié)論,我們現(xiàn)在需要一個(gè)表,表中的某一列的記錄值為 complexity 表中作為篩選條件的列名,如下表 2 所示: 表 2 field 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字主鍵 name 文本 column_name 文本列名 field 表中的 column_name 列存放 complexity 表中作為篩選條件的列名。 這樣就可以做到把條件一步一步拼起來(lái)了。 接著往下分析。需要選取出可能作為篩選條件的列名 c_u1、c_u2、c_u3、c_u4 四個(gè)字段,以后的分析將會(huì)以它們作為
16、例子。這里把 每個(gè)單獨(dú)的列名作為篩選條件的條件叫做簡(jiǎn)單條件,而多個(gè)簡(jiǎn)單條件組合而成 的條件叫做復(fù)雜條件。值得注意的是,篩選條件中有相當(dāng)一部分是類似于 c_u1 in (a, b, c, d)的,它也是簡(jiǎn)單條件,但是比較特殊一點(diǎn),這樣的 條件把它叫做簡(jiǎn)單序列條件。 假設(shè)現(xiàn)在客戶 ted 需要的數(shù)據(jù)是以 c_u1a 和 c_u2a 和 c_u2 a 或者c_u2=b ,篩選列和匹配的數(shù)值我們都可以 在相關(guān)表中取到,而篩選列和匹配的數(shù)值之間的關(guān)系,例如大于,小于,等于, 時(shí)間從某時(shí)間開(kāi)始,這些關(guān)系是我們?cè)趯?xiě)代碼的時(shí)候一直在重復(fù)的寫(xiě)的。而正 是因?yàn)檫@個(gè)原因,代碼不能做到代碼間的繼承和重用,這是一個(gè)失敗
17、指出。 要是通過(guò)接口設(shè)計(jì)能把這些關(guān)系像處理篩選列與匹配的數(shù)值一樣處理,這 個(gè)問(wèn)題也就解決了。能做到么?答案是肯定的。因?yàn)檫@些關(guān)系也就只有數(shù)種, 例如數(shù)字間的比較,時(shí)間數(shù)值之間的比較,諸如此類的關(guān)系是可以得到有效控 制的。 對(duì)于序列條件,只有兩種關(guān)系,即是否in ,很顯然也可以得到有效的控 制。 通過(guò)以上的分析,現(xiàn)在只需要再加一個(gè)表就可以了,這張表用來(lái)存放簡(jiǎn)單 條件的篩選列與匹配的數(shù)值之間的關(guān)系種類,而對(duì)于序列條件,就不用,在程 序里很容易做到動(dòng)態(tài)處理。為了不占據(jù)篇幅,數(shù)據(jù)篩選接口的完整數(shù)據(jù)庫(kù)架構(gòu) 會(huì)在后面的數(shù)據(jù)建模部分中一并出現(xiàn)。 5 5 數(shù)據(jù)建模數(shù)據(jù)建模 5.15.1 數(shù)據(jù)模型的建立數(shù)據(jù)模型
18、的建立 根據(jù)解決方案的設(shè)計(jì),畫(huà)出數(shù)據(jù)篩選接口的完整數(shù)據(jù)庫(kù)架構(gòu),如后頁(yè)圖所 示: condition pkid name negated container_id compound_condition pkid conjunction_id simple_condition pkid name value operator_id field_id list_condition pkid field_id conjunction pkid name code condition_operator pkid code name field pkid name column_name list_con
19、dition_match_value pkid list_condition_id match_value 圖 5 數(shù)據(jù)庫(kù)架構(gòu)圖 5.25.2 數(shù)據(jù)庫(kù)表結(jié)構(gòu)的設(shè)計(jì)數(shù)據(jù)庫(kù)表結(jié)構(gòu)的設(shè)計(jì) 根據(jù)前面完成的解決方案的設(shè)計(jì)以及數(shù)據(jù)模型的建立,可以設(shè)計(jì)出完整的 數(shù)據(jù)庫(kù)表結(jié)構(gòu)。具體設(shè)計(jì)如下: 用于存放篩選條件,具體設(shè)計(jì)如表 3 所示: 表 3 條件表 condition 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 name 文本條件名字 negated 數(shù)字判斷是否為否定字段 container_id 數(shù)字判斷是否屬于復(fù)合條件字段 用于存放條件聯(lián)接符,具體設(shè)計(jì)如表 4 所示: 表 4 條件聯(lián)接符表 conj
20、unction 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 name 文本名字 code 文本聯(lián)接符編碼 用于存放復(fù)合條件,具體設(shè)計(jì)如表 5 所示: 表 5 復(fù)合條件表 compound_condition 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 conjunction_id 數(shù)字聯(lián)接符編號(hào) 用于存放簡(jiǎn)單條件信息,具體設(shè)計(jì)如表 6 所示: 表 6 簡(jiǎn)單條件表 simple_condition 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 name 文本簡(jiǎn)單條件名字 value 文本簡(jiǎn)單條件數(shù)值 operator_id 數(shù)字條件運(yùn)算符編號(hào) field_id 數(shù)字篩選列編號(hào) 用于存放條件運(yùn)
21、算符信息,具體設(shè)計(jì)如表 7 所示: 表 7 條件運(yùn)算符表 condition_operator 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 name 文本條件運(yùn)算符名字 code 文本條件運(yùn)算符編碼 用于存放序列條件信息,具體設(shè)計(jì)如表 8 所示: 表 8 序列條件表 list_condition 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 field_id 數(shù)字篩選列編號(hào) 用于存放序列條件需要去匹配的數(shù)值信息,具體設(shè)計(jì)如表 9 所示: 表 9 序列條件匹配數(shù)值表 list_condition_match_value 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 list_condition
22、_id 數(shù)字序列條件編號(hào) match_value 文本序列條件匹配值 用于存放篩選列信息,具體設(shè)計(jì)如表 10 所示: 表 10 篩選列信息表 field 字段名數(shù)據(jù)類型說(shuō)明 id 數(shù)字編號(hào)字段 主鍵 name 文本篩選列名字(可作標(biāo)記) column_name 文本實(shí)際篩選列名 5.35.3 數(shù)據(jù)庫(kù)基礎(chǔ)視圖的設(shè)計(jì)數(shù)據(jù)庫(kù)基礎(chǔ)視圖的設(shè)計(jì) 通過(guò)之前的分析,我發(fā)現(xiàn)數(shù)據(jù)庫(kù)中的八個(gè)表之間關(guān)聯(lián)比較多,應(yīng)該把通常 發(fā)生關(guān)聯(lián)的表封裝起來(lái),視圖正是實(shí)現(xiàn)這個(gè)封裝的最佳選擇。 需要?jiǎng)?chuàng)建四個(gè)視圖,分別為簡(jiǎn)單條件視圖,序列條件視圖,組合條件視圖, 以及條件視圖。通過(guò)這四個(gè)視圖可以把簡(jiǎn)單條件,序列條件,以及組合條件和 fi
23、eld 表很好的封裝起來(lái)。為了避免占據(jù)過(guò)多篇幅,這里只以序列條件視圖和 組合條件視圖為例。 序列條件視圖: create or replace view v_list_condition (field_name, column_name, field_type_name, field_type_code, field_table_type_name, field_table_type_code, negated, item_count, id, field_id, field_type_id, container_id) as select f.name as field_name, f.co
24、lumn_name, ic.negated, ( select count( * ) from list_cond_match_value lcmv where ( lcmv.list_condition_id = lc.id ) ) as i_count, lc.id, f.id as field_id, f.type_id as field_type_id, ic.container_id from list_condition lc left outer join condition c on( c.id = lc.id ) left outer join field f on ( f.
25、id = lc.field_id ) / 組合條件視圖: create or replace view v_compound_condition (negated, conjunction_name, conjunction_code, condition_count, id, container_id, conjunction_id) as select ic.negated, c.name as conjunction_name, c.code as conjunction_code, ( select count( * ) from condition childcondition wh
26、ere ( childcondition.container_id = cic.id ) ) as condition_count, cc.id, ic.container_id, cc.conjunction_id from compound_condition cc left outer join condition ic on( ic.id = cc.id ) left outer join conjunction c on( c.id = cc.conjunction_id ) / 這樣就通過(guò)創(chuàng)建視圖,把簡(jiǎn)單條件,序列條件,以及組合條件和 field 表 很好的封裝起來(lái)了。 到此,數(shù)據(jù)
27、建模完成。 6 6 pl/sqlpl/sql 程序設(shè)計(jì)程序設(shè)計(jì) 現(xiàn)在進(jìn)行本接口設(shè)計(jì)的 pl/sql 程序設(shè)計(jì)部分。 從客戶出發(fā),這里來(lái)整理一下思路。當(dāng)客戶提出一系列篩選條件的要求時(shí), 開(kāi)發(fā)人員首先需要把這些基本的簡(jiǎn)單條件和匹配的數(shù)值,以及相關(guān)的記錄值, 一一插入相關(guān)的表中。開(kāi)發(fā)人員可以用寫(xiě)一系列的過(guò)程來(lái)實(shí)現(xiàn),通過(guò)傳入必需 的參數(shù)來(lái)調(diào)用相關(guān)的過(guò)程,插入一些數(shù)值。 從下到上,首先要對(duì)表直接進(jìn)行操作,需要一系列最基本的用來(lái)實(shí)現(xiàn)把數(shù) 值插入表的過(guò)程。 以簡(jiǎn)單條件為例: procedure ins_simple_condition ( p_calling_user_id integer, - requi
28、red p_name varchar2 := null, p_negated number := 0, - required p_container_id integer := null, p_field_id integer, - required p_value varchar2 := null, p_enum_value_id integer := null, p_comparison_field_id integer := null, p_operator_id integer, - required p_new_row_id out integer ) is begin -省略部分代
29、碼 ins_condition ( p_calling_user_id, p_name, p_negated, p_container_id, p_new_row_id ); insert into simple_condition ( id, field_id, value, enum_value_id, comparison_field_id, operator_id ) values( p_new_row_id, p_field_id, p_value, p_enum_value_id, p_comparison_field_id, p_operator_id ); -省略部分代碼 en
30、d; 然后,需要在這些基礎(chǔ)過(guò)程之上,寫(xiě)一些調(diào)用這些基礎(chǔ)過(guò)程的過(guò)程,也以 簡(jiǎn)單條件為例: procedure add_simple_condition ( p_calling_user_id integer, - required p_app_id integer, p_table_type_code varchar2, - required p_name varchar2 := null, p_negated number := 0, p_container_id integer := null, p_field_name varchar2, - required p_value varcha
31、r2 := null, p_value_date date := null, p_comparison_field_name varchar2 := null, p_operator_code varchar2, - required p_new_row_id out integer ) is - l_field_id integer; l_field_type_code varchar2( 100 ); l_comparison_field_id integer; l_comparison_field_type_code varchar2( 100 ); l_operator_code va
32、rchar2( 100 ); l_operator_id integer; l_value varchar2( 1000 ); begin -省略部分代碼 select id, code into l_operator_id, l_operator_code from condition_operator where ( lower( code ) = lower( p_operator_code ) ); -省略部分代碼 ins_simple_condition ( p_calling_user_id = p_calling_user_id, p_name = p_name, p_negat
33、ed = p_negated, p_container_id = p_container_id, p_field_id = l_field_id, p_value = l_value, p_comparison_field_id = l_comparison_field_id, p_operator_id = l_operator_id, p_new_row_id = p_new_row_id ); -省略部分代碼 end; 現(xiàn)在就可以創(chuàng)建一些比較復(fù)雜的組合條件了。為了不占據(jù)篇幅,這里只以 一個(gè)簡(jiǎn)單的復(fù)合條件為例: -first compound condition (no_notice in
34、(b,c,d) and msg_delinq_days90 and do_not_process=9 and client_id=116) declare l_calling_user_id integer; l_dps_appl_id integer; l_count integer; l_spec_id integer; l_item_id integer; l_simple_id integer; l_inventory_item_id integer; l_temp_id integer; l_compound_id integer; l_field_id integer; l_rul
35、e_id integer; l_list_id integer; l_state_4_ted1 varchar2( 4000 ) := b,c,d; begin -省略部分代碼 -add condition add_compound_item_condition ( p_name = the fourth compoud condition, p_negated = 0, p_conjunction = and, p_container_id = null, p_new_row_id = l_rule_id); select id into l_field_id from field_ whe
36、re name = no_notice and ( application_id = l_dps_appl_id or application_id is null ); add_list_item_condition ( p_name = no_notice in(b,c,d), p_negated = 1, p_field_id = l_field_id, p_container_id = l_rule_id, p_new_row_id = l_list_id); for x in ( with src as ( select l_state_4_ted1 exp from dual ),
37、 num as ( select rownum i from dual connect by rownum 0 order by r ) loop add_list_item_condition_mv ( p_list_item_condition_id = l_list_id, p_match_value = x.r, p_new_row_id = l_temp_id); end loop; select id into l_field_id from field_ where name = msg_delinq_days and ( application_id = l_dps_appl_
38、id or application_id is null ); add_simple_item_condition ( p_name = null, p_negated = 0, p_container_id = l_rule_id, p_field_id = l_field_id, p_value = 90, p_comparison_field_name = null, p_operator = greater, p_new_row_id = l_simple_id); select id into l_field_id from field_ where name = do_not_pr
39、ocess and ( application_id = l_dps_appl_id or application_id is null ); add_simple_item_condition ( p_name = null, p_negated = 0, p_container_id = l_rule_id, p_field_id = l_field_id, p_value = 9, p_comparison_field_name = null, p_operator = equals, p_new_row_id = l_simple_id); select id into l_field
40、_id from field_ where name = client_id and ( application_id = l_dps_appl_id or application_id is null ); add_simple_item_condition ( p_name = null, p_negated = 0, p_container_id = l_rule_id, p_field_id = l_field_id, p_value = 116, p_comparison_field_name = null, p_operator = equals, p_new_row_id= l_
41、simple_id); commit; end; 到此篩選列和需要匹配的數(shù)值,就可以得到靈活控制了。還需要對(duì)存儲(chǔ)在 表condition_operator中的數(shù)值,也就是記錄篩選列和需要匹配的數(shù)值之間的 關(guān)系的數(shù)值進(jìn)行處理,以便能動(dòng)態(tài)處理。下面只以需要匹配的數(shù)值的數(shù)據(jù)類型 為日期類型的情況為例。 當(dāng)需要匹配的數(shù)值的數(shù)據(jù)類型為日期類型時(shí),如下: function comparison_date ( p_row v_simple_condition%rowtype, p_field_ref varchar2, p_comparison_field_ref varchar2 ) return var
42、char2 is l_comparison varchar2( 4000 ); l_operator varchar2( 2 ); l_value_this_day date; l_value_this_day_string varchar2( 1000 ); l_value_next_day date; l_value_next_day_string varchar2( 1000 ); begin -省略部分代碼 if( p_comparison_field_ref is not null ) then -省略部分代碼 l_value_this_day_string := trunc( |
43、p_comparison_field_ref | , dd ); l_value_next_day_string := trunc( | p_comparison_field_ref | + 1, dd ); else if ( p_row.value is not null ) then l_value_this_day := to_date( p_row.value, g_date_format ); l_value_this_day_string := to_date( | | p_row.value | , | | g_date_format | ) ; l_value_next_da
44、y := l_value_this_day + 1; l_value_next_day_string := to_date( | | to_char( l_value_next_day, g_date_format ) | , | | g_date_format | ) ; end if; end if; case p_row.operator_code when equals then if( p_comparison_field_ref is not null ) then if( p_row.negated = 0 ) then l_comparison := ( ( | p_field
45、_ref | is null ) and | ( | p_comparison_field_ref | is null ) ) or | ( ( | p_field_ref | = | l_value_this_day_string | ) | and | ( | p_field_ref | | l_value_next_day_string | ) ); else l_comparison := ( ( | p_field_ref | is null ) and | ( | p_comparison_field_ref | is not null ) ) or | ( ( | p_field
46、_ref | is not null ) and | ( | p_comparison_field_ref | is null ) ) or | ( | p_field_ref | = | l_value_next_day_string | ); end if; else if( p_row.value is null ) then if( p_row.negated = 0 ) then l_comparison := p_field_ref | is null; else l_comparison := p_field_ref | is not null; end if; else if(
47、 p_row.negated = 0 ) then l_comparison := ( | p_field_ref | = | l_value_this_day_string | ) | and | ( | p_field_ref | | l_value_next_day_string | ); else l_comparison := ( | p_field_ref | is null ) | or | ( | p_field_ref | = | l_value_next_day_string | ); end if; end if; end if; when greater then nu
48、ll; if( ( p_comparison_field_ref is not null ) or ( p_row.value is not null ) ) then if( p_row.negated = 0 ) then l_operator := =; else l_operator := ; end if; l_comparison := p_field_ref | | l_operator | | l_value_next_day_string; else - the value were checking against is null, so we should have no
49、 matches. l_comparison := g_false_condition; end if; when less then if( ( p_comparison_field_ref is not null ) or ( p_row.value is not null ) ) then if( p_row.negated = 0 ) then l_operator := =; end if; l_comparison := p_field_ref | | l_operator | | l_value_this_day_string; else - the value were che
50、cking against is null, so we should have no matches. l_comparison := g_false_condition; end if; else raise_application_error ( g_error_number, unexpected operator: | p_row.operator_code ); end case; -省略部分代碼 return l_comparison; end; 總結(jié)一下,本接口設(shè)計(jì)的 pl/sql 程序設(shè)計(jì)部分是通過(guò)如下過(guò)程實(shí)現(xiàn)了靈活 控制篩選條件,并完成了數(shù)據(jù)篩選接口的基本部分的。 被 調(diào)
51、用 被 調(diào) 用 圖 6 創(chuàng)造數(shù)據(jù)篩選條件程序設(shè)計(jì)圖 現(xiàn)在篩選列和需要匹配的數(shù)值以及篩選列和需要匹配的數(shù)值之間的關(guān)系都 可以得到靈活控制了,只需要根據(jù)不同的參數(shù)調(diào)用公共的pl/sql接口,一一 拼裝起來(lái)即可。 現(xiàn)在還需要通過(guò)寫(xiě)過(guò)程來(lái)實(shí)現(xiàn)把這些復(fù)雜篩選條件拼裝起來(lái),最終篩 選出客戶需要的數(shù)據(jù),這樣一個(gè)功能。 以簡(jiǎn)單條件為例。 function cond_where_simple ( p_item_condition_id integer, p_index_field_prefix varchar2 ) return varchar2 is - required l_where_clause var
52、char2( 4000 ); l_row v_simple_item_condition%rowtype; l_effective_prefix varchar2( 100 ); l_field_ref varchar2( 1000 ); l_comparison_field_ref varchar2( 1000 ) := null; begin -省略部分代碼 l_effective_prefix := ; if( p_index_field_prefix is not null ) then l_effective_prefix := p_index_field_prefix | .; 基
53、礎(chǔ)操作條件過(guò)程1 對(duì)數(shù)據(jù)庫(kù)的相關(guān)條件表進(jìn)行 操作,包括插入,更新等 基礎(chǔ)操作條件過(guò)程2 動(dòng)態(tài)處理記錄篩選列和需 要匹配的數(shù)值之間的關(guān)系 的數(shù)值 調(diào)用基礎(chǔ)條件過(guò)程 用于創(chuàng)造一些復(fù)雜的組 合條件 end if; l_where_clause := ; select * into l_row from v_simplecondition where( id = p_item_condition_id ); l_field_ref := l_effective_prefix | l_row.column_name; if( l_row.comparison_column_name is not nul
54、l ) then l_comparison_field_ref := l_effective_prefix | l_row.comparison_column_name; end if; case l_row.field_type_name when boolean then l_where_clause := l_where_clause | comparison_boolean( l_row, l_field_ref, l_comparison_field_ref ); when date then l_where_clause := l_where_clause | comparison
55、_date( l_row, l_field_ref, l_comparison_field_ref ); when list then l_where_clause := l_where_clause | comparison_string( l_row, l_field_ref, l_comparison_field_ref ); when number then l_where_clause := l_where_clause | comparison_number( l_row, l_field_ref, l_comparison_field_ref ); when string the
56、n l_where_clause := l_where_clause | comparison_string( l_row, l_field_ref, l_comparison_field_ref ); else -省略部分代碼 end case; return l_where_clause; end; 現(xiàn)在還需要再完成一個(gè)對(duì)簡(jiǎn)單條件,序列條件,以及組合條件都開(kāi)放的公 共調(diào)用接口。 function condition_where_clause_r ( p_condition_id integer, - required p_index_field_prefix varchar2 := nul
57、l ) return varchar2 is - required l_where_clause varchar2( 10000 ) := null; l_condition_type varchar2( 100 ); begin -省略部分代碼 l_where_clause := ( ; - its either a simple, compound, or list condition. l_condition_type := condition_type( p_condition_id ); case l_condition_type when simple then l_where_c
58、lause := l_where_clause | cond_where_simple( p_condition_id, p_index_field_prefix ); when list then null; l_where_clause := l_where_clause | cond_where_list( p_condition_id, p_index_field_prefix ); when compound then l_where_clause := l_where_clause | cond_where_compound( p_condition_id, p_index_fie
59、ld_prefix ); else raise_application_error ( g_error_number, unknown type for item condition | p_condition_id ); end case; l_where_clause := l_where_clause | ); -省略部分代碼 return l_where_clause; end; 到此,數(shù)據(jù)篩選接口的設(shè)計(jì)就基本完成了。需要什么樣的條件,無(wú)論復(fù)雜 與否,都只需要根據(jù)需求,通過(guò)傳入相關(guān)參數(shù)調(diào)用產(chǎn)生條件的公共接口,然后 用動(dòng)態(tài) sql 的方法, 拼在篩選條件的地方就可以了。 結(jié)結(jié) 論論 所設(shè)
60、計(jì)與開(kāi)發(fā)的數(shù)據(jù)篩選接口會(huì)對(duì)系統(tǒng)的數(shù)據(jù)篩選部分起到便于靈活控制, 便于修改,便于維護(hù)的作用。 融合了面向?qū)ο蟮乃枷牒蟮臄?shù)據(jù)庫(kù)在開(kāi)發(fā)階段會(huì)發(fā)生了一些改善,例如提 高代碼的可重用性,這就很大程度上減少了開(kāi)發(fā)階段在代碼編寫(xiě)上所花費(fèi)的資 源,可以很好的提高軟件的開(kāi)發(fā)質(zhì)量,并且易于維護(hù)。 參考文獻(xiàn)參考文獻(xiàn) 1 johanna wenny rahayu,david taniar,eric pardede.object-oriented oraclem.irm press,2005。 2 steven feuerstein,bill pribyl.oracle pl/sql programming 4th e
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 軟件工程中的軟件架構(gòu)設(shè)計(jì)考核試卷
- 貨運(yùn)火車(chē)站物流企業(yè)服務(wù)質(zhì)量控制與提升考核試卷
- 羽絨制品企業(yè)信息化建設(shè)與管理考核試卷
- 航標(biāo)器材在跨海物流運(yùn)輸中的作用考核試卷
- 牛的飼養(yǎng)國(guó)際合作模式研究考核試卷
- 礦山機(jī)械維修工程案例分析考核試卷
- 租賃合同的數(shù)字化簽署與流程自動(dòng)化考核試卷
- 車(chē)載設(shè)備智能駕駛車(chē)輛駕駛輔助系統(tǒng)集成測(cè)試考核試卷
- 電子電路原理與應(yīng)用考核試卷
- 手術(shù)室的感染管理
- 購(gòu)買(mǎi)廢舊電纜合同協(xié)議
- 2024年河北承德辰飛供電服務(wù)有限公司招聘真題
- 焊接工程師理論基礎(chǔ)考核試題及答案
- 電氣設(shè)備知識(shí)培訓(xùn)課件
- 歷史文化遺產(chǎn)類博物館文旅融合發(fā)展的路徑探索
- 電影《滿江紅》觀后感與教育啟示
- 統(tǒng)編版語(yǔ)文八年級(jí)下冊(cè)24 唐詩(shī)三首課件
- 山東省臨沂市普通高中學(xué)業(yè)水平等級(jí)考試模擬試題政治含答案
- 2025年個(gè)人家政服務(wù)合同標(biāo)準(zhǔn)
- 基于STM32的輸電線路狀態(tài)監(jiān)測(cè)系統(tǒng)的研究
- 環(huán)衛(wèi)規(guī)范作業(yè)培訓(xùn)
評(píng)論
0/150
提交評(píng)論