AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

24
AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES

Transcript of AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

Page 1: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

A N D O B J E C T- O R I E N T E D DATA B A S E S

OBJECT-RELATIONAL DATABASES

Page 3: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

PROBLEMS WITH PRE-OBJECT-ERA RELATIONAL DATABASE SYSTEMS

• Extreme impedance mismatch• Atomic values are only common data type

• Complex objects demand many-way joins and relational dbs are not optimized for this• Difficult to create similar but different table

structures, like cars and red-cars• You must program with two very different

languages• Difficult to represent objects that are collections

Page 4: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

AN OVERRIDING PROBLEM: ONLY VALUE-BASED SEMANTICS

• No notion of object identity• We make assumptions about object identity based on key

values• We manipulate tuples that represent properties of

objects, not the objects themselves• We can look cardinality information about object sets by

doing selections

• No notion of versioning• We must simulate versions or time-based variations by

using multiple tuples and temporal/version fields

Page 5: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

WHAT IS A RELATIONAL DB?

• Collections of tables• A set of tuples, with atomic domains• Keys, FKs, null limits, FDs and MVDs, and triggers

• Manipulated with SQL• We extract semantics at runtime

Page 6: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

WHAT IS (OR WOULD BE) AN OBJECT DATABASE?

• Collections of classes• Defined by types• Including behavioral encapsulation• Subtypes allowed

• Components of an object can be sets, tuples, other objects• Manipulated with an object-oriented language extended

with an SQL derivative that includes path expressions

Page 7: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

OBJECT IDENTITY

• The key questions: • are these the same object or are they two objects that

look the same?• What is all the relevant information about this particular

object?

• Object IDs are immutable: different ID, different object• A relational PK only tells us that this description of

some object out there is unique

Page 8: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

AN OBJECT IS A…

• Pair (OID, value)• The oid is unseen• The value can have structure, such as…• A flat tuple• A tuple with a collection attribute• A tuple with an oid value attribute

Page 9: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

MORE PRECISELY, A VALUE IS…

• Primitive – like an integer or char string• A reference value, i.e., an oid• A tuple (at1: value1, at2:value2, …, atn: valuen)• A set {}

Page 10: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

A CLASS IS…

• A group of objects structured by a type• Three parts• Type• Method signatures• An extent – the objects in the class

• Classes are organized in a class hierarchy

Page 11: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

ODMG

• Group of object db vendors• Developed a standard• ODL – object definition language• OQL – object query language• A transaction protocol• Language bindings for c++, smalltalk, java

Page 12: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

THE BIG IDEA BEHIND OBJECT DATABASES

• Objects in the host language are identical in nature to the ones in the DB• Objects can become persistent “selectively”• Manipulating an object or a group of objects is the

same in the host language and the db language – because it is a single language• This is a “persistent programming language”• No more JDBC connectivity needed• No more embedding SQL in the host language• No more impedance mismatche

Page 13: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

A NOTE ON MULTIPLE LANGUAGE BINDINGS

• C++, Java, Smalltalk, C# are similar, but not identical• So we need a “reference data model” to map

these languages to

Page 14: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

WHY DID THEY DIE?

• Demands a new application stack• New database• New query language• Not optimized for set selection• The perceived need apparently wasn’t there• We are used to forms and tables• Potential user domains needed so much more, like

engineering constraints, solid modeling, animation, complex version hierarchies

Page 15: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

OBJECTS IN THE SMALL:THE SQL OBJECT EXTENSION

• First, all legacy relational databases are valid• A relation is• A set of tuples OR…• A set of objects

• An object is an oid and a tuple-value• A tuple value is (at1: value1, at2:value2, …, atn:

valuen)

Page 16: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

A VALUE IS

• Primitive• Reference (an oid)• Another tuple• A collection• Multiset• Fixed sized array

Page 17: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

NOTE

• A tuple can have complex internal structure without having to be an object• Thus, we call this “objects in the small”

Page 18: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

EXAMPLE TABLE

CREATE TABLE students ( Name CHAR(30),

Address row(Number INTEGER, Street CHAR(20), ZIP CHAR(5))

)

Page 19: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

EXAMPLE QUERIES

SELECT students.nameFROM student s sWHERE s.address.zip = ‘80309’

INSERT INTO students(Name, Address)VALUES (‘John Doe’, row “123 Elm, ‘80309’))

Page 20: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

USER DEFINED TYPES(UDTS)

• These encapsulate structural and behavioral content• A UDT can serve as the domain of an attribute

Page 21: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

EXAMPLE TYPE

CREATE TYPE PersonType AS (Name CHAR(20),Address ROW(Number INTEGER, Street CHAR(20),

ZIP CHAR(5)) );

CREATE TYPE StudentType UNDER PersonType AS (Id INTEGER,Status CHAR(2)

)METHOD award_degree() RETURNS BOOLEAN;

CREATE METHOD award_degree() FOR StudentTypeLANGUAGE CEXTERNAL NAME ‘file:/home/admin/award_degree’;

Page 22: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

EXAMPLE TABLE CREATION

• As an attribute type:

CREATE TABLE TRANSCRIPT (Student StudentType,CrsCode CHAR(6),Semester CHAR(6),Grade CHAR(1)

)

• As a table type:

CREATE TABLE STUDENT OF StudentType;

Such a table is called typed table.

Page 23: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

IMPORTANT DISTINCTION

• Only typed tables contain objects (ie, tuples with oids)• Compare:

CREATE TABLE STUDENT OF StudentType;

andCREATE TABLE STUDENT1 (

Name CHAR(20), Address ROW(Number INTEGER, Street CHAR(20),

ZIP CHAR(5)), Id INTEGER, Status CHAR(2) )

• Both contain tuples of exactly the same structure• Only the tuples in STUDENT – not STUDENT1 – have oids

Page 24: AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.

EXAMPLE COLLECTION TYPE

• Set (multiset) data type was added in SQL:2003.

CREATE TYPE StudentType UNDER PersonType AS (Id INTEGER,Status CHAR(2),Enrolled REF(CourseType) MULTISET

)