Object-Oriented DBMS - Models and Query Languages 8-10 december, Linköping Anders Carstensen Magnus Lundqvist 2 Introduction to OODBMSs •Some general definitions • OODM - A logical data model that captures the semantics of objects supported in object-oriented programming. • OODB - A persistent and shareable collection of objects defined by and OODM • OODBMS - The manager of an OODB •However: • There is no single object-oriented model for every system as is the case with the relational model. 3 Introduction to OODBMSs contd. •More detailed definitions • An OODBMS must provide database functionality, encapsulation and it must support object identity and objects with complex states. • An OODBMS is a system that provide database capabilities and support object-orientation; where OO is defined as abstract data types, inheritance and object identity. • An OODBMS is an object-oriented system that supports: • Supports storage of complex objects, indexes and access methods • Supports persistence, atomic transactions, and concurrency and recovery • control Provides a high-level query language with optimisation capabilities. 4 The Object-Oriented Database System Manifesto (’89) •Based on the view on OODBMS as OO+DBMS • Object-Oriented characteristics • • • • • • • • • Complex objects must be supported Object identity must be supported Encapsulation must be supported Types or classes must be supported Inheritance must be supported Dynamic binding must be supported (overloading and overriding) The data manipulation language (DML) must be computationally complete The data type set must be extensible DBMS characteristics • • • • • Data persistence must be provided The DBMS must be capable of handling very large databases The DBMS must support concurrent users The DBMS must be capable of recovery from hardware and software failures The DBMS must provide a simple way of querying data 5 Approaches to development of OODBMSs • Extend an existing object-oriented programming language with database capabilities (GemStone) • Provide extensible object-oriented DBMS libraries (Ontos, Versant, ObjectStore) • Embed object-oriented database language constructs in a conventional host language (O2) • Extend an existing database language with object-oriented capabilities (ODMG standard, Ontos, Versant) • Develop a novel database data model/data language (Semantic Information Manager, SIM) 6 The O2 System •Based on three main ideas • The merger of user interface, programming language and database technology • The use of object-oriented technology • The conformance to standards C C++ •Includes • A query language ,O2Query • A user interface generator, O2Look • An 4th-generation object language, O2C • A graphic programming environment including a O2Tools O2C O2Query O2Engine debugger and a schema and database browser 7 O2Look Data Model • Values and objects • Values have types • • Atomic types - boolean, char, integer, real, string, bits Complex types - tuple, list, [unique] set • Objects and classes • • Defined by its types and methods Methods without parameters are considered as attributes • Queries • Formulated in a SQL-like syntax with standard OO-approach • Select tuple(restaurant: r.name, choices: select tuple(price: menu.rate, food: menu.contents) from menu in m) from r in Restaurant, m in r.menus where r.adress.city.name = “Paris” and (exists menu in m: menu.rate < 100) 8 ODMG 3.0 • Standard proposed by Object Data Management Group 1999 • Consists of • Object Model • Object Definition Language (ODL) • Object Query Language (OQL) • C++, Java and Smalltalk language bindings 9 ODMB 3.0 - Object Model • Modelling primitives • Objects • Have an object identifier • Literals • Constant assigned as a value to an object •Objects and literals are instantiated from a type (or class) • The nature of a type can be • Atomic - char, string, long, short, float • Collection - set, bag, list, array, dictionary • Structured - date, time • Atomic object types posses state and behaviour • State by defining attributes and relationships with other objects • Behaviour by defining methods • State and behaviour of a super type is inherited but can be redefined • Collection consists of several homogenous elements which can be atomic objects or other collections • The extent of a type is the set of all instantiated objects that exist of that type 10 ODMG 3.0 - Object Query Language (OQL) • ODMG defines OQL with an SQL-like syntax for retrieving objects from an object database either as a user entered query or as a query embedded in object oriented programming language • The basic syntax for a query is: SELECT [DISTINCT] <expression> FROM <from list> [WHERE <expression>] [GROUP BY <attribute1:expression1, attribute2:expression2...] [HAVING <predicate>] [ORDER BY <expression>] •The result from such a query is a collection of objects, which can be given a specific name and be reused in other queries by the define-statement • DEFINE <query name>[(<parameter>)] AS <sql-expression> • The optional parameter can be used in the sql-expression 11 ODMG 3.0 - Object Query Language (OQL) contd. • Example class Restaurant (extent restaurants, key restNo) { attribute long restNo; attribute string name; attribute struct RestaurantAddress {string street, string city, string zipcode} address; attribute enum RestaurantCategories {Gourmet, FastFood, Café} category, attribute long numberOfTables; relationship set<Staff> HasWorkers inverse Staff::WorksAt }; class Staff (extent personnel, key staffNo) { attribute long staffNo; attribute struct FullName {string fName, string lName} staffName; attribute enum StaffPositions {Manager, Chef, Waiter} position; relationship Restaurant WorksAt inverse Restaurant::HasWorkers; } 12 ODMG 3.0 - Object Query Language (OQL) contd. • Find all restaurants of category Gourmet in Stockholm SELECT r FROM r IN restaurants WHERE r.category=”Gourmet” AND r.address.city=”Stockholm”; - The result is a set of literal structures • A variant of the previous query where the city and the category is given as parameters DEFINE GourmetRestaurantsIn(restCat, cityName) AS SELECT r FROM r IN restaurants WHERE r.category=restCat AND r.address.city=cityName; - GourmetRestaurantsIn(“Gourmet”, “Stockholm”) retrieves the same results as above • List restaurants and the number of waiters hired SELECT struct(RestaurantName, NumberOfWorkers: COUNT(partition)) FROM p IN personnel WHERE p.position=”Waiter” GROUP BY RestaurantName:p.WorksAt.name 13 Exercises 14 Final Dicsussion & Summary • Pros and Cons + Enriched modelling capabilities + Extensibility + Support for schema evolution + Long-duration transactions + Improved performance - Lack of universal data model - Object-level locks impact performance Novel area (in comparison) Lack of standards Conflict between encapsulation and optimisation Complexity Lack of support for views Lack of support for security 15