Docsity

Object-Relational Features in Oracle Database | CSCI 585, Papers of Deductive Database Systems

Partial preview of the text

Download Object-Relational Features in Oracle Database | CSCI 585 and more Papers Deductive Database Systems in PDF only on Docsity!

Object-Relational Features in

Oracle Database

Cyrus Shahabi

Computer Science DepartmentUniversity of Southern California

[email protected]

Oracle Database

„^ History of Oracle database^ ‹^

In 1979, Oracle Version 2 introduced^ )^ An early commercial relational database system.… ‹ In 1997, Oracle version 8 released^ )^ Support for object-oriented development and multimedia applications.^ )^ Object-Relational DBMS ‹ In 1999, Oracle 8

i^ released

)^ Tuned with the needs of the Internet/Web ‹ In 2001, Oracle 9

i^ released

)^ Include the facility to read and write XML documents ‹ In 2003, Oracle 10g released )^ Support for Grid Computing

Object-Oriented Concepts

„^ Abstraction and Encapsulation

(Provided by Abstract Data Types

(ADT))^ ‹^ Abstraction

is the process of identifying the essential aspects of an entity
and ignoring the unimportant properties. Focus on what an object is andwhat it does, rather than how it should be implemented. ‹ Encapsulation
(or information hiding) provides data independence by
separating the external aspects of an object from its internal details, whichis hidden from the outside world.

„^ Objects^ ‹^

Object^
is a uniquely identifiable entity that contains both the attributes that
describe the state of a real-world object and the actions that conceptualizethe behavior of a real-world object. The difference between object andentity is that object encapsulates both state and behavior while entity onlymodels state. ‹ Attributes
(or instance variables) describe the current state of an object
(the notation for attribute: object-name.attribute-name).

Object-Oriented Concepts

‹^ Methods:
define the behavior of the object. They can be used to change
the object’s state by modifying its attribute values, or to query the value ofthe selected attributes. A method consists of a name and a body thatperforms the behavior associated with the method name (notation: object-name.method-name).

„^ Classes:

A group of objects with the same attributes and methods.

Hence, the attributes and the associated methods are defined once forthe class rather than separately for each object. „ The^ instances

of a class are those objects belonging to a class.

Attributes

Oracle Objects

„^ Definition^ ‹^

Actual instance of the defined object type, ‹ Storages are allocated to an object and values are assigned to theattributes of an object CREATE^ TABLE

contacts

contact

person_type, c_date^

DATE^ );

--^ object

type^ can

be^ used

like^ any

other^

built-in

data^ types.

INSERT^

INTO^ contacts

VALUES

person_type(‘Tommy

Trojan’,

--^ instance

’24^ Jan

--^ person_type

is^ instantiated

and^ values

are^ assigned

to

--^ the^

attributes

of^ the

object

instance.

Oracle Methods

„^ Definition^ ‹^

Functions/procedures declared in the object type definition toimplement behavior of the object of that type. ‹ Written in PL/SQL or virtually any other languages (Java, C…)

„^ Method types^ ‹^

Member method^ )^ Defined on object instance’s data. ‹ Static method^ )^ Invoked on the object type, not its instances.^ )^ Can be used to the operations that are global to the type (e.g. initialization) ‹ Constructor method^ )^ Built-in constructor function, like in C++.

Constructor Method

„^ Every object type has a constructor method implicitly defined bysystem. „^ Returns a new instance of the user-defined object type and sets up thevalues of its attributes. „^ The name of constructor method is the same as the name of the objecttype.^ p^ =^

person_type(‘Scott

Tiger’,

--Built-in

constructor

method,

person_type(att1,

att2)^

is^ invoked

--to^ create

a^ new^

object^

instance

of^ person_type,

specify

values

--for^ its

attributes(name,

phone),

and^ set

the^ object

into^ a

--variable

p. INSERT^

INTO^ contacts VALUES^

(person_type(‘Scott

Tiger’,

’10^ Feb

--Same^

thing^ occurs

here.

Oracle Object Tables

„^ Object Table: special type of table, each row represents an object

CREATE^

TYPE^ person_type

AS^ OBJECT

name^

VARCHAR2(30),

phone^

VARCHAR2(20)
/ CREATE
TABLE^

person_table

OF^ person_type;

INSERT INTO person_tableVALUES (person_type (‘Scott

Tiger’, ‘321-123-1234’));

SELECT VALUE(p) FROM person_table p WHERE p.name is ‘Scott Tiger’;-- Single-column table: each row is a person_type object-- Perform

object-oriented operations

„^ Comparing to a relational table

CREATE TABLE person_table

(

name^

VARCHAR2(30),

phone^

VARCHAR2(20)

INSERT INTO person_tableVALUES (‘Tommy Trojan’, ‘213-740-1212’);SELECT name, phone

FROM person_table; -- Multi-column table: treat person_table as a relational table

Methods to Compare Objects (2) ‹ Order Method^ )^ Provides direct object-to-object comparison, telling that the current object is less than, equalto, or greater than the other object. CREATE^ TYPE^ circle_type

AS^ OBJECT

(

x^

NUMBER, y^

NUMBER, r^

NUMBER, ORDER MEMBER FUNCTION match(c

circle_type) RETURN INTEGER );

/

CREATE OR REPLACE TYPE

BODY circle_type

AS

ORDER MEMBER FUNCTION match (c circle_type) RETURN INTEGER ISBEGINIF r < c.r THEN

-- 3.14*r

2 <^ 3.14*c.r

2

RETURN –1;

-- any negative number ELSIF r > c.r THENRETURN 1;

-- any positive number ELSERETURN 0;END IF;END;END; -- returns only one integer value among positive, 0, and negative.

Methods to Compare Objects (3) CREATE TABLE circles OF circle_type;INSERT INTO circles VALUES (circle_type(10, 10, 3));INSERT INTO circles VALUES (circle_type(40, 20, 8));INSERT INTO circles VALUES (circle_type(10, 50, 4));SELECT c.x, c.yFROM circles cWHERE VALUE(c) < (circle_type(40, 25, 5)) ; CIRCLES.X

CIRCLES.Y
„^ C. Shahabi

Single inheritance:

When a subclass inherits

from no more than one superclass (note: forming class hierarchies

is permissible here).

„^ Multiple inheritance:

When a subclass inherits

from more than one superclass (note: amechanism is required to resolve conflicts whenthe Superclasses have the same attributes and/ormethods). Due to its complexity, not all OOlanguages and database systems support thisconcept. „ Repeated inheritance:

A special case of multiple

inheritance where the multiple Superclassesinherit from a common superclass (note: mustensure that subclasses do not inherit propertiesmultiple times).

OO Concepts - Inheritance

OO Concepts - Inheritance

„^ Overriding

:^ To redefine an inherited property by defining

the same property differently at the subclass level. „ Overloading:

A general case of overriding where the same

method name is reused within a class definition (overriding)or across class definitions. Hence, a single message canperform different functions depending on which objectreceiving it and, if appropriate what parameters are passedto the method (e.g.,

print^

method for different objects).

„^ Polymorphism:

“Having many forms” in Greek, is a

general case of overloading.^ ‹^ Inclusion polymorphism:

Same as overriding.

‹^ Operation (or ad hoc) polymorphism:

Same as overloading.

‹^ Parametric polymorphism (or Genericity):

It uses types as

parameters in generic type (or class) definition.

Oracle Type Inheritance (2)

CREATE^
OR^ REPLACE

TYPE^ person_type

AS^ OBJECT

ssn^

NUMBER,

name^

VARCHAR2(30),

address

VARCHAR2(100))
NOT^ FINAL;

--To^ permit

subtype,

object

type^ should

be^ defined

as^ NOT

FINAL.

--By^ default,

an^ object

type^ is

FINAL
CREATE^

TYPE^ student_type

UNDER^

person_type

deptid^

NUMBER,

major^

VARCHAR2(30))
NOT^ FINAL;
CREATE^

TYPE^ employee_type UNDER

person_type

empid^

NUMBER,

mgr^

VARCHAR2(30));
CREATE^

TYPE^ part_time_student_type

UNDER^

student_type

numhours

NUMBER
);^ /

Oracle Type Inheritance (2.5!)

CREATE

TABLE

persons

OF^ person_type;

INSERT

INTO

persons

VALUES

(student_type(123,

'PHE-306',

1,^ 'cs'));

INSERT

INTO

persons

VALUES

(employee_type(789,

'PHE-314',

'Cyrus'));

SELECT

*^ FROM

persons;

SELECT

VALUE(p)

FROM

persons

p^ WHERE

VALUE(p)

IS^ OF

(employee_type);SELECT^ TREAT(VALUE(p)

AS^ student_type).major

FROM

persons

p^ WHERE

VALUE(p)

IS^ OF

(student_type);