Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Advanced Databases The ODMG Standard for Object Databases.

Similar presentations


Presentation on theme: "1 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Advanced Databases The ODMG Standard for Object Databases."— Presentation transcript:

1 1 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Advanced Databases The ODMG Standard for Object Databases

2 2 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases ODMG 3 Object Database Standard Object Database Management Group, formed 1991, intended to: –provide a standard where previously there was none –support portability between products –move away from single language systems –standardize model, querying and programming issues Enables both designs and implementations to be ported between compliant systems Currently on version 3.0 Most vendor products are moving toward compliance; O2 is possibly the closest Vendors: Object Design,Objectivity, O2 Technology, POET, etc. URL: www.odmg.org

3 3 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases ODMG Components An architecture for OODBMS. An object model. –that will act as the logical model for all OODBMS and provide a level of interoperability. A data definition language (ODL). –a concrete specification of the operations permitted over a schema defined in the data model. A query language (OQL). –for posing ad-hoc queries but not for data definition or data manipulation. Language bindings to existing OOPL, (C++, Java, Smalltalk). –the object manipulation languages are the integration of a PL with the ODMG model, so the OOPL’s get persistence and the OODB gets a flexible and standard DB programming language.

4 4 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases An Architecture for OODBMS

5 5 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Object Model 1. Data Model –state and structure of data 2. Behaviour model –dynamics of the data –operations on the data 3. Persistence model –the way the persistent and transient data is created & changes status 4. Naming model –naming and accessing objects Object identity Complex objects Types and classes Inheritance hierarchies Encapsulation Late binding/overriding Extensibility Completeness

6 6 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Object Identity An object’s unique identifier maintained throughout the object’s lifetime Not user visible System generated An object has an existence independent of its value (identity vs equality) thus implying –object sharing –object updating –supports referential integrity Objects can be cyclic JohnMary Susan Children: Name: Age: School: Susan The composition graph is an object network

7 7 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases ODMG Model supports databases... Built-in structured types which permit traditional database modelling to be used –Objects and Literals (atomic and complex) –Relationships and Attributes Transactions –nested transactions, where transaction semantics only apply to persistent data Databases –built-in object types for databases, schemas and sub-schemas Persistence –lifetime of object specified when created Names –handles by which persistent information can be accessed

8 8 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Objects, Literals and Mutability Objects –are addressed through an object identifier –are instances of classes –are packaged structures –can be shared –will be stored separately—the oid will be stored in the containing structure –properties have different levels of visibility –new operations can be user- defined for classes –mutable (components can be updated but it remains as the same object) –can be arranged into hierarchies name address name address house street Carole Ian 3 Arcacia Ave age 21 age 47

9 9 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Objects, Literals and Mutability name address house street Carole 3 Arcacia Ave Literals –do not have an identity: are addressed by a physical address –are instances of types –are simple structures –are not shared –will be embedded in any containing structure –properties are all public –no methods can be defined against types –immutable (the value is the identity, so if one of the components change its a different value) –can’t be arranged into hierarchies age 21 name address house street Ian 3 Arcacia Ave age 47

10 10 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Complex Objects Atomic built-in literal types: –long, short, unsigned long, unsigned short, float, double, string, boolean, char, any, octet The simplest objects are made up of these atomic types Complex objects are built from simple ones by applying type constructors which can be nested Type constructors –collections –record structures Person: <oid:#2, name:Henah, address: “Heaton”, birthDate: 12/02/1990> employee: <oid:#18, name:Neil, address:”Newcastle”, birthDate: 23/09/1970, children: set(#2, #3), dept:#100, manager:#19>

11 11 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Object Types, Collections, Structures Object Types –interface: specifies abstract behaviour of objects Instances of an interface cannot be created. –class: specifies state and behaviour of objects Instances of a class can be created. Collection types –set (unordered collection without duplicates) –bag (unordered collections with duplicates allowed) –list (ordered collection with duplicates allowed) –array ( indexed lists, ordered, of fixed size) –dictionary (unordered, variable size, direct access) –enumerations (explicitly listed group of values, “Mr”, “Ms”) Record types –struct (tuple) struct Address { unsigned short house, string street, set residents }

12 12 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Attributes and Relationships Attributes –Unidirectional –Values could be literals and objects –Single as well as multi- valued Relationships –Implicitly modelled as properties whose values are objects –Frequently bidirectional –Bidirectional relationships require inverses –1:many, 1:1, many:many Resort Hotel name location beachType numberOfBeaches transferTime addFacility(F) isChildFriendly(): B checkAvailability(S,R) name address numberOfRooms isOverBooked addFacility(F) showHotels(): set(H) * 1 hotels resort

13 13 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Inheritance Classes are organized into inheritance hierarchies –The properties and operations of an object type are inherited by its subclasses and so only need to be written once. Saves code through reuse Makes code simpler Provides a compact, well structured and easy to understand Two kinds of inheritance supported: –Inheritance of Behaviour or ISA –Inheritance of State Inheritance of behaviour denoted by “:” interface Person {…}; class Student : Person {…}; Inheritance of state denoted by “extends” class Vehicle {…}; class Car extends Vehicle {…};

14 14 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Object Definition Language (ODL) ODL is a specification language used to define the schema of an ODMG compliant database. ODL supports all semantic constructs of the ODMG object model. ODL is independent of any programming language, and hence provides means for the portability of database schema across complaint OODBMSs. The database schema may comprise of: –an ODL module (i.e. a higher level construct for grouping ODL specifications), –some generic object types using interface, –some concrete object types using class, and –some literal types using struct, etc.

15 15 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases University schema in ODL class Student extends Person (extent Students) { attribute string major; relationship Lecturer tutor inverse Lecturer::tutees; relationship Course enrolledOninverse Course::hasStudents; relationshipset takesinverse Unit::takenBy; boolean register(in Course C); boolean takeUnit(in Unit U); }; class Lecturer extends Person (extent Lecturers) { attribute short room; relationship set tutees inverse Student::tutor; relationship Department worksFor inverse Department::staff; relationship set teaches inverse Unit::taughtBy; boolean teachUnit(in Unit U); }; class Person { attribute string name; attribute string address; attribute date birthDate; short age(); };

16 16 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases University schema in ODL – cont … class Course (extent Courses) { attribute string name; relationship Department offeredByinverse Department::offers; relationship set hasStudentsinverse Student::enrolledOn; relationship set hasUnitsinverse Unit::partOf; }; class Department (extent Departments) { attribute string name; relationship set staffinverse Lecturer::worksFor; relationship set offers inverse Course::offeredBy; }; class Unit (extent Units) { attribute string name; attribute string code; relationship set takenBy inverse Student::takes; relationship set taughtByinverse Lecturer::teaches; relationship set partOfinverse Course::hasUnits; };

17 17 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases OQL – for querying the database OQL is the the query language in ODMG standard. OQL is a superset of the SQL (in select-from-where clauses). It can be interactive as well as embedded in other programming languages. It is a declarative language. OQL can invoke operations written in programming languages (C++, Java, Smalltalk). The operators in the language can be freely composed. OQL includes operators for creating collections, arithmetic and logical operators, aggregation, sorting and grouping.

18 18 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Retrieving Objects select l from l in Lecturers where l.address = “Newcastle” or select l from Lecturers as l where l.address = “Newcastle” or select l from Lecturers l where l.address = “Newcastle” The query returns all Lecturer objects who live in Newcastle. The type of the query result is bag. Whenever the scope of an OQL query is a collection (e.g. Lecturers, a set of Lecturer objects), we define an iterator variable that ranges over the collection (e.g. l in Lecturer ). In the query l denotes an object of type Lecturer.

19 19 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Database Entry Points Named objects are entry points to the database (same as table or view names in RDBs). Class extents are usually used to refer to in OQL queries. Some frequently used objects can be assigned unique names e.g. ComMath a named Department object or AdvDB as named Unit object. To use named objects, you don’t have to write a query in select-from-where form. You can simply write: ComMath.staff which returns all staff member objects in the school of computing and mathematics. Students which returns a set of all Student objects in the database.

20 20 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Retrieving data from multiple objects Without using Joins select struct(LName:l.name, DName:l.worksFor.name) from l in Lecturers –The query contains an implicit join based on the relationship that exists between Lecturer and Department object types and due to the path expression l.worksFor.name. However, the user does not need to tell the OQL compiler. Using Joins select struct(LName:l.name, DName:d.name) from l in Lecturers, d in Departments where l.worksFor = d –Here the user explicitly tells that a join should be performed on the basis of matching OIDs (l.worksFor and d denote an OID of a Department object).

21 21 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Unnesting and Nesting Collections Unnesting a collection select struct(LName:l.name, SName:s.name) from l in Lecturers, s in l.tutees –The query retrieves names of lecturers and their tutees in pairs. –The query iterates over the collection Lecturers via the variable l; then iterates over l.tutees (a set of Student objects) via the variable s; then projects out name from l and name from s. The type of the query result is bag. Nesting a collection select struct(LName:l.name, SNames:(select s.name from s in l.tutees) from l in Lecturers –The query retrieves for every lecturer, his/her name and all his/her tutees names. –Here instead of unnesting l.tutees, the query iterates over l.tutees via s and projects out name attribute and then constructs a collection out of it. The type of the query is bag >.

22 22 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Language Binding Extends an OOPL (C++, Java, Smalltalk) with ODL and OML (Object Manipulation Language) for building OODB applications. ODL binding defines how ODL constructs are mapped onto an OOPL. OML binding defines how objects are created, deleted, and modified in an OOPL. An OOPL may embed OQL where results returned by OQL queries can be manipulated by OOPL.

23 23 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases C++ ODL class Department (extent Departments) { attribute string name; relationship set staff inverse Lecturer::worksFor; relationship set offers inverse Course::offeredBy; }; ODLODL const char _worksFor[ ] = “worksFor”; const char _offeredBy[ ] = “offeredBy”; class Department : d_Object {public: d_String name; d_Rel_Set staff; d_Rel_Set offers; }; d_Extent Departments(DB1); // for extent // DB1 is the database name C++C++ for inverse relationships

24 24 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases C++ OML Object Creation d_Ref S = new(DB1, “Student”) Student; // creates a new Student object in DB1 database d_Ref L = new(DB1, “Lecturer”) Lecturer; // creates a new Lecturer object in DB1 database Object Modification S->name = “Richard Spring”; // modifies name attribute of Student S S->address = “Durham”; // similarly L->room = 103; // modifies room attribute of Lecturer L L->tutees.insert_element(&S); // establishes a relationship // between Lecturer L and Student S Object Deletion L.delete_object(); // deletes the Lecturer object from the database

25 25 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases C++ OQL Define variables for the query result d_Bag > ComMathStaff; d_Bag > ToonArmy; Create an instance of type d_OQL_Query d_OQL_Query q (“select l from l in Lecturers where l.worksFor.name = $1); d_OQL_Query q1 (“select s from s in Students where s.address = “Newcastle”); Modify the query with Parameters q << “Computing and Maths”; // Imposes a restriction on the query Execute the query d_oql_execute(q, ComMathStaff); // executes the query q and stores the result into ComMathsStaff variable d_oql_execute(q1, ToonArmy); // executes the query q1 and stores the result into ToonArmy variable

26 26 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Summary An overview of ODMG standard An introduction to the Object Data Model A little bit of ODL Introduction to OQL Introduction to language binding


Download ppt "1 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Advanced Databases The ODMG Standard for Object Databases."

Similar presentations


Ads by Google