26
Object-Oriented Database Felipe Brigalante Hugo Mitsumori Revisor: Mateus Rocha Mazzari 1

Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

  • Upload
    vancong

  • View
    230

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object-Oriented DatabaseFelipe BrigalanteHugo Mitsumori

Revisor: Mateus Rocha Mazzari

1

Page 2: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Database● Collection of related data with inner meaning

● Represents real world aspects

● Can be maintained and manipulated using a DBMS

● Can be used by applications to provide data persistence

● Different model types. Ex: relational, document, graph, key-value, object-

oriented, etc

2

Page 3: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Relational Databases● Created in 1970

● Store and access of data via relations (tables)

● Conceptual model and physical storage

● Structured Query Language

● PC’s and Large servers

● The most used for traditional applications

3

Page 4: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object mapping issues for relational databases● Encapsulation

● Inheritance

● Data types

● Structural

4

Page 5: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

The appearance of OODB● Advent of the oriented-object languages

● Necessity to store and share complex objects

● 80s: begin of researches for OODB

○ Development of the first OODB Management Systems

● Lack of standards

● ODMG fundation

● Today: Object-Relational Databases5

Page 6: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

General Features● Complex Objects

● Object Identity

● Encapsulation

● Types and Classes

● Hierarchy

● Overriding, overloading, late binding

6

Page 7: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

General Features● Complex Objects

○ Simple Objects: Integers, Chars, booleans, byte strings, etc

○ Constructors: List, Bags, Arrays, Sets, Tuples, etc

○ Complex Objects: Simple Objects with “constructors”

○ Operations: Deletion and Update propagations, copy

7

Page 8: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

General Features● Object Identity

○ Identity vs Equality

○ Object Sharing

○ Object Update

○ Operations: Object Assignment, Copy, Equivalence Tests

8

Page 9: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

General Features● Encapsulation

○ Data and operation

○ Indirect access to data and restriction

○ Hidden data information and operations implementation

○ Logical data independence

9

Page 10: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

General Features● Types and Classes

○ Type: summarizes common features of a set of objects

■ Interface + Implementation

■ Only the Interface is visible

○ Class

■ Concrete structure

■ Two aspects: Object Factory and Object Warehouse

■ Manipulation of Objects

10

Page 11: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

General Features● Hierarchies (Inheritance)

○ Substitution

○ Inclusion

○ Constraint

○ Specialization

11

Page 12: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

General Features● Overriding, overloading and late binding

○ Overloading: different signatures for the same method

○ Overriding: substitute the implementation of a method

○ Late binding: bind operations names with the program at run-time

12

Page 13: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Other Mandatory Features● Computational Completeness● Extensibility● Persistence● Secondary storage management● Concurrency● Recovery● Ad Hoc Query facility

13

Page 14: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Standards● Object Data Management Group (ODMG), put a set of specifications with

respect to:○ Data Schema○ Programming Language Bindings (Smalltalk, Java and C++)○ Data Manipulation○ Query Languages

● Between 1993 and 2001, the ODMG published five revisions to its specification. The last revision was ODMG version 3.0, after which the group disbanded.

14

Page 15: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object Definition Language1. Defined by ODMG standards

2. Defines the interface to object types

3. Creates an abstraction layer, making data language and database

implementation independent

15

Page 16: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object Definition Language - Banking Example

Cardinality constraint: each loan belongs to a single branch16

Page 17: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object Definition Language - Exampleinterface Customer {

attribute integer ss#;attribute string name;attribute Struct Addr {string street, string city, int zip} address; relationship Set<Loans> borrowed inverse Loans::borrower;relationship Set<Branch> has-account-at inverse Branch:patrons;key(ss#)

}

17

Page 18: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object Definition Language - Exampleinterface Loan {

attribute real amount;attribute int loanid;attribute Enum loanType {house, car, general} type; relationship Branch belongs-to inverse Branch::loans-granted; relationship Set<Customer> borrower inverse Customer::borrowed;key(loanid)

}

18

Page 19: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object Definition Language - Exampleinterface Branch {

attribute integer branchid;attribute Struct Customer::Addr location;relationship Se<Loans>t loans-granted inverse Loans::belongs-to; relationship Set patrons inverse Customer::has-account-at;key(branchid);

}

19

Page 20: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

ODL Type System● Basic types: int, real/ float, string, enumerated types, and classes

● Type constructors: Struct for structures and four collection types: Set, Bag, List, and Array

20

Page 21: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

ODL Subclasses● Example: Faculty and Staff are subclasses of Employee. Faculty have

academic year (9 month salaries) but staff has a full-year (12 month salary)

● Follow name of subclass by colon and its superclass.○ interface Faculty:Employee { attribute real academic-year-salary; }

● Objects of the Faculty class acquire all the attributes and relationships of the Employee class.

21

Page 22: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object Query Language● Developed by ODMG, Object Query Language allows SQL-like queries to

be performed on a OODB● Like SQL, it is a declarative language. Based loosely on SQL, OQL includes

additional language constructs which allow for object oriented design such as operation invocation and inheritance.

● OQL only refers to SELECT statements. SQL includes both DDL and DML statements.

22

Page 23: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Object Query Language - Example● List all books written by someone whose name starts with ‘Camus’

○ SQL:

■ SELECT Book JOIN Artist ON Book.written_by = Artist.id WHERE Artist.name LIKE ’Camus%’

○ OQL:■ SELECT Book WHERE Book.writer.name LIKE ’Camus%’

● Audio, Video and Book are subclasses of Item. How to list items not being produced by a French company○ SELECT Item WHERE item.producer.country != ’France’

23

Page 24: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Native Queries● In 2005 was proposed to drop all standardization efforts to introduce

additional object-oriented query APIs but rather use the OO programming language itself

● Example using db4o with Java native query:○ // Find all the Brians

ObjectSet brians = db.get(new Person("Brian", null, 0));while (brians.hasNext())

System.out.println(brians.next());

24

Page 25: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Advantages and disadvantages

25

Advantage Disadvantage

● Complex objects & relations● Class hierarchy● No impedance mismatch● One data model● High performance on certain tasks● Less programming effort because

of inheritance, re-use and extensibility of code

● Schema change (creating, updating) is non trivial, it involves a system wide recompile.

● Language dependence: tied to OO languages (or specific languages when using native queries)

● Lack of Ad-Hoc query

Page 26: Object-Oriented Database - social.stoa.usp.br · Object Query Language Developed by ODMG, Object Query Language allows SQL-like queries to be performed on a OODB Like SQL, it is a

Bibliographic References● The Object-Oriented Database System Manifesto

● http://wwwbayer.in.tum.de/lehre/WS2001/HSEM-bayer/OODBMS.pdf

● http://www.ics.uci.edu/~dbclass/ics184/class-notes/odl.pdf

● Sistemas de Bancos de Dados (6a edição), Elmasri e Navathe. Pearson, 2010

● Foundations of object relational mapping, Mark Fussell

26