面向?qū)ο髷?shù)據(jù)庫_第1頁
面向?qū)ο髷?shù)據(jù)庫_第2頁
面向?qū)ο髷?shù)據(jù)庫_第3頁
面向?qū)ο髷?shù)據(jù)庫_第4頁
面向?qū)ο髷?shù)據(jù)庫_第5頁
已閱讀5頁,還剩95頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

面向?qū)ο髷?shù)據(jù)庫第1頁,共100頁,2023年,2月20日,星期四第13章面向?qū)ο髷?shù)據(jù)庫對復(fù)雜數(shù)據(jù)類型的需求面向?qū)ο髷?shù)據(jù)模型面向?qū)ο笳Z言持久性程序設(shè)計(jì)語言持久性C++系統(tǒng)持久性JAVA系統(tǒng)第2頁,共100頁,2023年,2月20日,星期四對復(fù)雜數(shù)據(jù)類型的需求數(shù)據(jù)處理中的傳統(tǒng)數(shù)據(jù)庫應(yīng)用具有簡單數(shù)據(jù)類型相對較少的數(shù)據(jù)類型,第一范式成立近年來復(fù)雜數(shù)據(jù)類型越來越重要例如:地址可處理為單個字符串,或者為每個子部分用一單獨(dú)的屬性,或者復(fù)合屬性(不屬于第一范式)例如:允許直接存儲多值屬性而不是創(chuàng)建單獨(dú)的第一范式關(guān)系存儲通常更方便應(yīng)用CAD,CASE多媒體與圖像數(shù)據(jù)庫,文檔/超文本數(shù)據(jù)庫第3頁,共100頁,2023年,2月20日,星期四面向?qū)ο髷?shù)據(jù)模型(略講)對象大體上對應(yīng)于E-R模型中的實(shí)體面向?qū)ο笫腔趯⑴c一對象有關(guān)的代碼與數(shù)據(jù)封裝成一個單位的思想.面向?qū)ο髷?shù)據(jù)模型是一個邏輯數(shù)據(jù)模型(類似E-R模型).使面向?qū)ο蟪绦蛟O(shè)計(jì)風(fēng)格(e.g.,Smalltalk,C++)適應(yīng)數(shù)據(jù)庫系統(tǒng)第4頁,共100頁,2023年,2月20日,星期四對象結(jié)構(gòu)對象具有:變量集合:包含對象的數(shù)據(jù).變量值本身也是對象.消息集合:對象對消息進(jìn)行反應(yīng);消息可具有零,一個或多個參數(shù).方法集合:

實(shí)現(xiàn)消息的代碼體;方法返回一個值作為對消息的反應(yīng)數(shù)據(jù)的物理表示僅對對象的實(shí)現(xiàn)者可見消息與反應(yīng)提供了對象的唯一的外部界面消息這個詞不必意味著物理上的消息傳遞.消息可以實(shí)現(xiàn)為過程調(diào)用第5頁,共100頁,2023年,2月20日,星期四消息與方法方法是用通用語言寫的程序,具有下列特性變量僅在對象本身內(nèi)部可以直接引用其他對象的數(shù)據(jù)只能通過發(fā)送消息引用.方法分為read-only和update方法只讀方法不改變對象的值嚴(yán)格地說,實(shí)體的每個屬性都必須表示為一個變量和兩個方法,一個用于讀屬性,另一個用于更新例如,屬性address可用變量address與兩條消息get-address和set-address表示為方便起見,許多面向?qū)ο髷?shù)據(jù)模型都允許直接存取其他對象的變量.第6頁,共100頁,2023年,2月20日,星期四對象類相似對象組成類;每個對象稱為它的類的實(shí)例一個類中所有對象具有相同的具有相同類型的變量,消息接口方法賦給變量的值可能不同例如:所有人對象組成person類類與E-R模型中的實(shí)體集相似第7頁,共100頁,2023年,2月20日,星期四類定義例

classemployee{

/*Variables*/

stringname;

stringaddress;

datestart-date;

intsalary;

/*Messages*/

intannual-salary();

stringget-name();

stringget-address();

intset-address(stringnew-address);

intemployment-length();

};在嚴(yán)格的封裝中還需要用來讀與設(shè)置其他變量的值的方法方法單獨(dú)定義如:int

employment-length(){return

today()–start-date;}

int

set-address(string

new-address){address=new-address;}第8頁,共100頁,2023年,2月20日,星期四繼承例如,銀行客戶類與銀行雇員類相似,盡管有不同之處兩者可以共享某些變量和消息,如name與address.

兩者也各有特殊變量和消息,如雇員的salary和客戶的credit-rating.每個雇員是人;所以employee是person的特例同樣,customer也是person的特例.創(chuàng)建類person,employeeandcustomer對所有人都適用的變量/消息與類person關(guān)聯(lián).雇員所特有的變量/消息與類employee關(guān)聯(lián)客戶所特有的變量/消息與類customer關(guān)聯(lián)第9頁,共100頁,2023年,2月20日,星期四繼承類組織成一個特化/IS-A層次屬于類person的變量/消息被類employee和customer繼承結(jié)果構(gòu)成一個類層次注意與E-R模型中的ISA層次的相似性第10頁,共100頁,2023年,2月20日,星期四類層次定義

classperson{

string name;

string address:

};

classcustomerisaperson{

intcredit-rating;

};

classemployeeisaperson{

datestart-date;

intsalary;

};

classofficerisaemployee{

intoffice-number,

intexpense-account-number,

};

...第11頁,共100頁,2023年,2月20日,星期四類層次例類officer的對象的完整變量列表:office-number,expense-account-number:

局部定義start-date,salary:從employee繼承name,address:從person繼承同變量一樣還繼承方法.可替換性—類的任何方法可以被屬于其子類的任何對象調(diào)用.類外延(extent):類中所有對象的集合.兩種選擇:1. 類employee的外延包含所有officer,teller和secretary對象.類employee的外延僅包含不屬于子類officer,teller或secretary的雇員對象這是OO系統(tǒng)通常的做法可訪問子類的外延求所有子類對象第12頁,共100頁,2023年,2月20日,星期四多重繼承多重繼承使一個類可有多個超類.類/子類聯(lián)系可表示為有向無圈圖(DAG)當(dāng)對象有多種相互獨(dú)立的分類方式時尤其有用E.g.臨時/永久獨(dú)立于Officer/secretary/teller為每一種子類組合創(chuàng)建一個子類不必為數(shù)據(jù)庫中不可能出現(xiàn)的子類組合創(chuàng)建子類類從它的所有超類繼承變量和方法存在歧義的可能:當(dāng)從兩個超類A和B繼承同名變量/消息N時若該變量/消息是在共享的超類中定義的則沒有問題否則,采用如下方法之一標(biāo)志為出錯,重命名變量(A.N和B.N)選擇其一.第13頁,共100頁,2023年,2月20日,星期四多重繼承例銀行例的類DAG第14頁,共100頁,2023年,2月20日,星期四多重繼承例一個對象可以同時屬于多個子類一個person可以具有student,teacher或footballPlayer等角色,或者任何組合例如,踢足球的學(xué)生助教可用多重繼承建模對象的“角色”即,允許對象具有多個類型但許多系統(tǒng)堅(jiān)持對象必須具有最具體類即,若某對象屬于多個類,則必須存在這些類的一個共同子類創(chuàng)建子類student-teacher與student-teacher-footballPlayer當(dāng)有許多可能的組合時,為每種組合創(chuàng)建子類會很麻煩第15頁,共100頁,2023年,2月20日,星期四對象標(biāo)識即使某些或全部變量的值或方法定義隨時間改變,對象仍保持其身份.對象標(biāo)識是一個比非面向?qū)ο蟮某绦蛘Z言或數(shù)據(jù)模型中對應(yīng)概念更強(qiáng)的標(biāo)識概念.值–數(shù)據(jù)值;例如關(guān)系系統(tǒng)中所用的主鍵值.名–由用戶提供;用于過程中的變量.內(nèi)建–數(shù)據(jù)模型或程序語言內(nèi)建的標(biāo)識.不需用戶提供標(biāo)識.面向?qū)ο笙到y(tǒng)采用的標(biāo)識形式第16頁,共100頁,2023年,2月20日,星期四對象標(biāo)識對象標(biāo)識用于唯一標(biāo)識對象對象標(biāo)識是唯一的:沒有兩個對象具有相同的標(biāo)識每個對象只有一個標(biāo)識例如,person對象的spouse字段可以是另一個person對象的標(biāo)識.可保存為一對象的字段,用來引用另一對象.可以是系統(tǒng)生成的(由數(shù)據(jù)庫創(chuàng)建),或外部的(如社會安全號)系統(tǒng)生成的標(biāo)識:更易用,但不能跨數(shù)據(jù)庫系統(tǒng)使用如果已存在唯一標(biāo)識則冗余第17頁,共100頁,2023年,2月20日,星期四對象包含設(shè)計(jì)中的每個部件可以包含其他部件可建模為對象包含.包含其他對象的對象稱為復(fù)合對象.多層次的包含形成了包含層次連線解釋為is-part-of,而非is-a.允許數(shù)據(jù)被不同用戶在不同粒度上觀察第18頁,共100頁,2023年,2月20日,星期四面向?qū)ο笳Z言面向?qū)ο蟾拍钤跀?shù)據(jù)庫系統(tǒng)中有多種用法面向?qū)ο罂杀挥米髟O(shè)計(jì)工具類似于用E-R圖建模再轉(zhuǎn)換成關(guān)系面向?qū)ο蟾拍羁膳c操作數(shù)據(jù)庫的程序設(shè)計(jì)語言結(jié)合.對象關(guān)系系統(tǒng)–在關(guān)系語言中增加復(fù)雜類型和面向?qū)ο?持久性程序設(shè)計(jì)語言–通過增加持久性和集合之類的概念來擴(kuò)展面向?qū)ο蟪绦蛟O(shè)計(jì)語言以便處理數(shù)據(jù)庫.第19頁,共100頁,2023年,2月20日,星期四持久性程序設(shè)計(jì)語言持久性程序設(shè)計(jì)語言允許創(chuàng)建對象并存儲在數(shù)據(jù)庫中,并且可在程序設(shè)計(jì)語言中直接使用允許從程序設(shè)計(jì)語言直接操作數(shù)據(jù)不必通過SQL.不必有顯式的格式(類型)改變格式改變由系統(tǒng)透明地完成若沒有持久性程序設(shè)計(jì)語言,格式改變成為程序員的負(fù)擔(dān)要寫更多的代碼更多的出錯機(jī)會允許對象在內(nèi)存中處理不必有顯式的從數(shù)據(jù)庫加載或存儲到數(shù)據(jù)庫節(jié)省代碼,節(jié)省加載/存儲大量數(shù)據(jù)的開銷第20頁,共100頁,2023年,2月20日,星期四持久性程序設(shè)計(jì)語言持久性程序設(shè)計(jì)語言的缺點(diǎn)由于多數(shù)程序設(shè)計(jì)語言的表達(dá)能力,很容易造成編程錯誤而破壞數(shù)據(jù)庫.語言的復(fù)雜性使得自動的高級優(yōu)化更加困難.不支持描述性查詢和關(guān)系數(shù)據(jù)庫第21頁,共100頁,2023年,2月20日,星期四對象的持久性使臨時對象持久化的途徑類持久–聲明某個類的所有對象是持久的;簡單但不靈活.創(chuàng)建持久–擴(kuò)展創(chuàng)建對象的語法以聲明對象是持久的.標(biāo)記持久–在程序中止之前將對象標(biāo)記為持久的.可達(dá)性持久–聲明(根)持久對象;被根對象直接或間接引用的對象也是持久的.對程序員更容易,但對數(shù)據(jù)庫系統(tǒng)有更多開銷類似Java中的垃圾收集,要檢查可達(dá)性第22頁,共100頁,2023年,2月20日,星期四對象標(biāo)識與指針持久對象被賦予持久的對象標(biāo)識.標(biāo)識的永久程度過程內(nèi)–標(biāo)識僅在單個過程執(zhí)行期間持續(xù)程序內(nèi)–標(biāo)識僅在單個程序或查詢執(zhí)行期間持續(xù)程序間–標(biāo)識在多個程序的執(zhí)行之間持續(xù),但隨存儲組織改變而改變持久的–標(biāo)識在程序執(zhí)行之間和數(shù)據(jù)的結(jié)構(gòu)重組之間持久這是面向?qū)ο笙到y(tǒng)要求的第23頁,共100頁,2023年,2月20日,星期四對象標(biāo)識與指針在O-O語言(如C++)中,對象標(biāo)識實(shí)際上是內(nèi)存指針持久性指針–在程序執(zhí)行之間持久可看作是指向數(shù)據(jù)庫內(nèi)對象的指針E.g.指明文件標(biāo)識和文件內(nèi)偏移第24頁,共100頁,2023年,2月20日,星期四持久對象的存儲與存取命名對象(同命名文件一樣)不能用于大量對象.通常只對類外延及其他對象集合命名,而非對象.暴露對象標(biāo)識或指向?qū)ο蟮某志弥羔樋稍谕獠勘4?所有對象都有對象標(biāo)識存儲對象集合,并允許程序在該集合上迭代以找到所需對象將對象集合建模為匯集類型類外延–屬于類的所有對象的集合;通常為具有持久對象的類維護(hù)外延.如何在數(shù)據(jù)庫中找到對象:第25頁,共100頁,2023年,2月20日,星期四持久性C++系統(tǒng)C++語言允許增加對持久性的支持而不修改語言聲明一個類Persistent_Object來支持持久性重載–在新類型中重定義標(biāo)準(zhǔn)函數(shù)名及運(yùn)算符(如+,–,指針去引用運(yùn)算–>)的能力模板類有助于構(gòu)建一個類型安全的支持匯集和持久類型的類型系統(tǒng).不必?cái)U(kuò)展C++語言而提供對持久性的支持相對容易實(shí)現(xiàn)但難以使用與避免改變語言的系統(tǒng)一樣,向C++語言增加新特性的持久性C++系統(tǒng)已被構(gòu)建第26頁,共100頁,2023年,2月20日,星期四ODMGC++對象定義語言O(shè)bjectDatabaseManagementGroup是一致力于標(biāo)準(zhǔn)化面向?qū)ο髷?shù)據(jù)庫的工業(yè)協(xié)會尤其是持久性程序設(shè)計(jì)語言包括C++,Smalltalk和Java標(biāo)準(zhǔn)ODMG-93ODMG-2.0and3.0(whichis2.0plusextensionstoJava)我們的描述基于ODMG-2.0ODMGC++標(biāo)準(zhǔn)避免改動C++語言

通過模板類和類庫提供功能第27頁,共100頁,2023年,2月20日,星期四ODMG類型模板類d_Ref<class>用于聲明引用(持久性指針)模板類d_Set<class>用于定義對象集合. 方法包括insert_element(e)和delete_element(e)還提供其他匯集類如d_Bag(允許重復(fù)的集合),d_List和d_Varray(變長數(shù)組).還提供許多標(biāo)準(zhǔn)類型的d_版本,如d_Long和d_string對這些類型的解釋是依賴于平臺的動態(tài)分配的數(shù)據(jù)在數(shù)據(jù)庫中分配,而非在內(nèi)存第28頁,共100頁,2023年,2月20日,星期四ODMGC++1.0ODL:例

classBranch:publicd_Object{…. } classPerson:publicd_Object{

public:

d_Stringname;//shouldnotuseString! d_Stringaddress;

};

classAccount:publicd_Object{

private:

d_Longbalance;

public:

d_Longnumber;

d_Set<d_Ref<Customer>>owners; intfind_balance();

intupdate_balance(intdelta);

};第29頁,共100頁,2023年,2月20日,星期四ODMGC++1.0ODL:例classCustomer:publicPerson{

public:

d_Datemember_from;

d_Longcustomer_id;

d_Ref<Branch>home_branch;

d_Set<d_Ref<Account>>accounts;};第30頁,共100頁,2023年,2月20日,星期四C++ODL2.0ExampleclassPerson(extentpeople){private:AttributeStringname;AttributeRef<Person>spouse;AttributeSet<Person>children;AttributeList<Person>parents;public:Person(char*name);voidbirth(Personchild);voidmarriage(Personspouse);Stringget_name(){returnname;}List<Person>get_children(){returnchildren;};};第31頁,共100頁,2023年,2月20日,星期四實(shí)現(xiàn)聯(lián)系類之間的聯(lián)系用引用實(shí)現(xiàn)特定的引用類型通過增加/刪除逆鏈接來實(shí)施完整性.類型d_Rel_Ref<Class,InvRef>是對Class的引用,其中Class的屬性InvRef是逆引用.類似地,d_Rel_Set<Class,InvRef>用于引用的集合類d_Rel_Ref的賦值方法(=)是重載的用類型定義來自動查找及更新逆鏈接使程序員免除更新逆鏈接的任務(wù)消除不一致鏈的可能性類似地,d_Rel_Set的insert_element()和delete_element()方法利用類型定義自動查找及更新逆鏈接第32頁,共100頁,2023年,2月20日,星期四實(shí)現(xiàn)聯(lián)系E.g.

externconstchar_owners[],_accounts[];

classAccount:publicd.Object{

….

d_Rel_Set<Customer,_accounts>owners;

}

//..Sincestringscan’tbeusedintemplates…

constchar_owners=“owners”;

constchar_accounts=“accounts”;第33頁,共100頁,2023年,2月20日,星期四ODMGC++對象操縱語言使用C++運(yùn)算符的持久性版本,如

new(db)

d_Ref<Account>account=new(bank_db,“Account”)Account;new在指定數(shù)據(jù)庫中分配對象,而不是在內(nèi)存中.第二個參數(shù)(“Account”)給出數(shù)據(jù)庫中用的類型名.當(dāng)去除引用運(yùn)算符->作用于d_Ref<Account>引用時,在繼續(xù)通常的C++去除引用之前先加載被引用對象到內(nèi)存(如果不在內(nèi)存的話)類的構(gòu)造子–創(chuàng)建對象時用于初始化對象的特殊方法;對new自動調(diào)用.在創(chuàng)建與刪除對象時類外延自動被維護(hù)僅針對說明了此特性的類通過用戶接口說明,而非C++早期版本的ODMG不支持自動維護(hù)類外延第34頁,共100頁,2023年,2月20日,星期四ODMGC++OML:數(shù)據(jù)庫與對象函數(shù)類d_Database提供方法打開數(shù)據(jù)庫:open(databasename)

命名對象:set_object_name(object,name)用名查找對象:lookup_object(name)重命名對象:rename_object(oldname,newname)關(guān)閉數(shù)據(jù)庫:close()類d_Object被所有持久性類繼承.提供方法分配及刪除對象更新對象之前必須調(diào)用方法mark_modified().創(chuàng)建對象時自動調(diào)用第35頁,共100頁,2023年,2月20日,星期四ODMGC++OML:例intcreate_account_owner(Stringname,StringAddress){ d_Databasebank_db.obj;

d_Database*bank_db=&bank_db.obj;

bank_db->open(“Bank-DB”);

d_TransactionTrans;

Trans.begin();

d_Ref<Account>account=new(bank_db)Account;

d_Ref<Customer>cust=new(bank_db)Customer;

cust->name=name;

cust->address=address;

cust->accounts.insert_element(account);

...Codetoinitializeotherfields

Tmit();}第36頁,共100頁,2023年,2月20日,星期四ODMGC++OML:例數(shù)據(jù)庫中類外延自動維護(hù).為存取類外延:

d_Extent<Customer>customerExtent(bank_db);類d_Extent提供方法

d_Iterator<T>create_iterator()

來創(chuàng)建一個類外延上的迭代子提供select(pred)方法以返回滿足選擇謂詞pred的對象上的迭代子.迭代子用于遍歷集合或類外延中的對象.匯集(sets,lists等)也提供方法create_iterator().第37頁,共100頁,2023年,2月20日,星期四ODMGC++OML:迭代子例intprint_customers(){

Databasebank_db_obj;

Database*bank_db=&bank_db_obj;

bank_db->open(“Bank-DB”);

d_TransactionTrans;Trans.begin();

d_Extent<Customer>all_customers(bank_db);

d_Iterator<d_Ref<Customer>>iter;

iter=all_customers–>create_iterator();

d_Ref<Customer>p; while{iter.next(p))

p->print_cust();//Functionassumedtobedefinedelsewhere Tmit();}第38頁,共100頁,2023年,2月20日,星期四ODMGC++Binding:其他特性說明性查詢語言O(shè)QL,看上去像SQL形成查詢字符串,執(zhí)行之得到返回結(jié)果集合(實(shí)際上是bag,因?yàn)榭赡苡兄貜?fù))

d_Set<d_Ref<Account>>result;

d_OQL_Queryq1("selecta

fromCustomerc,c.accountsa

where=‘Jones’

anda.find_balance()>100");

result=q1.d_oql_execute();提供基于C++例外的出錯處理機(jī)制,通過類d_Error提供API用來存取數(shù)據(jù)庫模式.第39頁,共100頁,2023年,2月20日,星期四使指針持久性透明ODMG1.0C++方法的缺點(diǎn):兩種指針程序員必須確保調(diào)用mark_modified(),否則數(shù)據(jù)庫可能被破壞ObjectStore方法內(nèi)存中與數(shù)據(jù)庫中的對象使用完全相同的指針類型持久性對應(yīng)用是透明的創(chuàng)建對象時例外由于指針類型相同,同樣的函數(shù)可以用在內(nèi)存中對象和持久對象上實(shí)現(xiàn)時采用一種稱為指針swizzling的技術(shù),第11章有具體描述.不需要調(diào)用mark_modified(),因?yàn)榭梢宰詣颖O(jiān)測到更新.第40頁,共100頁,2023年,2月20日,星期四ODMG2.0ObjectQueryLanguageObjectQueryLanguage,PrinciplesDeclarativequerylanguage(SQL-like)CanbeoptimizedSyntaxbasedonSQLQueriescanreturn:AcollectionofobjectsAnobjectAcollectionofliteralsAliteral第41頁,共100頁,2023年,2月20日,星期四ODMGLanguageBindings,Why?Extendprogramminglanguagewithpersistentcapability

MigrateprogrammingapplicationsinmemorytoDBManipulateobjectdatabaseswithstandardprogramminglanguageProvidetoprogramminglanguagedatabasefunctionality:Querying,Transactions,Indexing,…第42頁,共100頁,2023年,2月20日,星期四ODMGLanguageBindingsBindingsforODL,OMLandOQLSingle,unifiedtypesystempersistentortransientinstancesLanguage-specificbindingsrespectthesyntaxandsemanticsofthebaselanguageSmallsetofextensionsCanmixexpressionsofOML,OQLandbaselanguage第43頁,共100頁,2023年,2月20日,星期四C++Binding:DesignPrinciplesProvideaC++librarywherethereisaunifiedtypesystemacrosstheprogramminglanguageandthedatabaseTheC++bindingmapstheODMGObjectModelintoC++throughasetof"persistence-capable"classes

UsesC++templateclassesforimplementationBasedonthesmartpointer("ref-based")approachMainFeaturesMappingbetweenODMGtypesandC++typesC++/OQLCouplingTheOML/C++isC++compliant(i.e.standardC++compilers)CompatiblewithStandardTemplateLibrary(STL)+persistence第44頁,共100頁,2023年,2月20日,星期四Persistence-capableClassesForeachpersistence-capableclassT,atwinclassd_Ref<T>isdefinedInstancesofapersistence-capableclassbehavelikeC++pointers(butOIDs

1C++pointer)TheC++bindingdefinestheclassd_Objectasthesuperclassofallpersistence-capableclassesPersistencepropagationbyinheritanceThenotionofinterfaceisimplicitinODMGC++binding

interface:publicpartofC++classdefinitionsimplementation:privatepartsofC++classdefinitions第45頁,共100頁,2023年,2月20日,星期四C++BindingC++ODLMaybegenerated(fromODMGODL)orprogrammer-writtenC++OMLC++OQL第46頁,共100頁,2023年,2月20日,星期四C++ODLBasicTypesBasicTypeRangeDescriptiond_Short16bitssignedintegerd_Long32bitssignedintegerd_UShort16bitsunsignedd_ULong16bitsunsignedd_Float32bitsSingleprecisiond_Double64bitsdoubleprecisiond_Char8bitsASCII………第47頁,共100頁,2023年,2月20日,星期四C++ODLd_RefAd_Refisparameterizedbythetypeofthereferencedobjectd_Ref<Employee>Employee;d_Ref<Dept>Dept;Dept=Employee->Departmentd_Refisdefinedasaclasstemplate:Template<classT>classd_Ref{…..}Thedereferencingoperator(->)isusedtoaccessmembersofthepersistentobject“addressed”bythespecificreference第48頁,共100頁,2023年,2月20日,星期四C++ODLCollectiond_Set,d_Bag,d_list,d_Array,d_Dictionaryaresubclassofd_CollectionThecollectionsclassesaredefinedasclasstemplates:Template<classT>classd_Collection{…..}Template<classT>classd_Set:publicd_Collection{…..}Elementsthereinareaccessedthroughiterators第49頁,共100頁,2023年,2月20日,星期四MappingtheODMGODLintoC++ODLClassCSet<T>Bag<T>List<T>Array<T>RelationshipTExtentofclassTOperationCreateDeleteBasictypesTd_Ref<C>d_Set<T>d_Bag<T>d_List<T>d_Array<T>d_Rel_Ref<T>D_Extent<T>C++functionsConstructor,Destructord_T:d_String,d_Time,d_Date,d_Boolean第50頁,共100頁,2023年,2月20日,星期四C++ODLExampleclassPerson(extentpeople){private:AttributeStringname;AttributeSet<Person>spouse;AttributeSet<Person>children;AttributeList<Person>parents;public:Person(char*name);voidbirth(Personchild);voidmarriage(Personspouse);Stringget_name(){returnname;}List<Person>get_children() {returnchildren;};};classPerson{private:d_Stringname;d_Ref<Person>spouse;d_List<d_Ref<Person>>children;d_List<d_Ref<Person>>parents;public:Person(char*name);voidbirth(d_Ref<Person>child);voidmarriage(d_Ref<Person>spouse);d_Stringget_name(){returnname;}d_List<d_Ref<Person>>get_children() {returnchildren;};d_Set<d_Ref<Person>>*people;};第51頁,共100頁,2023年,2月20日,星期四C++OMLStandardC++syntaxusedObjectcreation/modification/deletionManipulationcollectionsOQLembeddedinC++Databasesandtransactionssupportedthroughclasslibraries第52頁,共100頁,2023年,2月20日,星期四ObjectCreation/DeletionPerson::Person(char*pname){ this->name=pname; people->insert_element(this);}d_Ref<Person>toto;toto=newPerson(“Toto”);

第53頁,共100頁,2023年,2月20日,星期四Using“This”notationVoidPerson::marriage(d_Ref<Person>with){ this->spouse=with; with->spouse_=this;}d_Ref<Person>toto,tata;toto=newPerson(“Toto”);tata=newPerson(“Tata”);toto->marriage(tata);

第54頁,共100頁,2023年,2月20日,星期四ObjectNaming&d_DatabaseclassToretrieveobjectsinadatabaseweneedpersistentnamesThesesnamesaretherootofthepersistencyAnamecanidentifyauniqueobjectoracollectionofobjectsOthersupportedoperationsincludeopeningandclosinganexistingdatabase.第55頁,共100頁,2023年,2月20日,星期四ObjectNaming&d_Databaseclass:

Exampled_Databasedatabase;database.open(“family”);database.create_persistent_root(“Toto”,”d_Ref<Person>”);database.create_persistent_root(“people”, ”d_Set<d_Ref<Person>>”);

d_Ref<Person>toto(“Toto”);d_Set<d_Ref<Person>>people(people);toto=newPerson(“Toto”);Person*titi;titi=newPerson(“titi”);toto->spouse=titi;

第56頁,共100頁,2023年,2月20日,星期四ManipulatingCollectionVoidPerson::birth(d_Ref<Person>child){ this->children.insert_element_last(child); child->parents.insert_element_last(this); if(spouse_!=0){ spouse->children.insert_element_last(child); child->parents.insert_element_last(spouse);}d_Ref<Person>toto,tata;toto=newPerson(“Toto”);tata=newPerson(“Tata”);toto->marriage(tata);toto->birth(newPerson(“Titi”));

第57頁,共100頁,2023年,2月20日,星期四IteratingonCollectionsToiterateoncollectionsatemplateclassd_Iterator<T>isdefinedIteratorscanbeobtainedthoughthecreate_iteratormethoddefinedintheclassd_CollectionTheget_elementfunctionreturnthevalueofthecurtrently“pointed-to”elementinthecollectionThenextfunctioncheckstheendofiteration,advancingtheiteratorandreturningthecurrentelementIteratorsmeangreatflexibility:Collectiontypeindependence,Elementtypeindependence.

第58頁,共100頁,2023年,2月20日,星期四IteratingonCollections:Examplevoidprint_persons(d_Collection<d_Ref<Person>>s){ d_Ref<Person>p; d_Iterator<d_Ref<Person>>it=s.create_iterator(); while(it.next(p)) cout<<p->get_name()<<endl;} 第59頁,共100頁,2023年,2月20日,星期四OQLEmbeddedinC++Anobjectoftyped_OQL_QuerymustbeconstructedThequerymustbeexecutedwiththed_oql_executefunctionQueriesareconstructedincrementallyusing<<Queriescanbeparameterized:parametersinthequeryare$i,theshift-leftoperator(<<)isusedtoprovidevalues.

第60頁,共100頁,2023年,2月20日,星期四OQLEmbeddedinC++:Exampled_List<d_Ref<Person>>list;d_OQL_Queryq1(“sortpinpeoplebyp.get_name”);d_oql_execute(q1,list);d_Ref<Person>Toto;d_OQL_Queryq1(“element(selectpfrompinpeoplewherep.get_name==$1”);q1<<“Toto”;d_oql_execute(q1,Toto);第61頁,共100頁,2023年,2月20日,星期四持久性Java系統(tǒng)ODMG-3.0定義了對Java的持久性擴(kuò)充Java不支持模板,因此需要對語言進(jìn)行擴(kuò)充持久性模型:按可達(dá)性持久配合Java的垃圾收集模型對數(shù)據(jù)庫同樣需要垃圾收集對短暫和持久指針只有一種指針類型第62頁,共100頁,2023年,2月20日,星期四持久性Java系統(tǒng)通過對Java編譯器生成的目標(biāo)代碼執(zhí)行一個后處理器使得類成為可持久的(persistencecapable)與C++中用的預(yù)處理器不同后處理器自動加上mark_modified()定義匯集類型DSet,DBag,DList,etc.使用Java迭代子,不需要新的迭代子類第63頁,共100頁,2023年,2月20日,星期四持久性Java系統(tǒng)事務(wù)必須從根對象之一開始存取數(shù)據(jù)庫(按名查找)從根對象沿指針找到其他對象被一個已讀取對象所引用的對象也在內(nèi)存分配空間,但不一定讀取讀取可以是以懶惰方式進(jìn)行的已分配空間但尚未讀取的對象稱為空洞對象(hollowobject)訪問空洞對象時,其數(shù)據(jù)才從磁盤讀取.第64頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

Acall-levelinterface:JDBCLowLevel,InvokeSQLCommandsDirectlyABaseUponWhichtoBuildHigher-levelInterfacesandTools,suchasSQLJJavaBlendWhatdoesJDBCdo?EstablishaConnectionwithaDatabaseSendSQLStatementsProcesstheResultsLatestUpdate:JDBC4.0APICoreAPIStandardExtensions第65頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

JDBC2.0APINewFeaturesofJDBCCoreAPIScrollableResultSetsResultSetsthatcanbeUpdatedBatchUpdatesSQL3DataTypeSupport(SQLtypesARRAY,BLOB,CLOB,STRUCT,DISTINCTandREF)CustomMappingofSQL3User-DefinedTypestoJavaClassesStoringJavaObjectsinanObject-RelationalDatabase第66頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

JDBC2.0APIJDBC2.0APIStandardExtensionRowsetEstablishingDatabaseConnectionsUsingDataSourceObjectsandtheJavaNamingandDirectoryInterfaceTM(JNDI)ConnectionPoolingDistributedTransactions第67頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

JDBCProductADistributedObjectJDBCArchitecture

OPENjdbc,theJDBCDriverforDataBrokerCORBA-basedJDBCsolutionprovidesacompletetechnologybridgefromcurrenttofutureITsolutions第68頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

EmbeddedSQLStatements:SQLJALanguagethatEmbedsStaticSQLinJavaProgramSpecifiedbyOracle,IBMandCompaq'sTandemJointly,AcceptedasANSIStandardinDecember1998HowDoesSQLJwork?第69頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

SQLJFeaturesPrecededby:#sql#sql{UPDATETABSETCOL1=:xWHERECOL2>:yANDCOL3<:z};ProvidesApplicationDeveloperswithaHigher-levelProgrammingInterfaceforStaticSQLSQLJtranslatorperformstype-checkingandschema-checkingofSQLstatementsatprogramdevelopmenttimeSQLJRuntime,aThinLayerofPureJavaCodeaboveaJDBCDriverComprehensiveFacilitiesDatabaseIndependence第70頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

SQLJandOracle8iOracleDatabaseServer--Oracle8iJavavirtualmachineinternaltothedatabaseOracleExtendsSupportforStandardsBasedSQLJImplementedSQLJintoOracle8iSupportsAccesstoBLOBandCLOBDataSupportsSQLObjectTypesinSQLJProgramsthroughJPulishertoolJavaStoredProceduresandTriggersProvidesAccesstoOracleProprietaryLanguagePL/SQLUsingSQLJinOracle8iEJBServerOracelJavaIDE--JDeveloper第71頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

SQLJExampleimportjava.sql.*;importsqlj.runtime.ref.DefaultContext;importoracle.sqlj.runtime.Oracle;

publicclassJDBCInterop{

#sqlpublicstaticiteratorEmployees(Stringename,doublesal);

publicstaticvoidmain(String[]args)throwsSQLException{

if(args.length!=1){

System.out.println("usage:JDBCInterop");

System.exit(1);

} Oracle.connect(JDBCInterop.class,"perties");

Connectionconn= DefaultContext.getDefaultContext().getConnection();

第72頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

SQLJExample

//createaJDBCStatementobjecttoexecuteadynamicquery

Statementstmt=conn.createStatement();

Stringquery="SELECTename,salFROMempWHERE";

query+=args[0];

//usetheresultsetreturnedbyexecutingthequerytocreate

//anewstrongly-typedSQLJiterator

ResultSetrs=stmt.executeQuery(query);

Employeesemps;

#sqlemps={CAST:rs};

while(emps.next()){

System.out.println(emps.ename()+"earns"+emps.sal());

}

emps.close();

stmt.close();

}}第73頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

ODMGJavaBindingImpedanceMismatchObjectDataManagementGroup(ODMG)JavaBindingwasAddedtoODMG2.0AppliestobothODBMSandRDBMSPersistencebyReachabilityDatabaseTransparencyAutomaticallyMappingbetweenDatabaseandaCacheintheApplicationMemoryJavaObjectsareMappedintotheCacheWhenApplicationNavigatesthroughthemDatabaseTracksJavaObjectsintheCacheandWritethembacktoDatabaseatTransactionCommitTime第74頁,共100頁,2023年,2月20日,星期四DatabaseServerJavaDatabaseSupport

ODMGJavaBindingThree-TierModelClient...GUIApplicationLogicApplicationLogicObjectManagementApplicationLogicObjectManagementApplicationServers第75頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

ODMGJavaBindingComponentsJavaObjectDefinitionLanguage(ODL)DefinetheSpecificationsofObjectTypesthatConformtotheODMGObjectModelJavaObjectManipulationLanguage(OML)SupporttheODMGObjectModelwithCollections,TransactionsandDatabasesJavaObjectQueryLanguage(OQL)ProvidesFastandEfficientObject-QueryingCapabilitiesinJavaOQLQueriesandJavaMethodscancalleachotherinterchangeably第76頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

ODMGJavaBindingProduct1VisualBSFfromObjectmatterObject-relationalJavaFrameworkthatAllowsJavaObjectstobeEasilySavedandRetrievedfromRelationalDatabasesNon-intrusiveandDynamicOpenArchitectureCompleteObjectModelingLegacyDatabaseIntegrationSecurityPowerfulQueryCapabilitiesStandardsBasedFastPerformance

第77頁,共100頁,2023年,2月20日,星期四JavaDatabaseSupport

ODMGJavaBindingProduct2POETObjectServer5.0fromPOETPOET'sJavaSDKandSQLObjectFactoryAddsDistributedandEnterpriseCriticalFeatureODMG2.0CompliantJavaAPIBindingJavaObjectsareMappedtothePOETObjectDatabaseoraRelationalDatabaseatRuntimeTransparentJavaObjectPersistenceMulti-threadingandTransactionCapabilitiesTierIndependentOtherProductsJavaBlend,Jasmine…

第78頁,共100頁,2023年,2月20日,星期四IntroductiontoEnterpriseJavaBeansWhatisEJB?ServersidecomponentimplementingbusinesslogicwrappingDBwrappingexistingapplicationprovidingnewbusinessfunctionsSimilartoJavaBeanwrappedinejb-jarvisualdeploymentandmanagementEasyprogrammingWriteonce,runanywhere(clientandserver)Reusable第79頁,共100頁,2023年,2月20日,星期四Multi-tierEJBApplications(**)Heavy-dutyserversintheorganizationsDeployedoverintranetImprovedperformanceImprovedmanageabilityEasiermaintenanceIn-controlsystemupgradeThinclientsGUIpresentationEasytodownloadPossiblebuilt-inupgradingfeatures第80頁,共100頁,2023年,2月20日,星期四High-levelViewofaSimpleScenarioTransparentinvocationContainer-managedpersistencyTransaction第81頁,共100頁,2023年,2月20日,星期四EJBRolesandDeployment第82頁,共100頁,2023年,2月20日,星期四Client’sViewContractContractbetweenclientandcontainerFulfilledbybothEJBproviderandcontainerproviderIncludesIdentityMethodinvocationHomeinterfaceJNDINamingconventionSessionBeanexample:TraderBeanTraderTraderHome第83頁,共100頁,2023年,2月20日,星期四SessionBeanExamplepublicclassTraderBeanimplementsSessionBean{

publicvoidejbRemove()throws...{...}publicvoidejbActivate()…{…}publicvoidejbPassivate()...publicvoidsetSessionContext(SessionContextctx)...

publicvoidejbCreate()...

publicTradeResultbuy(...)...publicTradeResultsell(...)...publicdoublegetStockPrice(StringstockSymbol)...}publicinterfaceTraderHomeextendsEJBHome{Tradercreate()…}publicinterfaceTraderextendsEJBObject{publicTradeResultbuy(...)...publicTradeResultsell(...)...publicdoublegetStockPrice(StringstockSymbol)...}第84頁,共100頁,2023年,2月20日,星期四ComponentContractContractbetweenBeanandcontainerIncludesBeanclassinstance’sviewofitslifecycleForsessionBeans,statemanagementcallbackmethodsinvokedby

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論