Docsity

Object Relational Systems - Lecture Slides | CS 610, Study notes of Deductive Database Systems

Toggle sidebar
bg1
Ob ject-Relational Systems
๎˜
Ob ject-oriented ideas enter the relational
world.
โœฆ
Keep relation as the fundamental
abstraction.
๎˜
Compare with \ob ject-oriented DBMS," which
uses the class as the fundamental abstraction
and tacks on relations as one of manytypes.
Motivations
๎˜
Allow DBMS's to deal with specialized types
| maps, signals, images, etc. | with their
own specialize d methods.
๎˜
Supports specialized methods even on
conventional relational data.
๎˜
Supports structure more complex than \๎˜at
๎˜Œles."
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Object Relational Systems - Lecture Slides | CS 610 and more Study notes Deductive Database Systems in PDF only on Docsity!

Ob ject-Relatio nal Systems

 Ob ject-oriented ideas enter the relational world. F Keep relation as the fundamental abstraction.

 Compare with \ob ject-oriented DBMS," which uses the class as the fundamental abstraction and tacks on relations as one of many typ es.

Motivatio ns

 Allow DBMS's to deal with sp eciali zed typ es | maps, signals, images, etc. | with their own sp ecialize d metho ds.

 Supp orts sp ecializ ed metho ds even on conventional relational data.

 Supp orts structure more complex than \ at les."

Plan

  1. Basic ideas from SQL3 standards do cuments.
  2. Use Oracle 8 notation when similar.
  3. Intro duce some new concepts from Oracle 8.

F On-line do cument: or-objects.html.

Oracle 8 Approach

While SQL3 talks ab out typ es (for columns) and row-typ es (for relations), Oracle 8 uses ob ject- typ es for b oth.

Example

CREATE TYPE BarType AS OBJECT ( name CHAR(20) UNIQUE, addr CHAR(20) );

CREATE TYPE BeerType AS OBJECT ( name CHAR(20) UNIQUE, manf CHAR(20) ); CREATE TYPE MenuType AS OBJECT ( bar REF BarType, beer REF BeerType, price FLOAT );

 Note: in Oracle, typ e de nitions must b e followed by a slash (/) in order to get them to compile.

Creating Tables

Typ e declarations do not create tables.

 They are used in place of element lists in CREATE TABLE statements.

Example

CREATE TABLE Bars OF BarType; CREATE TABLE Beers OF BeerType; CREATE TABLE Sells OF MenuType;

Accessing Fields of an Ob ject

The dot op erator works as exp ected.

 Thus, if we want the bar name and address without the constructor: SELECT bb.name, bb.addr FROM Bars bb;

 The alias bb is not technicall y necessary, but there are other places where we must use an alias in order to access ob jects, and it is a go o d habit to use an alias always.

Inserting Values

We can use the standard INSERT in Oracle, but we must wrap the inserted ob ject in its typ e- constructor.

Example

INSERT INTO Bars VALUES( BarType('Joe''s Bar', 'Maple St.') );

Need to Use Aliases

If you access an attribute whose typ e is an ob ject typ e, you must use an alias for the relation. E.g.,

SELECT favBeer.name FROM Drinker;

will not work. Neither will:

SELECT Drinker.favBeer.n ame FROM Drinker;

You have to say:

SELECT dd.favBeer.name FROM Drinker dd;

Dereferencing in SQL

A! B = the B attribute of the ob ject referred to by reference A.

Example

Find the b eers served by Jo e.

SELECT beer -> name FROM Sells WHERE bar -> name = 'Joe''s Bar';

Oracle's DEREF Op erator

If we wanted the entire BeerType ob ject, we might try to write

SELECT ss.beer FROM Sells ss WHERE ss.bar.name = 'Joe''s Bar';

That is legal, but ss.beer is a reference, and we'd get a gibb erish value.

 To see the whole b eer ob ject, use:

SELECT DEREF(ss.beer) FROM Sells ss WHERE ss.bar.name = 'Joe''s Bar';

Metho ds

Real reason ob ject-relational isn't just nested structures in relations.

 We'll follow Oracle 8 syntax.

 Declared in a CREATE TYPE statement, de ned in a CREATE TYPE BODY statement.

 Metho ds are functions or pro cedures; in Oracle they are de ned like any PL/SQL pro cedure or function. F But, there is a sp ecial tuple variable SELF that refers to that ob ject to which the metho d is applied.

Some Points to Rememb er

 The pragma is needed to allow priceInYen to b e used in queries. F WNDS = \write no database state."

 In the declaration, function/pro cedure arguments need a mo de, IN, OUT, or IN OUT, just like PL/SQL pro cedures. F But the mo de do es not app ear in the de nition.

 Many metho ds will take no arguments (relying on the built-in \self "). F In that case, do not use parentheses after the function name.

 The b o dy can have any numb er of function declarations, separated by semicolons.

Example of Metho d Use

Follow a designator for the ob ject to which you want to apply the metho d by a dot, the name of the metho d, and argument(s).

SELECT ss.beer.name, ss.priceInYen(106.0) FROM Sells ss WHERE ss.bar.name = 'Joe''s Bar';

Example

Order BarType ob jects by name.

CREATE TYPE BarType AS OBJECT ( name CHAR(20) UNIQUE, addr CHAR(20), ORDER MEMBER FUNCTION before( bar2 IN BarType) RETURN INT, PRAGMA RESTRICT REFERENCES(before , WNDS,RNDS,WNPS,RNPS) ); /

CREATE TYPE BODY BarType AS ORDER MEMBER FUNCTION before(bar2 BarType) RETURN INT IS BEGIN IF SELF.name < bar2.name THEN RETURN -1; ELSIF SELF.name = bar2.name THEN RETURN 0; ELSE RETURN 1; END IF; END; END; /

 The extra co des in the pragma guarantee no reading or writing of the database state or the \package state."