Ch22 - Object-Based Databases - RDBMS
Ch22 - Object-Based Databases - RDBMS
(attributes that describe the object) and associated procedures known as methods (what you can do to that object). Object-oriented database management system is a DBMS where information is represented in the form of objects as used in objectoriented programming. Differ from relational database, which are table-oriented. Object-Relational Data Model extends the relational data model by including object orientated features and constructs to deal with added (complex) data types.
Bridge the gap (hybrid approach) between relational databases and
the object-oriented modeling techniques used in programming languages such as Java, C++, Visual Basic .NET, C# . RDBMS products focus on the efficient management of data using a simple data-types, an object-relational DBMS for the integration of user-defined types and the methods that apply to them into the DBMS.
22.2
Collection and large object types Nested relations are an example of collection types Structured types Nested record structures like composite attributes Inheritance Object orientation Including object identifiers and references Not fully implemented in any database system currently
But some features are present in each of the major commercial database systems Read the manual of your database system to see what it supports
22.3
Structured types (a.k.a. user-defined types) can be declared and used in SQL create type Name as (firstname varchar(20), lastname varchar(20)) final create type Address as (street varchar(20), city varchar(20), zipcode varchar(20)) not final
Note: final and not final indicate whether subtypes can be created
Structured types can be used to create tables with composite attributes create table person ( name Name, address Address, dateOfBirth date) Dot notation used to reference components: name.firstname
22.4
Methods
Can add a method declaration with a structured type.
create instance method ageOnDate (onDate date) returns interval year for CustomerType begin return onDate - self.dateOfBirth; end
We can now find the age of each customer:
22.5
Constructor Functions
Constructor functions are used to create values of structured types E.g.
create function Name(firstname varchar(20), lastname varchar(20)) returns Name begin set self.firstname = firstname; set self.lastname = lastname; end
To create a value of type Name, we use
insert into Person values (new Name(John, Smith), new Address(20 Main St, New York, 11001), date 1960-8-22);
22.6
Type Inheritance
Suppose that we have the following type definition for people:
create type Student under Person (degree varchar(20), department varchar(20)) create type Teacher under Person (salary integer, department varchar(20))
22.7
array [Silberschatz,`Korth,`Sudarshan]
Multisets
insert into books values (Compilers, array[`Smith,`Jones], new Publisher (`McGraw-Hill,`New York), multiset [`parsing,`analysis ]);
22.8
select title from books where database in (unnest(keyword-set )) We can access individual elements of an array by using indices E.g.: If we know that a particular book has three authors, we could write: select author_array[1], author_array[2], author_array[3] from books where title = `Database System Concepts To get a relation containing pairs of the form title, author_name for each book and each author of the book select B.title, A.author from books as B, unnest (B.author_array) as A (author ) To retain ordering information we add a with ordinality clause select B.title, A.author, A.position from books as B, unnest (B.author_array) with ordinality as A (author, position )
22.9
create type Department ( name varchar (20), head ref (Person) scope people)
We can then create a table departments as follows
and instead make an addition to the create table statement: create table departments of Department (head with options scope people)
Referenced table must have an attribute that stores the identifier, called
the self-referential attribute create table people of Person ref is person_id system generated;
22.10
Object-Relational Mapping
Object-Relational Mapping (ORM) systems built on top of traditional
relational databases Mapping from objects to relations Objects are purely transient, no permanent object identity Objects can be retrieved from database
System uses mapping to fetch relevant data from relations and construct objects Updated objects are stored back in database by generating corresponding update/insert/delete statements The Hibernate ORM system is widely used described in Section 9.4.2 Provides API to start/end transactions, fetch objects, etc Provides query language operating direcly on object model queries translated to SQL Limitations: overheads, especially for bulk updates
22.11
simple data types, powerful query languages, high protection. Persistent-programming-language-based OODBs complex data types, integration with programming language, high performance. Object-relational systems complex data types, powerful query languages, high protection.
Object-relational mapping systems
complex data types integrated with programming language, but built as a layer on top of a relational database system Note: Many real systems blur these boundaries E.g. persistent programming language built as a wrapper on a relational database offers first two benefits, but may have poor performance.
22.12
End of Chapter 22