Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Advanced Databases (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies.

Similar presentations


Presentation on theme: "1 Advanced Databases (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies."— Presentation transcript:

1 1 Advanced Databases (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies School of Informatics Dr. Akhtar Ali The ODMG Standard for Object Databases

2 2 Advanced Databases (CM036) – 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.

3 3 Advanced Databases (CM036) – 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.

4 4 Advanced Databases (CM036) – 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.

5 5 Advanced Databases (CM036) – 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).

6 6 Advanced Databases (CM036) – 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 >.

7 7 Advanced Databases (CM036) – 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.

8 8 Advanced Databases (CM036) – 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

9 9 Advanced Databases (CM036) – 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

10 10 Advanced Databases (CM036) – 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

11 11 Advanced Databases (CM036) – 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 (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies."

Similar presentations


Ads by Google