odl sub classes f ollo w name of sub class b y colon and
play

ODL Sub classes F ollo w name of sub class b y colon and - PDF document

ODL Sub classes F ollo w name of sub class b y colon and its sup erclass. Example: Ales are Beers with a Color class Ales:Beers { attribute string color; } Ob jects of the class acquire all the Ales


  1. ODL Sub classes F ollo w name of sub class b y colon and its sup erclass. Example: Ales are Beers with a Color class Ales:Beers { attribute string color; } Ob jects of the class acquire all the Ales � attributes and relationships of the class. Beers While E/R en tities can ha v e manifestations in � a class and sub class, in ODL w e assume eac h ob ject is a mem b er of exactly one class. 1

  2. Keys in ODL Indicate with follo wing the class name, and key(s) a list of attributes forming the k ey . Sev eral lists ma y b e used to indicate sev eral � alternativ e k eys. P aren theses group mem b ers of a k ey , and also � group to the declared k eys. key Th us, = \one (key( a ; a ; : : : ; a )) � 1 2 n k ey consisting of all attributes." n = \eac h is a k ey b y a ; a ; : : : ; a a (key ) 1 2 n i itself." Example class Beers (key name) { attribute string name ... : Keys are optional in ODL. The R ememb er � \ob ject ID" su�ces to distinguish ob jects that ha v e the same v alues in their elemen ts. 2

  3. Example: Multiple Multiattribut e Keys class Courses (key (dept, number), (room, hours)) { ... 3

  4. T ranslating ODL to Relations 1. Classes without relationships: lik e en tit y set, but sev eral new problems arise. 2. Classes with relationships: a) T reat the relationship separately , as in E/R. b) A ttac h a man y-one relationship to the relation for the \man y ." 4

  5. ODL Class Without Relationships Problem: ODL allo ws attribute t yp es built � from structures and collecti on t yp es. Structure: Mak e one attribute for eac h �eld. � Set: mak e one tuple for eac h mem b er of the � set. ✦ More than one set attribute? Mak e tuples for all com binations. Problem: ODL class ma y ha v e no k ey , but w e � should ha v e one in the relation to represen t \OID." 5

  6. Example class Drinkers (key name) { attribute string name; attribute Struct Addr {string street, string city, int zip} address; attribute Set<string> phone; } name street cit y zip phone n s c z p 1 1 1 1 1 n s c z p 1 1 1 1 2 Surprise: the k ey for the class (name) is not � the k ey for the relation (name, phone). ✦ in the class determines a unique name ob ject, including a of phones. set ✦ in the relation do es not determine a name unique tuple. ✦ Since tuples are not iden tical to ob jects, there is no inconsistency! BCNF violati on: separate out name-phone. � 6

  7. ODL Relationships If the relationship is man y-one from to , A B � put k ey of attributes in the relation for class B A . If relationship is man y-man y , w e'll ha v e to � duplicate A -tuples as in ODL with set-v alued attributes. ✦ W ouldn't y ou really rather create a separate relation for a man y-man y- relationship? ✦ Y ou'll wind up separating it an yw a y , during BCNF decomp osition. 7

  8. Example class Drinkers (key name) { attribute string name; attribute string addr; relationship Set<Beers> likes inverse Beers::fans; relationship Beers favorite inverse Beers::realFans; relationship Drinkers husband inverse wife; relationship Drinkers wife inverse husband; relationship Set<Drinkers> buddies inverse buddies; } Drink ers(name, addr, b eerName , fa vBeer, wife, budd y) 8

  9. Decomp ose in to 4NF FD's: name ! addr fa vBeer wife � MVD's name ! b eerName, name ! buddy � ! ! Resulting decomp osition: � Drinkers(name , addr, favBeer, wife) DrBeer(name , beer ) DrBuddy(name , buddy) 9

  10. OQL Motiv atio n: Relational languages su�er from imp e danc e � when w e try to connect them to mismatch con v en tional languages lik e C or C++. ✦ The data mo dels of C and SQL are radically di�eren t, e.g. C do es not ha v e relations, sets, or bags as primitiv e t yp es; C is tuple-at-a-time, SQL is relation-at-a- time. OQL is an attempt b y the OO comm unit y � to extend languages lik e C++ with SQL-lik e, relation-at-a-time dictions. 10

  11. OQL T yp es Basic t yp es: strings, in ts, reals, etc., plus class � names. T yp e constructors: � ✦ for structures. Struct ✦ Collecti on t yp es: set, bag, list, arra y . Lik e ODL, but no limit on the n um b er of � times w e can apply a t yp e constructor. Set(Struct()) and Bag(Struct()) pla y sp ecial � roles akin to relations. 11

  12. OQL Uses ODL as its Sc hema-De�nition P ortion F or ev ery class w e can declare an = extent � name for the curren t set of ob jects of the class. ✦ Remem b er to refer to the exten t, not the class name, in queries. 12

  13. class Bar (extent Bars) { attribute string name; attribute string addr; relationship Set<Sell> beersSold inverse Sell::bar; } class Beer (extent Beers) { attribute string name; attribute string manf; relationship Set<Sell> soldBy inverse Sell::beer; } class Sell (extent Sells) { attribute float price; relationship Bar bar inverse Bar::beersSold; relationship Beer beer inverse Beer::soldBy; } 13

  14. P ath Expressions Let b e an ob ject of class . x C If is an attribute of , then = the v alue a C x:a � of in the ob ject. a x If is a relationship of , then = the r C x:r � v alue to whic h is connected b y . x r ✦ Could b e an ob ject or a collect i on of ob jects, dep ending on the t yp e of . r If is a metho d of , then x:m ( � � ) is the m C � � result of applying to x . m 14

  15. Examples Let b e a v ariable whose t yp e is Sell . s = the price in the ob ject s . s.price � = the address of the bar s.bar.addr � men tioned in s . ✦ Note: cascade of dots OK b ecause s.bar is an ct , not a collecti on. obje Example of Illegal Use of Dot b.beersSold.price , where is a ob ject. b Bar Wh y illegal ? Because is a of b.beersSold set � ob jects, not a single ob ject. 15

  16. OQL Select-F rom-Where < list of v alues > SELECT < list of collecti ons and FROM t ypical mem b ers > < condition > WHERE Collecti ons in can b e: FROM � 1. Exten ts. 2. Expressions that ev aluate to a collecti on. F ollo wing a collecti on is a name for a t ypical � mem b er, optionally preceded b y AS . Example Get the men u at Jo e's. SELECT s.beer.name, s.price FROM Sells s WHERE s.bar.name = "Joe's Bar" Notice double-quoted strings in OQL. � 16

  17. Example Another w a y to get Jo e's men u, this time fo cusing on the ob jects. Bar SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" Notice that the t ypical ob ject in the �rst b � collecti on of is used to help de�ne the FROM second collecti on. T ypical Usage If is an ob ject, y ou can extend the path x � expression, lik e or in s.beer.name . s s.beer If is a collect i on, y ou use it in the list, x FROM � lik e ab o v e, if y ou w an t to access b.beersSold attributes of x . 17

  18. T ailoring the T yp e of the Result Default: bag of structs, �eld names tak en from � the ends of path names in clause. SELECT Example SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" has result t yp e: Bag(Struct( name: string, price: real )) 18

  19. Rename Fields Pre�x the path with the desired name and a colon. Example SELECT beer: s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" has t yp e: Bag(Struct( beer: string, price: real )) 19

  20. Change the Collectio n T yp e Use to get a set of structs. SELECT DISTINCT � Example SELECT DISTINCT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" Use clause to get a list of structs. ORDER BY � Example joeMenu = SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" ORDER BY s.price ASC = ascending (default); = descending. ASC DESC � W e can extract from a list as if it w ere an � arra y , e.g. cheapest = joeMenu[1].name; 20

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend