DOC PREVIEW
UW CSE 444 - Study Notes

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Why Object-Oriented DBMS?SQL Doesn’t Work in ScotlandTwo Approaches to OOObject Definition LanguageODL Class DeclarationsExample MethodOQL: Object Query LanguageTypes in OQLPath ExpressionsSelect-From-Where in OQLComplications in the FROM ClauseComplex Output TypesOther Features of OQLInterface with Host LanguageHandling Sets or BagsAnother ExampleFinal ExampleRow Types in SQL-3Relations as Row TypesReferencesAbstract Data Types in SQL3Address ADTDifferences Between OODB ApproachesWhy Object-Oriented DBMS?•Abstract data types (relational data model is too simple).•Interface with host programming language•Managing large number of objects:–Encapsulation, reusability•Semantic networks: the worls is actually a complex hierarchy.SQL Doesn’t Work in ScotlandSelect nameFrom EmployeeWhere name > “Mc” and name < “Md”OrderBy nameDoesn’t work for the McAndish clan: (they’re all the same!) McAndish MacAndish M’AndishComparison based on ASCIIOther countries are even more problematic.Two Approaches to OO1. Object Query Language: part of ODMG (that also gave us OQL)2. Adding object features to SQL (row types and ADT’s). Also known as Object-relational systems.The difference: How important is a relation to you? How important is SQL to you?Object Definition Language•Resembles C++ (and Smalltalk).•Basic design paradigm in ODL: –Model objects and their properties.•For abstraction purposes:–Group objects into classes.•What qualifies as a good class?–Objects should have common properties.ODL Class DeclarationsInterface <name> { attributes: <type> <name>; relationships <range type> <name>; methods (in, out, inout, exceptions)}Example MethodInterface Movie { (extent Movies) attribute string title; relationship Set <Star> stars inverse Star::starredIn; float lengthInHours raises(noLengthFound); starNames (out Set <String>); otherMovies (in Star, out Set<Movie>) raises (noSuchStar);}Note: defining signature, not implementation. Overloading allowed.OQL: Object Query LanguageSELECT can construct new objects, arbitrary structuresFROM tuple variables can range over any collection; may have subqueries.WHERE pretty much the same as in SQLTypes in OQLBasic types: Atomic types (e.g., string, integer, …) Enumeration types (Monday, Tuesday, Wednesday….)Constructors: can be applied without limitations. Set: (1, 5, 6) Bag: (1, 1, 5, 6, 6 ) List: (1, 5, 6, 1, 6 ) Array: Integer[17] Struct: (name: string, address: string) struct( name: “John”, childrenAges: bag (1,1,2,2))Declaring types for objectsPath ExpressionsPath expressions are needed in order to access componentsof objects.Attributes: a.p is the value of the attribute a of p.Relationships: a.p is the object or collection of objects related to a by p.Methods: a.p is the result of applying p to a (perhaps with a parameter).Also possible to have longer expressions: a.father.wife.child.father.wife….Select-From-Where in OQL(simple) Example: SELECT s.name FROM Movies m, m.stars s WHERE m.title = “Sleepless in Seattle”Note: this looks a lot more procedural than SQL.Complications in the FROM ClauseSELECT a.phoneNumber FROM Movies m, (SELECT m.address FROM m.stars WHERE m.city=“Los Angeles”) AS a WHERE m.title = “Sleepless in Seattle”The FROM clause can contain arbitrary subqueries that returncollections.Complex Output TypesThe SELECT clause can create complex structures:SELECT Struct: (address: a, phoneNumber: a.phoneNumber) FROM Movies m, (SELECT m.address FROM m.stars WHERE m.city=“Los Angeles”) AS a WHERE m.title = “Sleepless in Seattle”Other Features of OQL• Ordering of the results ORDER BY m.title, m.year.• Subqueries wherever a collection is appropriate.• Quantifier expressions:• FOR ALL x IN S : C(x)• EXISTS x IN S:C(x)• Aggregation, grouping and HAVING clauses.• Set operators: UNION, INTERSECT, EXCEPT (different if operating on bags or sets).• Remove duplicates: SELECT DISTINCT.Interface with Host Language OQL is much more tightly integrated with the host language.OQL produces objects (of various types). One can simply assignthe objects as values to variables with the appropriate types.No need for special interface.ELEMENT: turns a bag of one element into the single element: var1 = ELEMENT (SELECT m FROM Movies m WHERE title=“sleepless in Seattle”);Handling Sets or BagsFirst: turn them into lists (using ORDER BY).Then: use host language operations to go through them.Example: movieList = select m FROM Movies m WHERE m.year > 1990 ORDER BY m.title, m.year; numberOfMovies = COUNT (movieList); for (I=0; I < numberOfMovies; I++) { movie = movieList[I]; do something with it.}Another ExampleSchema: one relation Tour (S, E, C ) meaning: company C offers a tour from city S to city E.Query: find for every city, the companies giving tours of itself.SELECT [S: x.S C : (SELECT y.C from y in Tour WHERE x.E=y.S and x.S=y.E) ] FROM x in TourFinal ExampleSELECT [S:x.S, C: (SELECT y.C FROM y in Tour, y’ in Tour WHERE x.S=y.S and x.E=y.E and x.E=y’.S and x.S=y’.E and y.C = y’.C)]from x in Tour.Find companies offering tours from city S to some destinationE and back to S.Row Types in SQL-3Row types define types for tuples, and they can be nested.CREATE ROW TYPE AddressType{ street CHAR(50), city CHAR(25), zipcode CHAR(10) }CREATE ROW TYPE PersonType{ name CHAR(30), address AddressType, phone phoneNumberType}Relations as Row TypesCREATE TABLE Person OF TYPE PersonType;Recall: row types can be nested!Accessing components of a row type: (double dots)SELECT Person.name, Person.address..cityFROM PersonWHERE Person.address..street LIKE ‘%Mountain%’ReferencesWe can define attributes of a row type to reference objects of otherrow types:CREATE ROW TYPE Company( name char(30),


View Full Document

UW CSE 444 - Study Notes

Documents in this Course
XML

XML

48 pages

SQL

SQL

25 pages

SQL

SQL

42 pages

Recovery

Recovery

30 pages

SQL

SQL

36 pages

Indexes

Indexes

35 pages

Security

Security

36 pages

Wrap-up

Wrap-up

6 pages

SQL

SQL

37 pages

More SQL

More SQL

48 pages

SQL

SQL

35 pages

XML

XML

46 pages

Triggers

Triggers

26 pages

Load more
Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?