outline
play

Outline Object-orientation and databases CS 235: Object-oriented - PDF document

Outline Object-orientation and databases CS 235: Object-oriented model: ODL Object Query Language Introduction to Databases Svetlozar Nestorov Lecture Notes #15 CS 235: Introduction to Databases 2 Object-Oriented DBMSs ODMG


  1. Outline � Object-orientation and databases CS 235: � Object-oriented model: ODL � Object Query Language Introduction to Databases Svetlozar Nestorov Lecture Notes #15 CS 235: Introduction to Databases 2 Object-Oriented DBMS’s ODMG Compliant Databases � Jasmine (Computer Associates) � ODMG = Object Data Management Group: an OO standard for databases. � TITANIUM (MicroDB Systems) � ObjectStore (EXcelon) � ODL = Object Description Language: design in the OO style. � Objectivity (Objectivity) � POET Object Server (POET Soft.) � OQL = Object Query Language: queries an OO database with an ODL schema, in a � Versant ODBMS (Versant Corp.) manner similar to SQL. � OO databases account for less than 2% of database market. CS 235: Introduction to Databases 3 CS 235: Introduction to Databases 4 ODL Overview ODL Class Declarations interface <name> { Class declarations ( interfaces ). � elements = attributes, relationships, Interface includes: � methods } 1. Name for the interface. 2. Key declaration(s), which are optional. � Element Declarations attribute <type> <name>; 3. Extent declaration = name for the set of relationship <rangetype> <name>; currently existing objects of a class. � Relationships involve objects; attributes involve non-object values, e.g., integers. 4. Element declarations. An element is an attribute, a relationship, or a method. CS 235: Introduction to Databases 5 CS 235: Introduction to Databases 6 1

  2. Method Example ODL Relationships � Only binary relations supported. float gpa(in name) raises(noGrades) • Multiway relationships require a “connecting” � float = return type. class, as discussed for E/R model. � in : indicates the argument (a student � Relationships come in inverse pairs. name) is read-only. � Example: Sells between beers and bars is • Other options: out, inout. represented by a relationship in bars, giving the beers sold, and a relationship in � noGrades is an exception that can be beers giving the bars that sell it. raised by method gpa. CS 235: Introduction to Databases 7 CS 235: Introduction to Databases 8 More ODL Relationships Beers-Bars-Drinkers Example � Many-many relationships have a set type interface Beers { attribute string name; (called a collection type ) in each direction. attribute string manf; � Many-one relationships have a set type for relationship Set<Bars> servedAt inverse Bars::serves; the one, and a simple class name for the relationship Set<Drinkers> fans many. inverse Drinkers::likes; } � One-one relations have classes for both. � An element from another class is indicated by <class> : : � Form a set type with Set < type > . CS 235: Introduction to Databases 9 CS 235: Introduction to Databases 10 Bars ODL Drinkers ODL interface Bars { interface Drinkers { attribute string name; attribute string name; attribute Struct Addr {string street, string city, int zip} address; attribute Struct Bars::Addr attribute Enum Lic {full, beer, none} licenseType; address; relationship Set<Drinkers> customers relationship Set<Beers> likes inverse Drinkers::frequents; relationship Set<Beers> serves inverse Beers::fans; inverse Beers::servedAt; relationship Set<Bars> frequents } inverse Bars::customers; � Structured types have names and bracketed lists of field- } type pairs. � Note reuse of Addr type. � Enumerated types have names and bracketed lists of values. CS 235: Introduction to Databases 11 CS 235: Introduction to Databases 12 2

  3. ODL Type System Many-One Relationships � Don’t use a collection type for relationship in the “many” � Basic types: int, real/float, string, enumerated class. types, and classes. � Drinkers have favorite beers: � Type constructors: Struct for structures and four interface Drinkers { … collection types : Set, Bag, List, and Array. relationship Beers favoriteBeer � Limitation on nesting: inverse Beers::realFans; … • Relationships: class – collection } � Also add to Beers: • Attributes: basic – struct – collection relationship Set<Drinkers> realFans inverse Drinkers::favoriteBeer; CS 235: Introduction to Databases 13 CS 235: Introduction to Databases 14 Example: Multiway Relationship Example (contd.) Consider a 3-way relationship bars-beers-prices. We have to create � � Inverses for theBar, theBeer must be a connecting class BBP. added to Bars, Beers. interface Prices { attribute real price; � Better in this special case: make no Prices relationship Set<BBP> toBBP class; make price an attribute of BBP. inverse BBP::thePrice; } � Notice that keys are optional. interface BBP { • BBP has no key, yet is not “weak.” Object relationship Bars theBar inverse ... identity suffices to distinguish different BBP relationship Beers theBeer inverse ... objects. relationship Prices thePrice inverse Prices::toBBP; } CS 235: Introduction to Databases 15 CS 235: Introduction to Databases 16 Roles in ODL ODL Subclasses Names of relationships handle roles. E.g. Spouses and Drinking Buddies � Follow name of subclass by colon and its � interface Drinkers { superclass. attribute string name; attribute Struct Bars::Addr � Example: Ales are Beers with a Color address; interface Ales:Beers { relationship Set<Beers> likes inverse Beers::fans; attribute string color; relationship Set<Bars> frequents } inverse Bars::customers; relationship Drinkers husband � Objects of the Ales class acquire all the inverse wife; attributes and relationships of the Beers class. relationship Drinkers wife inverse husband; � While E/R entities can have manifestations in a relationship Set<Drinkers> buddies class and subclass, in ODL we assume each inverse buddies; } object is a member of exactly one class. Notice that Drinkers:: is optional when the inverse is a relationship of the � same class. CS 235: Introduction to Databases 17 CS 235: Introduction to Databases 18 3

  4. Keys in ODL Example � Indicate with key(s) following the class name, interface Beers (key name) and a list of attributes forming the key. {attribute string name …} � Several lists may be used to indicate several alternative keys. interface Courses � Parentheses group members of a key, and also (key (dept, number), (room, hours)) group key to the declared keys. {...} � Thus, (key( a 1, a 2… a n )) = “one key consisting of � Keys are optional in ODL. The object ID all n attributes.” (key a 1, a 2… a n ) = “each a i is a suffices to distinguish objects that have key by itself.” the same values in their elements. CS 235: Introduction to Databases 19 CS 235: Introduction to Databases 20 Translating ODL to Relations ODL Class Without Relationships � Problem: ODL allows attribute types built from 1. Classes without relationships: like entity structures and collection types. set, but several new problems arise. � Structure: Make one attribute for each field. 2. Classes with relationships: � Set: make one tuple for each member of the set. a) Treat the relationship separately, as in E/R. • More than one set attribute? Make tuples for all combinations. b) Attach a many-one relationship to the � Problem: ODL class may have no key, but we relation for the many. should have one in the relation to represent “OID.” CS 235: Introduction to Databases 21 CS 235: Introduction to Databases 22 Example: ODL Example: Relations interface Drinkers (key name) { name street city zip phone n 1 s 1 c 1 z 1 p 1 attribute string name; n 1 s 1 c 1 z 1 p 2 attribute Struct Addr � Surprise: the key for the class (name) is not the {string street, string city, int zip} address; key for the relation (name, phone). attribute Set<string> phone; • name in the class determines a unique object, including a set of phones. } • name in the relation does not determine a unique tuple. • Since tuples are not identical to objects, there is no inconsistency! � BCNF violation: separate out name-phone. CS 235: Introduction to Databases 23 CS 235: Introduction to Databases 24 4

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