Object-Oriented DBMS’s

Slides:



Advertisements
Similar presentations
Databases : Relational Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Advertisements

Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
Fall 2001Arthur Keller – CS 18016–1 Schedule Nov. 20 (T) More OQL. u Read Sections Assignment 7 due (late ones by ). Nov. 22 (TH) Thanksgiving.
Winter 2002Arthur Keller – CS 18015–1 Schedule Today: Feb. 28 (TH) u Datalog and SQL Recursion, ODL. u Read Sections , Project Part 6.
Winter 2002Arthur Keller – CS 18012–1 Schedule Today: Feb. 19 (T) u Object-Relational Systems. u Read Sections 4.5, Assignment 5 due. Feb. 21.
Fall 2001Arthur Keller – CS 18015–1 Schedule Nov. 15 (TH) Object Queries (OQL). u Read Sections 9.1. Project Part 6 due on Sunday night. Nov. 20 (T) More.
Winter 2002Arthur Keller – CS 18016–1 Schedule Today: Mar. 5 (T) u More ODL, OQL. u Read Sections 9.1. Assignment 7 due. Mar. 7 (TH) u More OQL. u Read.
Fall 2001Arthur Keller – CS 18014–1 Schedule Nov. 13 (T) Object-Relational, O-R Queries. u Read Sections 4.5, Assignment 6 due. (No office hours.)
1 Other High-Level Design Languages Unified Modeling Language Object Description Language.
1 Announcements Research Paper due Monday November 22.
Databases Illuminated Chapter 7 The Object-Oriented Model.
Object and object-relational databases 1. Object databases vs. Object-relational databases Object databases Stores complex objects – Data + functions.
Winter 2006Keller Ullman Cushing8–1 Turning in Assignments Please turn in hard copy (use only in the direst of circumstances). I am not your secretary.
Winter 2006Keller, Ullman, Cushing9–1 Constraints Commercial relational systems allow much more “fine-tuning” of constraints than do the modeling languages.
1 Object-Oriented Database Languages Object Description Language Object Query Language.
Winter 2006Keller, Ullman, Cushing12–1 Object-Relational Systems Object-oriented ideas enter the relational world. u Keep relation as the fundamental abstraction.
Database Management COP4540, SCS, FIU Database Modeling A Introduction to object definition language (ODL)
1 Object-Oriented Database Languages Object Description Language Object Query Language.
Object Definition Language
Object Definition Language
Database Design Why do we need it? – Agree on structure of the database before deciding on a particular implementation. Consider issues such as: –What.
Winter 2006Keller Cushing Ullman17–1 Subqueries Used mainly in FROM clauses and with quantifiers EXISTS and FORALL. Example: Subquery in FROM Find the.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
© D. Wong Security and User Authorization in SQL 8.7 pp. 410  Authorization ID = user name  Special authorization ID: PUBLIC  Privileges for:
1 Introduction to SQL Database Systems. 2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation.
1 Unified Modeling Language. 2 UML  UML is designed to model software, but has been adapted as a database modeling language. – No multiway relationships.
1 Introduction to Database Systems, CS420 SQL Persistent Stored Modules (PSM) – Stored Procedure.
1 Database Design: DBS CB, 2 nd Edition Logical Database Model: Entity Relationship Model & Object Description Language & Unified Modeling Language Ch.
Database Design and Programming Jan Baumbach Adopted from previous slides of Peter Schneider-Kamp.
1. 2 Standards group: ODMG = Object Data Management Group. ODL = Object Description Language, like CREATE TABLE part of SQL. OQL = Object Query Language,
Introduction to Database Systems, CS420
Select-From-Where Statements Multirelation Queries Subqueries
CPSC-310 Database Systems
Object-Oriented Databases and the ODMG Standard
Entity-Relationship Model
Schedule Today: Jan. 28 (Mon) Jan. 30 (Wed) Next Week Assignments !!
Slides are reused by the approval of Jeffrey Ullman’s
CPSC-310 Database Systems
Computational Biology
Object-Relational Databases
Database Design Why do we need it? Consider issues such as:
Introduction to Database Systems, CS420
CPSC-310 Database Systems
CPSC-608 Database Systems
The Entity-Relationship Model
CS 440 Database Management Systems
Chapter 12 Outline Overview of Object Database Concepts
Instructor: Zhe He Department of Computer Science
Database Models Relational Model
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
IST 210: Organization of Data
Object-Relational Systems
CPSC-310 Database Systems
ISC321 Database Systems I Chapter 10: Object and Object-Relational Databases: Concepts, Models, Languages, and Standards Spring 2015 Dr. Abdullah Almutairi.
Object Definition Language
Persistent Stored Modules (PSM) PL/SQL Embedded SQL
Lecture 5: The Relational Data Model
The Relational Data Model
Chapter 15: Object-Oriented Database Development
CS 405G Introduction to Database Systems
CS 505: Intermediate Topics to Database Systems
CSC Database Management Systems
CPSC-608 Database Systems
CMSC-461 Database Management Systems
Instructor: Zhe He Department of Computer Science
Select-From-Where Statements Multirelation Queries Subqueries
CS 405G: Introduction to Database Systems
Presentation transcript:

Object-Oriented DBMS’s Keller Cushing Ullman Winter 2006 Object-Oriented DBMS’s ODMG = Object Data Management Group: an OO standard for databases. ODL = Object Description Language: design in the OO style. OQL = Object Query Language: queries an OO database with an ODL schema, in a manner similar to SQL. Winter 2006 Keller Ullman Cushing

ODL Overview Class declarations include: Name for the interface. Key declaration(s), which are optional. Extent declaration = name for the set of currently existing objects of a class. Element declarations. An element is an attribute, a relationship, or a method. Winter 2006 Keller Ullman Cushing

ODL Class Declarations class <name> { elements = attributes, relationships, methods } Element Declarations attribute <type> <name>; relationship <rangetype> <name>; Relationships involve objects; attributes involve non-object values, e.g., integers. Method Example float gpa(in string) raises(noGrades) float = return type. in: indicates the argument (a student name, presumably) is read-only. Other options: out, inout. noGrades is an exception that can be raised by method gpa. Winter 2006 Keller Ullman Cushing

ODL Relationships Only binary relations supported. Multiway relationships require a “connecting” class, as discussed for E/R model. Relationships come in inverse pairs. Example: “Sells” between beers and bars is represented by a relationship in bars, giving the beers sold, and a relationship in beers giving the bars that sell it. Many-many relationships have a set type (called a collection type) in each direction. Many-one relationships have a set type for the one, and a simple class name for the many. One-one relations have classes for both. Winter 2006 Keller Ullman Cushing

Beers-Bars-Drinkers Example class Beers { attribute string name; attribute string manf; relationship Set<Bars> servedAt inverse Bars::serves; relationship Set<Drinkers> fans inverse Drinkers::likes; } An element from another class is indicated by <class>:: Form a set type with Set<type>. Winter 2006 Keller Ullman Cushing

Structured types have names and bracketed lists of field-type pairs. class Bars { attribute string name; attribute Struct Addr {string street, string city, int zip} address; attribute Enum Lic {full, beer, none} licenseType; relationship Set<Drinkers> customers inverse Drinkers::frequents; relationship Set<Beers> serves inverse Beers::servedAt; } Structured types have names and bracketed lists of field-type pairs. Enumerated types have names and bracketed lists of values. Winter 2006 Keller Ullman Cushing

Note reuse of Addr type. class Drinkers { attribute string name; attribute Struct Bars::Addr address; relationship Set<Beers> likes inverse Beers::fans; relationship Set<Bars> frequents inverse Bars::customers; } Note reuse of Addr type. Winter 2006 Keller Ullman Cushing

ODL Type System Basic types: int, real/float, string, enumerated types, and classes. Type constructors: Struct for structures and four collection types: Set, Bag, List, Array, and Dictionary. Relationship types may only be classes or a collection of a class. Winter 2006 Keller Ullman Cushing

Many-One Relationships Don’t use a collection type for relationship in the “many” class. Example: Drinkers Have Favorite Beers class Drinkers { attribute string name; attribute Struct Bars::Addr address; relationship Set<Beers> likes inverse Beers::fans; relationship Beers favoriteBeer inverse Beers::realFans; relationship Set<Bars> frequents inverse Bars::customers; } Also add to Beers: relationship Set<Drinkers> realFans inverse Drinkers::favoriteBeer; Winter 2006 Keller Ullman Cushing

Example: Multiway Relationship Consider a 3-way relationship bars-beers-prices. We have to create a connecting class BBP. class Prices { attribute real price; relationship Set<BBP> toBBP inverse BBP::thePrice; } class BBP { relationship Bars theBar inverse ... relationship Beers theBeer inverse ... relationship Prices thePrice inverse Prices::toBBP; Inverses for theBar, theBeer must be added to Bars, Beers. Better in this special case: make no Prices class; make price an attribute of BBP. Notice that keys are optional. BBP has no key, yet is not “weak.” Object identity suffices to distinguish different BBP objects. Winter 2006 Keller Ullman Cushing

Roles in ODL Example: Spouses and Drinking Buddies Names of relationships handle “roles.” Example: Spouses and Drinking Buddies class Drinkers { attribute string name; attribute Struct Bars::Addr address; relationship Set<Beers> likes inverse Beers::fans; relationship Set<Bars> frequents inverse Bars::customers; relationship Drinkers husband inverse wife; relationship Drinkers wife inverse husband; relationship Set<Drinkers> buddies inverse buddies; } Notice that Drinkers:: is optional when the inverse is a relationship of the same class. Winter 2006 Keller Ullman Cushing

ODL Subclasses Example: Ales are Beers with a Color Follow name of subclass by colon and its superclass. Example: Ales are Beers with a Color class Ales:Beers { attribute string color; } Objects of the Ales class acquire all the attributes and relationships of the Beers class. While E/R entities can have manifestations in a class and subclass, in ODL we assume each object is a member of exactly one class. Winter 2006 Keller Ullman Cushing

Keys in ODL Indicate with key(s) following the class name, and a list of attributes forming the key. Several lists may be used to indicate several alternative keys. Parentheses group members of a key, and also group key to the declared keys. Thus, (key(a1,a2 , … , an)) = “one key consisting of all n attributes.” (key a1,a2 , … , an) = “each ai is a key by itself.” Example class Beers (key name) {attribute string name . . .} Remember: Keys are optional in ODL. The “object ID” suffices to distinguish objects that have the same values in their elements. Winter 2006 Keller Ullman Cushing

Example: A Multiattribute Key class Courses (key (dept, number), (room, hours)) { ...} Winter 2006 Keller Ullman Cushing

Translating ODL to Relations Classes without relationships: like entity set, but several new problems arise. Classes with relationships: Treat the relationship separately, as in E/R. Attach a many-one relationship to the relation for the “many.” Winter 2006 Keller Ullman Cushing

ODL Class Without Relationships Problem: ODL allows attribute types built from structures and collection types. Structure: Make one attribute for each field. Set: make one tuple for each member of the set. More than one set attribute? Make tuples for all combinations. Problem: ODL class may have no key, but we should have one in the relation to represent “OID.” Winter 2006 Keller Ullman Cushing

Example name street city zip phone n1 s1 c1 z1 p1 n1 s1 c1 z1 p2 class Drinkers (key name) { attribute string name; attribute Struct Addr {string street, string city, int zip} address; attribute Set<string> phone; } name street city zip phone n1 s1 c1 z1 p1 n1 s1 c1 z1 p2 Surprise: the key for the class (name) is not the key for the relation (name, 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. Winter 2006 Keller Ullman Cushing

ODL Relationships If the relationship is many-one from A to B, put key of B attributes in the relation for class A. If relationship is many-many, we’ll have to duplicate A-tuples as in ODL with set-valued attributes. Wouldn’t you really rather create a separate relation for a many-many-relationship? You’ll wind up separating it anyway, during BCNF decomposition. Winter 2006 Keller Ullman Cushing

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; } Drinkers(name, addr, beerName, favBeer, wife, buddy) Winter 2006 Keller Ullman Cushing

Decompose into 4NF FD’s: nameaddr favBeer wife MVD’s: namebeername, namebuddy Resulting decomposition: Drinkers(name, addr, favBeer, wife) DrBeer(name, beer) DrBuddy(name, buddy) Winter 2006 Keller Ullman Cushing

OQL Motivation: Relational languages suffer from impedance mismatch when we try to connect them to conventional languages like C or C++. The data models of C and SQL are radically different, e.g., C does not have relations, sets, or bags as primitive types; C is tuple-at-a-time, SQL is relation-at-a-time. OQL is an attempt by the OO community to extend languages like C++ with SQL-like, relation-at-a-time dictions. Winter 2006 Keller Ullman Cushing

OQL Types Basic types: strings, ints, reals, etc., plus class names. Type constructors: Struct for structures. Collection types: set, bag, list, array. Like ODL, but no limit on the number of times we can apply a type constructor. Set(Struct()) and Bag(Struct()) play special roles akin to relations. Winter 2006 Keller Ullman Cushing

OQL Uses ODL as its Schema-Definition Portion For every class we can declare an extent = name for the current set of objects of the class. Remember to refer to the extent, not the class name, in queries. Winter 2006 Keller Ullman Cushing

class Bar (extent Bars) { attribute string name; attribute string addr; relationship Set<Sell> beersSold inverse Sell::bar; } class Beer (extent Beers) 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; Winter 2006 Keller Ullman Cushing

Path Expressions Let x be an object of class C. If a is an attribute of C, then x.a = the value of a in the x object. If r is a relationship of C, then x.r = the value to which x is connected by r. Could be an object or a collection of objects, depending on the type of r. If m is a method of C, then x.m(…) is the result of applying m to x. Winter 2006 Keller Ullman Cushing

Example of Illegal Use of Dot Examples Let s be a variable whose type is Sell. s.price = the price in the object s. s.bar.addr = the address of the bar mentioned in s. Note: cascade of dots OK because s.bar is an object, not a collection. Example of Illegal Use of Dot b.beersSold.price, where b is a Bar object. Why illegal? Because b.beersSold is a set of objects, not a single object. Winter 2006 Keller Ullman Cushing

OQL Select-From-Where SELECT <list of values> FROM <list of collections and typical members> WHERE <condition> Collections in FROM can be: Extents. Expressions that evaluate to a collection. Following a collection is a name for a typical member, optionally preceded by AS. Example Get the menu at Joe’s. SELECT s.beer.name, s.price FROM Sells s WHERE s.bar.name = "Joe's Bar" Notice double-quoted strings in OQL. Winter 2006 Keller Ullman Cushing

Example Another way to get Joe’s menu, this time focusing on the Bar objects. SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" Notice that the typical object b in the first collection of FROM is used to help define the second collection. Typical Usage If x is an object, you can extend the path expression, like s or s.beer in s.beer.name. If x is a collection, you use it in the FROM list, like b.beersSold above, if you want to access attributes of x. Winter 2006 Keller Ullman Cushing

Tailoring the Type of the Result Default: bag of structs, field names taken from the ends of path names in SELECT clause. Example SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" has result type: Bag(Struct( name: string, price: real )) Winter 2006 Keller Ullman Cushing

Rename Fields Prefix 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 type: Bag(Struct( beer: string, price: real )) Winter 2006 Keller Ullman Cushing

Change the Collection Type Use SELECT DISTINCT to get a set of structs. Example SELECT DISTINCT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" Use ORDER BY clause to get a list of structs. joeMenu = SELECT s.beer.name, s.price ORDER BY s.price ASC ASC = ascending (default); DESC = descending. We can extract from a list as if it were an array, e.g., cheapest = joeMenu[1].name; Winter 2006 Keller Ullman Cushing