Introduction To Object-Oriented Databases: Goran Nenadic
Introduction To Object-Oriented Databases: Goran Nenadic
Aims
Understand the need for object oriented DBs Learn basic concepts and principles Learn the basics of ODL and OQL Understand advantages and disadvantages of object databases
Plan
Overview of object-oriented methodology Object data model (ODMG) Object definition language (ODL) Object query language (OQL) Object and object-relational DBs
continued
Need for
abstract data types encapsulation of operations inheritance better integration with programming languages
OODBs introduction
Integration of two technologies: OO programming and DBs Main ideas
raise the level of abstraction provide direct correspondence between real-world and database objects objects do not lose their integrity and identity and can easily be identified and operated upon
OODBs objects
An object belongs to a specific class Have structure, state (value), behavior (operations), identity, name(s) Object structure of arbitrary complexity
in order to contain all of the necessary information
OODBs operations
Applied to objects of a particular type
includes non-standard application-specific operations
Operator polymorphism/overloading
ability to be applied to different types of objects operation name may refer to several distinct implementations, depending on the type of objects it is applied to
10
Why OO standards?
One of the reasons for success of the relational database paradigm was the SQL standard
portability, interoperability
11
Note: ODMG
The ODMG is a non-profit consortium of database vendors and interested parties who collaborated to define data storage portability standards for object-oriented applications. Since its inception in 1991, the ODMG has continued to grow and today includes database vendors, tool vendors, consulting firms, and corporate end users. Member companies include Advanced Language Technologies, Andersen Consulting, Ardent Software, Baan, CERN, Computer Associates, Ericsson, GemStone Systems, Hitachi, IBEX Computing SA, JavaSoftSun Microsystems, Lockheed Martin, Microsoft, NEC Corporation, Object Design, The Object People, Objectivity, POET Software, Sybase, Telenor R&D, Versant Object Technology, and Watershed Technologies. The ODMG group completed its work on object data management standards in 2001 and was disbanded. The final release of the ODMG standard (ODMG 3.0, including the overall data model) can be found at http://www.odmg.org 12
13
continued
literals interface [see additional materials] class extent, key, factory objects
14
ODMG objects
Object has four characteristics
identifier (OID): unique system-wide identifier name: unique within a particular database and/or program; [optional] lifetime: persistent vs. transient structure: specifies how object is constructed by the type constructor and whether it is collection object atomic object
15
Contains
properties: attributes and relationships operations
17
ODMG literals
Literal has a current value but not an identifier
embedded in objects
18
ODMG class
Class is a specification of abstract behaviour and abstract state of an object
classes are instantiable
Inheritance through classes allows both state and behavior inheritance, but (strictly) among classes Two concepts related to classes: extent and key
19
continued
ODMG class
Extent of a class
contains all persistent objects of that class similar to creating an object of type Set<class_name> and making it persistent
Keys
one or more properties whose values are unique for objects in an extent e.g. national insurance number
20
21
ODMG database
ODMG Object Model supports the concept of databases as storage areas for persistent objects of a given set of types (defined by OM) A database has a schema that contains a set of type definitions (see ODL) ODMG defines interfaces for Database and DatabaseFactory objects
22
continued
ODMG database
Each OO database has
its database name bind operation (assigns individual unique names to persistent objects)
named objects are entry points to the database
unbind (removes bound names) lookup (retrieves an object with the specified name)
23
24
25
ODL
Supports semantics constructs of ODMG Independent of any programming language
but can be easily mapped to a OO language using the specific language bindings
Used to create object specifications (classes and interfaces) Not used for database manipulation
26
Pname {string fname, string lname} name; ssn; birthdate; Gender{M, F} sex; Address {short no, string street, string city, string post_code} address;
28
Multiple class inheritance is not supported! (but multiple behaviour inheritance is)
30
10
31
continued
continued
11
Operation names are unique within the class/interface Can specify exceptions
raising exceptions during operation execution
void register_student(in string ssn) raises(student_no_valid, section_full);
34
35
36
12
37
OQL
ODMGs query language Syntax is similar to SQL with additional features for objects Works closely with programming languages such as C++
embedded OQL statements return objects that are compatible with the type system of the host language
38
Basic syntax
SELECT d.name FROM d in departments WHERE d.college = Engineering;
An entry point to the database (e.g. named persistent object) is needed for each query Typically, an extent name (e.g., departments) may serve as an entry point
Recall: an extent is a persistent set of all persistent objects from a class
39
13
40
41
continued
42
14
where: <fromList> ::= <variableName> IN <expression>| <variableName> IN <expression>,<fromList>| <expression> AS <variableName>| <expression> AS <variableName>,<fromList>
43
44
continued
FacultyMember
set<FacultyMember>
45
15
46
47
Example
select struct( last_name: s.name.lname, first_name: s.name.fname, gpa: s.gpa), from s in informatics_dept.has_majors where s.class = senior order by gpa desc, last-name asc, first_name asc; Retrieve last and first names plus GPA (average) of all senior (i.e. final year) students in the InformaticsDept; order the results by gpa, and then by names
48
16
continued
Example
select struct( last_name: s.name.lname, first_name: s.name.fname, gpa: s.gpa), from s in students where s.majors_in.dname = Informatics and s.class = senior order by gpa desc, last-name asc, first_name asc; Retrieve last and first names plus GPA (average) of all senior (i.e. final year) students in the InformaticsDept; order the results by gpa, and then by names
49
50
51
17
52
Once a query definition is created, it will persist until deleted or redefined A view definition can include parameters
53
continued
18
Aggregate operators
OQL supports a number of aggregate operators (that operate over a collection) that can be applied to query results min, max, count, sum, and avg count returns an integer; others return the same type as the collection type
count (s in has_minors(Informatics)); count (select f.name from f in faculty where f.sex = F);
55
continued
Aggregate operators
avg (select s.gpa from s in students where s.class = senior and s.majors_in.dname =Business);
56
19
continued
58
Grouping operator
select deptname, avg_gpa : avg (select p.s.gpa from p in partition) from s in students group by deptname: s.majors_in.dname having count (partition) > 100;
expression attribute
20
61
62
continued
63
21
64
65
66
22
67
Current status
OODB market around $250M as opposed to the relational DB revenue of $20-50B OODBMS were originally thought of to replace RDBMS because of their better fit with objectoriented programming languages. However, high switching cost and the inclusion of objectoriented features in RDBMS to make them object-relational have made RDBMS successfully defend their dominance.
68
continued
Current status
Object databases are now established as a complement rather than a replacement for relational databases. OO ideas are being used in a large number of applications, without explicitly using the OODB platform to store data
OO tools for modelling and analysis, OO programming languages object relational DBMS
69
23
continued
Current status
Database services
RDBMS RDBMS
Object-relational DBMS
ODBMS OODBMS
Data modeling
70
continued
Many vendors provide specific type extensions for newer data type (e.g. cartridges in Oracle) Other vendors: Informix Universal Server, IBMs UDB, DB2/II
72
24
Open source
db4o Ozone Perst Zope (ZODB)
73
continued
75
25
continued
Summary
Overview of OO methodology Object model and various constructs and built-in types of the ODMG model presented ODL and OQL languages were presented Current state of OODBs/ORDBs, advantages and disadvantages discussed
77
78
26