Object Based Databases

33
Fall 2013 insert into ' Advanced_Database_Course (' Title ',' Author ') values( Object - Based Databases ‘, Farzad Nozarian );

Transcript of Object Based Databases

Fall 2013

insert into

'Advanced_Database_Course’

('Title','Author') values(

‘Object-Based Databases‘,‘Farzad Nozarian‘

);

•Summary

Overview1

Complex Data Types2

Structured Types and

Inheritance in SQL3

Structured Types3.1

Type Inheritance3.2

•Summary

Table Inheritance4

Array and Multiset Types in SQL5

Querying Collection-Valued Attributes

5.2

Nesting and Unnesting5.3

Creating and Accessing Collection Values

5.1

Overview

• richer type system including complex data types and

object orientation

•Overview

Obstacles using the relational data model

Object-relational database systems

• limited type system support

• difficulty in accessing database data from in C++ or Java

Object-relational data model

• migrate for users who wish to use object-oriented features

•Overview

Persistence

Storage management

Concurrency

Recovery

Querying

DBMS

Object-Oriented Database

complex objects

object identity

encapsulation

types & classes

class hierarchy

extensibility

Computational completeness

overriding & overloading

Object-Oriented System

+

•Overview

• Motivation for the development of complex data types

• Object-relational database systems

• Supporting persistence for data

• object-oriented database system

• object-relational mapping

• Object-relational approach Vs. object-oriented approach

Overview

Complex Data Types

•Complex Data Types

Example1 : addresses

Example 2: phone numbers

(street, address, city, state, postal code)

Atomic data item of type string

A better alternative structured data types

The alternative of normalization by creating a

new relation is expensive and artificial for this example.

Using normalization ?!

•Complex Data Types

A library application

satisfies 4NF

Several domains will be non-atomic

•Complex Data Types

The 4NF design requires queries to join multiple relations,

whereas the non-1NF design makes many types of queries

easier.

The typical user or programmer of an information-retrieval

system thinks of the database in terms of books having sets

of authors, as the non-1NF design models.

Overview

Complex Data Types

Structured Types and Inheritance in SQL

•Structured Types and Inheritance in SQLStructured Types

Allow composite attributes of E-R designs to be

represented directly

create type Name as

(firstname varchar(20), lastname varchar(20)) final;

create type Address as(street varchar(20),city varchar(20),zipcode varchar(9))not final;

•Structured Types and Inheritance in SQLStructured Types

We can now use these types to create

composite attributes in a relation

create table person(name Name,address Address,dateOfBirth date);

The components of a composite attribute can

be accessed using a “dot” notation

•Structured Types and Inheritance in SQLStructured Types

We can also create a table whose rows are of a user-defined type

create type PersonType as (name Name,address Address,dateOfBirth date)not final

create table personof PersonType;

•Structured Types and Inheritance in SQLStructured Types

An alternative way of defining composite

attributes in SQL is to use types.

create table person_r(name row (firstname varchar(20),lastname varchar(20)),address row (street varchar(20),city varchar(20),zipcode

varchar(9)),dateOfBirth date);

select name.lastname,address.cityfrom person;

name and address have

rows of the table also have an !

finds the last name and city of each person

•Structured Types and Inheritance in SQLStructured Types

create type PersonType as (name Name,address Address,dateOfBirth date)not final

method ageOnDate(onDate date)returns interval year;

A structured

type can have

methods

defined on it !

•Structured Types and Inheritance in SQLStructured Types

Can I create the method body separately ?

create instance method ageOnDate(onDate date)returns interval yearfor PersonType

beginreturn onDate−self.dateOfBirth;

end

• which type this method is for

can contain procedural statements!

• refers to the Person instance on which the method is invoked

• this method executes on an instance of the Person type

Yes !

How to find the age

of each person ?

•Structured Types and Inheritance in SQLStructured Types

select name.lastname,

ageOnDate(current_date)

from person;

create function Name( firstname varchar(20), lastname varchar(20) )

returns Name

begin

set self.firstname = firstname;

set self.lastname = lastname;

end

•Structured Types and Inheritance in SQLStructured Types

constructor functions are used to create values of structured types

How we can create a value of Name type ?

new Name(’John’, ’Smith’)

•Structured Types and Inheritance in SQLStructured Types

Example : Create a new tuple in the Person

relation

insert into Person

values

( new Name(’John’, ’Smith’),

new Address(’20 Main St’, ’New York’, ’11001’),

date ’1960-8-22’);

Note !

By default every structured type has a constructor with no arguments,

which sets the attributes to their default values

•Structured Types and Inheritance in SQLType Inheritance

create type Person

(name varchar(20),

address varchar(20));

create type Student

under Person

(degree varchar(20),

department varchar(20));

create type Teacher

under Person

(salary integer,

department varchar(20));

•Structured Types and Inheritance in SQLType Inheritance

Can you create a TeachingAssistant type ?

Methods of a structured type are inherited by its

subtypes using overriding method

The keyword final says that subtypes may not be

created from the given type

not final says that subtypes may be created.

create type TeachingAssistant under Student, Teacher;

Yes !

•Structured Types and Inheritance in SQLType Inheritance

any problem ?!

name address in

department in

Person

Teacher

Student

create type TeachingAssistant

under Student with(department as student_dept),

Teacher with(department as teacher_dept);

Note!

The SQL standard does not support

multiple inheritance

Overview

Complex Data Types

Structured Types and Inheritance in SQL

Table Inheritance

•Table Inheritance

Subtables in SQL correspond to the E-R notion of

specialization/generalization.

create table people of Person;

create table students of Student

under people;

create table teachers of Teacher

under people;

•Table Inheritance

Question

delete from people where P ;only people

Array and Multiset Types in SQL

Overview

Complex Data Types

Structured Types and Inheritance in SQL

Table Inheritance

•Array and Multiset Types in SQL

SQL supports two collection typesarrays

multisets

SQL:1999

SQL:2003

create type Publisher as

(name varchar(20),

branch varchar(20));

create type Book as

(title varchar(20),

author_array varchar(20) array[10],

pub_date date,

publisher Publisher,

keyword_set varchar(20) multiset);

create table books of Book;

•Array and Multiset Types in SQLCreating and Accessing Collection Values

An array of values can be created in SQL:1999 in this way:

array[’Silberschatz’, ’Korth’, ’Sudarshan’]

A multiset of keywords can be constructed as follows:

multiset[’computer’, ’database’, ’SQL’]

insert into booksvalues (’Compilers’, array[’Smith’, ’Jones’], new Publisher(’McGraw-Hill’, ’New York’),multiset [’parsing’, ’analysis’] );

But, How we can access or

update elements of an

array ?

•Array and Multiset Types in SQLQuerying Collection-Valued Attributes

find all books that have the

word “database” as one of

their keywords

select title from books

where ’database’ in (

unnest (keyword_set) );

select author_array[1],author_array[2],author_array[3]

from books

where title = ’Database System Concepts’;

•Array and Multiset Types in SQLQuerying Collection-Valued Attributes

select B.title, A.author

from books as B, unnest (B.authorarray) as

A(author);

select title, A.author, A.position

from books as B,

unnest(B.author_array) with ordinality as A(author,

position);

Thanks