Download presentation
Presentation is loading. Please wait.
Published byDoris Welch Modified over 9 years ago
1
ORDBS1 Object Relational Database Systems: 1. Introduction 2. Objects in SQL3 3. Comparison of ODL/OQL and SQL3 Approaches CIS 671
2
ORDBS2 Object Query Language (OQL) “Bring the best of SQL to the object world.” Syntax similar to SQL Plus additional features Works with programming languages where ODMG has defined bindings –Java, C++, Smalltalk –Returns object matching type system of that language –May implement class operations in these languages SQL3 – “Bring the best of the object-oriented world to the relational world.”
3
ORDBS3 Overview:Object Relational DB Systems SQL3 Interfacing SQL to a programming language. –Cursors Data Types –Built-in –User Defined Operations
4
ORDBS4 Data Types – Built-in smallint – 16-bit integer integer – 32-bit integer decimal(p,s) – decimal number, precision p, scale s float – 32-bit float double – 64-bit float date – year, month, day time – hour, minute, second timestamp - year, month, day, hour, minute, second, microsecond interval – year/month or day/time char(n) – fixed length, n ≤ 254 varchar(n) – varying length –n ≤ 254 –254 ≤ n ≤ 4000; no group by, etc. bit(n) varbit(n) boolean [SQL3] Large Objects [SQL3] –blob(binary large object) ≤ 2 31 –1 bytes –clob(character large object) ≤ 2 31 –1 bytes Domain e.g.,create domain SSN_TYPE as char(9) not used much.
5
ORDBS5 Objects in SQL3 Row objects, tuples or structs, and Abstract data types (ADT), general objects, used as components of tuples.
6
ORDBS6 Movies title year length /* in minutes */ filmType:{color, blackAndWhite} lengthInHours starNames otherMovies Movies Example: Movies, Stars, Studios ODL Version Stars name address street city Studios name starsstarredIn ownedByowns Set of stars of this movie. Other movies by star of this movie.
7
ORDBS7 Movies Example: Movies, Stars, Studios ER Version MovieMovieStar StarsIn NM
8
ORDBS8 Row Types [SQL3 or SQL:1999] Row-type Definition: create row type T ( ) Examples: create row type AddressType( streetchar(50), citychar(20)); create row type StarType( namechar(30), addressAddressType ); create table MovieStar of type StarType; selectMovieStar..name, MovieStar..address..street fromMovieStar WhereMovieStar..address..city = ‘Columbus’; Cannot directly represent set of movies starred-in. Double dot Path Exp.
9
ORDBS9 References SQL3’s way to represent “objects”. create row type StarType( namechar(30), addressAddressType ); create row type MovieType( titlechar(30), yearinteger ); create row type StarsInType( starref(StarType), movieref(MovieType) ); create table Movie of type MovieType; create table MovieStarof type StarType; create table StarsIn of type StarsInType; select movie -> title fromStarsIn wherestar->name = ‘Mel Gibson’ Dereferencing operator (->) MovieMovieStar StarsIn NM
10
ORDBS10 Object Identifiers May be explicitly declared and accessed. Can serve as both object ID and primary key. create row type MovieType( movie_idref(MovieType), titlechar(30), yearinteger ); create row type StarType( star_idref(StarType), namechar(30), addressAddressType ); create table Movie of type MovieType values for movie_id are system generated; create table MovieStarof type StarType values for star_id are system generated;
11
ORDBS11 Specifying Scope to Aid Performance create row type StarsInType( starref(StarType), movieref(MovieType) ); create table StarsIn of type StarsInType scope forstarisMovieStar, scope formovieisMovie; select movie -> title fromStarsIn wherestar->name = ‘Mel Gibson’ How to find movies? Examine every StarsIn tuple. Index on name attribute. Could have another relation with StarType.
12
ORDBS12 Objects in SQL3 Row objects, tuples or structs (REVIEW), and Abstract data types (ADT), general objects, used as components of tuples.
13
ORDBS13 Abstract data type (ADT) Used as components of tuples, –Not as tuples themselves. Have tuple structure.
14
ORDBS14 ADT - “Built-in” Functions Constructor functions returning new object of type. –All attributes initially null. –If T is name of ADT, then T() is constructor. Observer functions for each attribute. –If A is attribute name & X is variable whose value is an object of the ADT, then A(X) (or X.A ) is the value of attribute A of object X. Mutator functions for each attribute. –Sets the value of that attribute to a new value. –Normally used on left side of assignment
15
ORDBS15 Example: Address ADT create type AddressADT ( streetchar(50), citychar(20), equalsaddrEq, less thanaddrLT other functions could be declared here ); Addresses will be encapsulated Access to street & city allowed only if observer and mutator functions made public. Functions addrEQ and addrLT defined later.
16
ORDBS16 More interesting example: ADT for Mpegs create type Mpeg ( videoblob, lengthinteger, copyrightvarchar(255), equals default, /* i.e., identity */ less than none definitions of MPEG functions go here );
17
ORDBS17 Defining Methods for ADT’s Function types –Internal Written in SQL. –External Written in C++, Java, etc. Only signature appears in definition of the ADT. Function ( ) returns ;
18
ORDBS18 Extended SQL := used as assignment operator. Variable local to the function can be declared by giving its name, preceded by a colon and followed by its type. :schar(50)/* s will be a street */ Dot operator used to access components of a structure :a.street := :s /* a, an address */ Boolean values can be expressed as in where clauses. begin and end are used to collect several statements into the body of a function.
19
ORDBS19 Some Functions for the ADT AddressADT: 1. Constructor Function function AddressADT (:s char(50), :c char(20)) returns AddressADT; :a AddressADT; /* declare local variable */ begin :a := AddressADT(); /* use built-in constructor */ :a.street := :s; :a.city := :c; return :a; end; Note:We can use the same name, AddressADT, as the default constructor.
20
ORDBS20 More Functions for the ADT AddressADT: 2. equals (addrEq )and less than (addrLT) Functions function addrEq (:a1 AddressADT, :a2 AddressADT) returns boolean; return (:a1.street= :a2.street and :a1.city = :a2.city); function addrLT (:a1 AddressADT, :a2 AddressADT) returns boolean; return ((:a1.city < :a2.city) or (:a1.city = :a2.city and :a1.street < :a2.street));
21
ORDBS21 Another Function for the ADT AddressADT: function fullAddr (:a AddressADT) returns char(82); :z char(10); /* for the zip code nnnnn-nnnn*/ begin :z := findZip(:a.street, :a.city ); return (:a.street || ‘ ‘ || :a.city || ‘ ‘ || :z); end; 3. fullAddr, function returning the full address, including zip code, as a single character string findZip, an externally defined function which looks up the zip code for a given city and street.
22
ORDBS22 External Functions ADT Definition must include: –Signature. –Specification of programming language in which function is written. declare external findZip char(50), char(20) returns char(10) language Java; Arguments passed according to Java conventions.
23
ORDBS23 Comparison of ODL/OQL and SQL3 Approaches Similarities outweigh differences, even though origins different: –ODL/OQL: object-oriented programming languages. –SQL3: relational database languages. Have effectively adopted ideas from each other.
24
ORDBS24 Comparing ODL/OQL vs. SQL3 actually ODL/OQL vs. SQL3 row types vs. SQL3 ADT types 1.Programming environment. 2.Role of relations. 3.Encapsulation. 4.Extents of classes. 5.Mutability of objects. 6.Object identity.
25
ORDBS25 ODL/OQL vs. SQL3 row types vs. SQL3 ADT types 1. Programming environment OQL –Assumes statements embedded in OO programming language, C++, Java, … SQL3 –Objects not objects of surrounding programming language. –External functions in SQL3 ADT’s provide additional flexibility.
26
ORDBS26 ODL/OQL vs. SQL3 row types vs. SQL3 ADT types 2. Role of relations OQL –Sets and bags of objects or structures are central. SQL3 –Relations are central. –Row types describe relations. –ADT’s describe new types for attributes. Collections of structures in ODL/OQL similar to Relations in SQL3.
27
ORDBS27 SQL3 Row Types –Not encapsulated. –Querying & modifying relations, tuples, and components allowed. SQL3 ADT’s –Encapsulated in the usual sense. ODL Classes –Similar to SQL3 ADT’s in encapsulation ODL/OQL vs. SQL3 row types vs. SQL3 ADT types 3. Encapsulation
28
ORDBS28 ODL/OQL vs. SQL3 row types vs. SQL3 ADT types 4. Extents for Classes OQL –Single extent maintained for each class. –Thus references (relationships in OQL) always refer to some member or members of this extent. SQL3 –An extent for a row type allowed, but not required. If no extent for a row type, then may be problem finding relation containing referenced tuple.
29
ORDBS29 ODL/OQL vs. SQL3 row types vs. SQL3 ADT types 5. Mutability of Objects Immutable Object: once created, no part of its values can change. –Objects of elementary type, e.g., integers or strings, are immutable. Mutable Object: components may change, while object retains its identity. ODL Classes & SQL3 Row Types –Define classes of mutable objects. –ODL/OQL: modification occurs through surrounding programming language, not through OQL. SQL3 ADT’s –Mutator functions applied to their values result in new value, which may replace old one. Similar to SQL update statement on integer-valued attribute produces a new integer that might replace the old integer in the tuple.
30
ORDBS30 ODL/OQL vs. SQL3 row types vs. SQL3 ADT types 6. Object Identity OQL & SQL3 ADT’s –“Standard” OID: system generated, which cannot be stored or manipulated by user. SQL3 Row Type –User can create “primary key”. –Without this relations would usually have two “keys”: OID Surrogate value, e.g., Employee_ID.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.