Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 671OODBs1 Lecture 3 Object database standards, languages and design.

Similar presentations


Presentation on theme: "CIS 671OODBs1 Lecture 3 Object database standards, languages and design."— Presentation transcript:

1 CIS 671OODBs1 Lecture 3 Object database standards, languages and design

2 CIS 671OODBs2 Development of Object-based Systems Object-Oriented Database Systems –An alternative to relational systems –Application domains where objects play central role –Heavily influenced by object-oriented programming languages –An attempt to add DBMS functionality to a programming language environment

3 CIS 671OODBs3 Development of Object-based Systems - cont. Object-Relational Database Systems –An attempt to extend relational databases Broader set of applications –Provide bridge between relational and object- oriented systems

4 CIS 671OODBs4 Why a Standard? Portability from one vendor (system) to another Interoperability between systems based on different vendor products easier

5 CIS 671OODBs5 Object Data Management Group (ODMG) ODMG-93 or ODMG 1.0; ODMG 2.0 (1997) Parts –Object model –Object definition model (ODL) –Object query language (OQL) –Bindings to OO programming languages

6 CIS 671OODBs6 Unified Modeling Language (UML) Consortium of vendors including  DEC  HP  IBM  Unisys  I-Logix  Intellicorp  MCI Systemhouse  TI UML 0.9 (1996); UML 1.1 (1997) Unified as to -Differences in Modeling Languages -Differences in Perspectives  Microsoft  Icon Computing  Rational Software  Oracle

7 CIS 671OODBs7 ODMG Object Model Literal –State (or value) {constant} –No OID –May have complex structure –Types of literals Atomic- Simple, e.g., 10.2 -Structured, e.g. Date (19, May, 2001) Collection, e.g. days of the week (Sun, Mon, …, Sat)

8 CIS 671OODBs8 ODMG Object Model Object –Identifier (OID) –Name (optional) –Lifetime (persistent or transitory) –Structure How constructed –Atomic –Collection: t a type, k a key, v a value »Set »Bag »List »Array »Dictionary Specified by interface

9 CIS 671OODBs9 Interface Definitions from ODMG Object Model Object Data Language –ODL

10 CIS 671OODBs10 Examples: Object–inherited by all objects Date–structured literal interface Object { … booleansame_as(in Object other_object); Objectcopy(); voiddelete(); } interface Date: Object { enumWeekday {Sunday, Monday, …, Saturday}; enumMonth {January, February, …, December}; unsigned shortyear(); unsigned shortmonth(); unsigned shortday() … booleanis_equal(in Date other_Date); booleanis_greater(in Date other_Date); … } Operations are inherited by user- defined objects. Date is subtype of Object (i.e., inherits from).

11 CIS 671OODBs11 See text for the following examples: Structured Literals –Time –Timestamp –Interval Collection Objects –Collection Iterator Set Bag List Array –Association –Dictionary

12 CIS 671OODBs12 Object Interfaces All objects inherit basic interface of Object using dot notation: –o.same_as(p) – true if p is the same as o –p = o.copy() – create copy p of object o –o.delete() – delete object o May also use arrow notation: –o->same_as(p) – true if p is the same as o

13 CIS 671OODBs13 Class Definition Examples: Employee Class Employee ( extentall_employees keyssn ) {attributestringname; attributestringssn; attributedatebirthdate; attributeenum Gender{M,F}sex; relationshipDepartmentworks_for inverse Department::has_emps; voidreassign_emp(in string new_dname) raises(dname_not_valid); } Note that both “works_for” and inverse relationship, “has_emps”, are specified.

14 CIS 671OODBs14 Class Definition Examples: Department Class Department ( extentall_departments keydname, dnumber ) {attributestringdname; attributeshortdnumber; attributestruct Dept_Mgr{Employee manager, date startdate} mgr; attributeset locations; attribute struct Projs {string projname, time weekly_hours} projs; relationship set has_emps inverse Employee::works_for; voidadd_emp(in string new_ename) raises(ename_not_valid); voidchange_manager(in string new_mgr_name) in date startdate); }

15 CIS 671OODBs15 Relationships works_for and has_emps between Employee and Department Class Employee {… relationship Department works_for inverse Department::has_emps; } Class Department {… relationship set has_emps inverse Employee::works_for; }

16 CIS 671OODBs16 COMPANY database in ODL Diagram more details on page 680 in book EMPLOYEES MANAGE_DEPT DEPARTMENT LOCATION PROJECT WORKS_ON_PROJECT DEPENDENT has_ dependents dependent_of controls controlled _by has_ projects located_at has_ departments located_at works_foremploys employee manager department project works _on employees_on manages managed_by supervisee supervisor

17 CIS 671OODBs17 Object Types: Interfaces vs. Classes Interface (e.g. Date) –Abstract behavior, specification via operation signatures –Noninstantiable (i.e. cannot have object matching description) –Used via inheritance (behavior inheritance “:”) Class (e.g. Employee) –Abstract behavior –Abstract state –Instantiable Terminology –Behavior: operations –State: properties (attributes & relationships)

18 CIS 671OODBs18 Inheritance Relationships: Behavior vs. Extends Behavior Inheritance –Supertype must be interface –Subtype may be interface or class –Denoted by “:” –Multiple inheritance permitted EXTENDS Inheritance –Inherit state and behavior among classes Both supertype and subtype must be classes –Multiple inheritance not permitted –Specified by extends keyword

19 CIS 671OODBs19 Example: Person UNIVERSITY Database Class Person ( extentpersons keyssn ) {attributestruct Pname {string fname, string mname, string iname} name; attributestringssn; attributedatebirthdate; attributeenum Gender{M,F}sex; attributestruct Address {short no, string street, …, short zip} shortage(); }

20 CIS 671OODBs20 Example: Faculty UNIVERSITY Database Class Faculty extends Person ( extentfaculty) {attributestringrank; attributefloatsalary; attributestringoffice; attribute string phone; relationshipDepartmentworks_in inverse Department::has_faculty; relationshipset advises inverse GradStudent ::advisor; relationshipset on_committee_of inverse GradStudent ::committee; voidgive_raise(in float raise); voidpromote(in string new_rank); } Extends inheritance from Person

21 CIS 671OODBs21 Example: other classes UNIVERSITY Database Student extends Person Degree GradStudent extends Student Department Course Section CurrSection extends Section Grade

22 CIS 671OODBs22 Factory Objects Used to generate individual objects Examples –ObjectFactory –DateFactory –DatabaseFactory Include new() operation Interface ObjectFactory { Objectnew(); }

23 CIS 671OODBs23 Database Factory interface Database { voidopen(in string database_name); voidclose(); voidbind(in any some_object, in string some_object); Objectunbind(in string name); Objectlookup(in string object_name) raises(ElementNotFound); } interface DatabaseFactory { Databasenew(); }

24 CIS 671OODBs24 Object Database Standards, Languages, and Design Part II: Object Query language (OQL)

25 CIS 671OODBs25 Object Query Language (OQL) “Bring the best of SQL to the object world.” Syntax similar to SQL Plus additional features Works with programming languages where ODMG has defined bindings –Java, C++, Smalltalk –Returns object matching type system of that language –May implement class operations in these languages SQL3 – “Bring the best of the object-oriented world to the relational world.”

26 CIS 671OODBs26 Movie title year length /* in minutes */ filmType:{color, blackAndWhite} lengthInHours starNames otherMovies Movies Example: Movies, Stars, Studios Star name address street city Studio name starsstarredIn1..* ownedByowns 1..*1..1 Set of stars of this movie. Other movies by star of this movie.

27 CIS 671OODBs27 Movies Example: Movies, Stars, Studios class Movie (extent Movies key (title, year)) {attribute stringtitle; attribute integeryear; attribute integer length; /* in minutes */ attribute enumeration(color, blackAndWhite) filmType; relationshipset stars inverse Star :: starredIn; relationshipStudio ownedBy inverse Studio :: owns; float lengthInHours() raises(noLengthFound); starNames(out set ); otherMovies(in Star, out set( )raises(noSuchStar); };

28 CIS 671OODBs28 Class Star (extent Stars key name) {attribute stringname; attribute structAddr; {string street, string city} address; relationshipset starredIn inverse Movie :: stars; }; Class Studio (extent Studios key name) {attribute stringname; relationshipset owns inverse Movie :: ownedBy; }; Movies Example, contd.

29 CIS 671OODBs29 Specifying data from ODB Path expression –Dot notation similar to structure in programming language, –e.g., o.a attribute a of object o. Select-From-Where expression –Similar to SQL. –References are to data classes, not relations. Integrated directly into host language.

30 CIS 671OODBs30 Path Expressions Assume myMovie a host-language variable, value a Movie object. myMovie.length - length of the movie. myMovie.lengthInHours() - real number, computed as length in minutes. myMovie.stars – set of Star objects related to myMovie by relationship stars. myMovie.starNames(myStars) – returns no value, sets output variable myStars of method starNames to set of strings with names of the stars of the movie. myMovie.ownedBy.name – string that is name of studio owning myMovie.

31 CIS 671OODBs31 Select-From-Where Expressions, I Year of the movie Gone with the Wind. select m.year from m in Movie where m.title = “Gone with the Wind”; Bag containing names of stars of Casablanca. select s.name from m in Movies, s in m.stars where m.title = “Casablanca”; Set containing names of stars of Disney movies. select distinct s.name from m in Movies, s in m.stars where m.ownedBy.name = “Disney”; Might contain duplicates, therefore bag. No duplicates, therefore set. Must name all components in hierarchy, i.e., Movies & stars.

32 CIS 671OODBs32 Select-From-Where Expressions, II Pairs of stars living at the same address. select distinct struct(star1: s1, star2: s2) from s1 in Stars, s2 in Stars where s1.addr = s2.addr and s1.name < s2.name; Set containing names of stars of Disney movies, using subquery. Select distinct s.name from (select m from m in Movies where m.ownedBy.name = “Disney”) dm, s in dm.stars; Set of all Disney movies, ordering results by length and title. select m from m in Movies where m.ownedBy.name = “Disney” order by m.length, m.title; Result is set of structs. List of Movies in ascending order Bag of all Disney movies. Stars in those movies.

33 CIS 671OODBs33 Select-From-Where Expressions, III Set containing names of stars of Disney movies, using existential quantifier. select distinct s.name from s in Stars where exists m in s.starredIn : m.ownedBy.name = “Disney”; Set containing names of stars that have appeared only in Disney movies, using universal quantifier. select distinct s.name from s in Stars where for all m in s.starredIn : m.ownedBy.name = “Disney”;

34 CIS 671OODBs34 Select-From-Where Expressions, IV Average length of all movies. Avg( select m.length from Movies m); Table of lengths of movies for each studio for each year. select std, yr, sumLength: sum( select p.m.length from p in partition) from m in Movies group by std: m.studio, yr: m.year; Table of lengths of movies for each studio for each year where studio produced at least one movie of over 120 minutes in that year. select std, yr, sumLength: sum( select p.m.length from p in partition) from m in Movies group by std: m.studio, yr: m.year having max(select p.m.length from partition p) > 120; Want bag of lengths, not set.

35 CIS 671OODBs35 Views View returning Set containing movies by studio studio. define moviesFromStudio(studio) as select m from m in Movies where m.ownedBy.name = studio; Do not need “distinct m”, since Movies is already a set.

36 CIS 671OODBs36 Returning a single element Bag or Set (if distinct included) normally returned. May want single element. Return Movie with name Casablanca. Element (select m from m in Movies where m.title = “Casablanca”);

37 CIS 671OODBs37 Find names of those who starred in all Disney movies. Movie title year length /* in minutes */ filmType:{color, blackAndWhite} lengthInHours starNames otherMovies Star name address street city Studio name starsstarredIn1..* ownedByowns 1..*1..1 Idea:select s.name from s in Star where for all DisneyMovies exists ds in DisneyMovies.stars with same name;

38 CIS 671OODBs38 Find names of those who starred in all Disney movies: First attempt. 1.Using “if p then q”. selects.name froms in Star wherefor all m in Movie : (if m.ownedBy.name = ‘Disney’ thenexists s1 in m.stars : s1.name = s.name); 2.Converting “if p then q” to “~p or q”. selects.name froms in Star wherefor all m in Movie : (m.ownedBy.name != ‘Disney’ or exists s1 in m.stars : s1.name = s.name);

39 CIS 671OODBs39 Find names of those who starred in all Disney movies: Using a view of all Disney movies. View returning Set of Disney movies. define DisneyMovies as select m fromm in Movies wherem.ownedBy.name = ‘Disney’; 3.Query for stars using the DisneyMovies view. selects.name froms in Star wherefor all dm in DisneyMovie : (exists s1 in dm.stars : s1.name = s.name);

40 CIS 671OODBs40 Find names of those who starred in all Disney movies: Using the Movie.starNames function. Change –starNames(out set ) to a function –set starNames() 4.Query for stars using the DisneyMovies view and starNames() function. selects.name froms in Star wherefor all dm in DisneyMovie : s.name in dm.starNames();


Download ppt "CIS 671OODBs1 Lecture 3 Object database standards, languages and design."

Similar presentations


Ads by Google