1 / 40

Lecture 3

Lecture 3. Object database standards, languages and design. 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

gryta
Download Presentation

Lecture 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3 Object database standards, languages and design OODBs

  2. 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 OODBs

  3. 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 OODBs

  4. Why a Standard? • Portability from one vendor (system) to another • Interoperability between systems based on different vendor products easier OODBs

  5. 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 OODBs

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

  7. 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) OODBs

  8. 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 <t> • Bag <t> • List <t> • Array <t> • Dictionary <k, v> • Specified by interface OODBs

  9. Interface Definitions from ODMG Object Model • Object Data Language • ODL OODBs

  10. interfaceObject { … boolean same_as(in Object other_object); Object copy(); void delete(); } Examples:Object – inherited by all objectsDate – structured literal Date is subtype of Object (i.e., inherits from). interfaceDate:Object { enum Weekday {Sunday, Monday, …, Saturday}; enum Month {January, February, …, December}; unsigned short year(); unsigned short month(); unsigned short day() … boolean is_equal(in Date other_Date); boolean is_greater(in Date other_Date); … } Operations are inherited by user-defined objects. OODBs

  11. Structured Literals Time Timestamp Interval Collection Objects Collection Iterator Set Bag List Array Association Dictionary See text for the following examples: OODBs

  12. 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 OODBs

  13. Class Definition Examples:Employee ClassEmployee ( extent all_employees key ssn ) { attribute string name; attribute string ssn; attribute date birthdate; attribute enum Gender{M,F}sex; relationship Departmentworks_for inverse Department::has_emps; void reassign_emp(in string new_dname) raises(dname_not_valid) ; } Note that both “works_for” and inverse relationship, “has_emps”, are specified. OODBs

  14. Class Definition Examples:Department ClassDepartment ( extent all_departments key dname, dnumber ) { attribute string dname; attribute short dnumber; attribute struct Dept_Mgr{Employee manager, date startdate} mgr; attribute set<string> locations; attribute struct Projs {string projname, time weekly_hours} projs; relationship set<Employee> has_emps inverse Employee::works_for; void add_emp(in string new_ename) raises(ename_not_valid); void change_manager(in string new_mgr_name) in date startdate); } OODBs

  15. Relationships works_for andhas_empsbetweenEmployee and Department • ClassEmployee • {… • relationship Departmentworks_for inverse Department::has_emps; • } • ClassDepartment • {… • relationship set <Employee> has_emps inverseEmployee::works_for; • } OODBs

  16. COMPANY database in ODL Diagrammore details on page 680 in book works_for employs supervisee EMPLOYEES DEPARTMENT manages managed_by located_at supervisor manager department controls has_ dependents MANAGE_DEPT works _on has_ departments LOCATION employee has_ projects WORKS_ON_PROJECT project controlled _by dependent_of located_at employees_on DEPENDENT PROJECT OODBs

  17. 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 Object Types: Interfaces vs. Classes • Terminology • Behavior: operations • State: properties (attributes & relationships) OODBs

  18. 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 Inheritance Relationships: Behavior vs. Extends OODBs

  19. Example: PersonUNIVERSITY Database ClassPerson ( extent persons key ssn ) { attribute struct Pname {string fname, string mname, string iname} name; attribute string ssn; attribute date birthdate; attribute enum Gender{M,F}sex; attribute struct Address {short no, string street, …, short zip} short age(); } OODBs

  20. Example: FacultyUNIVERSITY Database ClassFaculty extendsPerson ( extent faculty) { attribute string rank; attribute float salary; attribute string office; attribute string phone; relationship Department works_in inverse Department::has_faculty; relationship set<GradStudent> advises inverse GradStudent ::advisor; relationship set<GradStudent> on_committee_of inverse GradStudent ::committee; void give_raise(in float raise); void promote(in string new_rank); } Extends inheritance from Person OODBs

  21. Student extends Person Degree GradStudent extends Student Department Course Section CurrSection extends Section Grade Example: other classesUNIVERSITY Database OODBs

  22. Factory Objects • Used to generate individual objects • Examples • ObjectFactory • DateFactory • DatabaseFactory • Include new() operation Interface ObjectFactory { Object new(); } OODBs

  23. Database Factory interfaceDatabase { void open(in string database_name); void close(); void bind( in any some_object, in string some_object); Object unbind(in string name); Object lookup(in string object_name) raises(ElementNotFound); } interfaceDatabaseFactory { Database new(); } OODBs

  24. Object Database Standards, Languages, and DesignPart II: Object Query language (OQL) OODBs

  25. 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.” OODBs

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

  27. Movies Example: Movies, Stars, Studios classMovie (extent Movieskey (title, year)) { attribute string title; attribute integer year; attribute integer length; /* in minutes */ attribute enumeration (color, blackAndWhite) filmType; relationshipset<Star> stars inverse Star :: starredIn; relationship Studio ownedBy inverse Studio :: owns; float lengthInHours() raises(noLengthFound); starNames(out set<String>); otherMovies(in Star, out set(<Movie>) raises(noSuchStar); }; OODBs

  28. ClassStar (extent Stars key name) { attribute string name; attribute struct Addr; {string street, string city} address; relationshipset<Movie> starredIn inverse Movie :: stars; }; Movies Example, contd. ClassStudio (extent Studios key name) { attribute string name; relationshipset<Movie> owns inverse Movie :: ownedBy; }; OODBs

  29. 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. OODBs

  30. 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. OODBs

  31. 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. Must name all components in hierarchy, i.e., Movies & stars. No duplicates, therefore set. OODBs

  32. Select-From-Where Expressions, II Result is set of structs. • Pairs of stars living at the same address. select distinctstruct(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, sin 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 bym.length, m.title; Bag of all Disney movies. Stars in those movies. List of Movies in ascending order OODBs

  33. 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 existsm 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 allm in s.starredIn : m.ownedBy.name = “Disney”; OODBs

  34. Select-From-Where Expressions, IV Want bag of lengths, not set. • 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 havingmax(select p.m.length from partition p) > 120; OODBs

  35. 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. OODBs

  36. Returning a single element • Bag or Set (if distinct included) normally returned. • May want singleelement. • Return Moviewithname Casablanca. Element (select m from m in Movies where m.title = “Casablanca”); OODBs

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

  38. Find names of those who starred in allDisney movies:First attempt. • Using “if p then q”. select s.name from s in Star wherefor all m in Movie : (if m.ownedBy.name = ‘Disney’ thenexists s1 in m.stars : s1.name = s.name); • Converting “if p then q” to “~p or q”. select s.name from s in Star wherefor all m in Movie : (m.ownedBy.name != ‘Disney’ or exists s1 in m.stars : s1.name = s.name); OODBs

  39. Find names of those who starred in allDisney movies:Using a view of all Disney movies. View returning Set of Disney movies. define DisneyMovies as select m from m in Movies where m.ownedBy.name = ‘Disney’; • Query for stars using the DisneyMovies view. select s.name from s in Star wherefor all dm in DisneyMovie : (exists s1 in dm.stars : s1.name = s.name); OODBs

  40. Find names of those who starred in allDisney movies:Using the Movie.starNamesfunction. Change • starNames(out set<String>) to a function • set<String> starNames() • Query for stars using the DisneyMovies view and starNames() function. select s.name from s in Star wherefor all dm in DisneyMovie : s.name in dm.starNames(); OODBs

More Related