Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oracle Objects Object Oriented Database Approach.

Similar presentations


Presentation on theme: "Oracle Objects Object Oriented Database Approach."— Presentation transcript:

1 Oracle Objects Object Oriented Database Approach

2 Overview n Oracle supported concepts - features are implemented as extensions on relational engine n Defining Oracle objects n Using Oracle objects n Object views

3 Oracle Supported OO Concepts n An object has a name, a standard representation, and a standard collection of operations that affect it (methods) n Abstract data types model classes of data within the database n Abstract data types inherit the representation of their parents u hierarchies of abstract data types u implementation inheritance - inherit behavior of parents

4 Oracle Supported OO Concepts con’t n Approximate encapsulation u encapsulation - data structure can only be accessed via a defined set of methods u relational system cannot have means of accessing data limited n No polymorphism u ability of same instruction to be interpreted different ways by different objects

5 Abstract Data types n Data types that consist of one or more subtypes n Can be nested n Can reference other abstract datatypes n Example CREATE TYPE ADDR_TY AS OBJECT (STREETVARCHAR2(50), CITYVARCHAR2(25), STATECHAR(2), ZIPVARCHAR(9)) /

6 Embedded Objects - Collectors n Nested table - u table within a table u collection of rows represented as a column within main table u stores 1:M relationships n Varying arrays u set of objects each with the same data type u nested table with a limited set of rows (size limited when created) u Store repeating attributes in table n Cannot be indexed

7 Large Objects - LOB n BLOB - binary data that can be extended to 4 GB n CLOB - character data up to 4 GB n NCLOB - stores CLOB data for multibyte character sets Stored inside database, can be single row n BFILE - pointer to external file. File exists on OS

8 Example of Simple Object CREATE TYPE PERSON_TY AS OBJECT (NAME VARCHAR2(25), ADDRESSADDR_TY) / Note: data described not stored, cannot store data in types CREATE TABLE STUDENT (STUDENT_IDVARCHAR2(9), PERSONPERSON_TY) / Must own data type or be granted access. Need execute access for methods including constructor methods. Avoid synonyms

9 Inserting Records n Constructor methods - program named after the data type, parameters names of attributes defined for datatype n insert into student values (100, person_ty(‘Mary Ann Robbert’, addr_ty(‘122 North St.’, ’Watham’,’MA’, ‘02579’))) constructor methods

10 Querying n Select student_id, person.name... u COLUMN.ATTRIBUTE n Select person.addr.street … u COLUMN.COLUMN.ATTRIBUTE n SELECT STUDENT_ID, S.PERSON.NAME, S.PERSON.ADDRESS.STATE S.PERSON.NAME, S.PERSON.ADDRESS.STATE FROM STUDENT S FROM STUDENT S

11 Object Views n Bridge between relational and object n Allows adding OO concepts on top of relational tables n Gives benefit of relational storage with OO structures n Benefits u create abstract data types within tables that already exist u flexibility to treat base table as relational table or object table

12 Creating Object View based on Existing Table n Assume person, and address types plus a relational student table CREATE VIEW STUDENT_OV (STUDENT_ID, PERSON) AS SELECT STUDENT_ID, PERSON_TY(NAME, ADDR_TY(STREET,CITY,STATE,ZIP)) FROM STUDENT

13 Updating Through Object View n Instead of Triggers u use on object views or relational views u change values through views n Use with PL/SQL code u create trigger xyz instead of update on view for each row ….

14 Methods CREATE TYPE PERSON_TY3 AS OBJECT CREATE TYPE PERSON_TY3 AS OBJECT (NAME VARCHAR2(25), (NAME VARCHAR2(25), ADDRESS ADDR_TY, ADDRESS ADDR_TY, BIRTHDATE DATE, BIRTHDATE DATE, MEMBER FUNCTION AGE(BIRTHDATE IN DATE) RETURN NUMBER) MEMBER FUNCTION AGE(BIRTHDATE IN DATE) RETURN NUMBER)

15 Methods n CREATE TYPE PERSON_TY4 AS OBJECT (NAME VARCHAR2(25), ADDRESS ADDR_TY, ADDRESS ADDR_TY, BIRTHDATE DATE, BIRTHDATE DATE, MEMBER FUNCTION AGE(BIRTHDATE IN DATE) RETURN NUMBER, MEMBER FUNCTION AGE(BIRTHDATE IN DATE) RETURN NUMBER, PRAGMA RESTRICT_REFERENCES(AGE,WNDS)) PRAGMA RESTRICT_REFERENCES(AGE,WNDS)) WNDS – Write No Database State RNDS - Read (no queries) WNPS – No packaged variables changed RNPS – no packg var referenced

16 Methods n create or replace type body person_ty4 as member function AGE(birthdate date) return number is BEGIN RETURN ROUND(SYSDATE - BIRTHDATE); END;END

17 Example n CREATE TABLE STUDENT4 (SIDNUMBER, PERSON PERSON_TY4); n SELECT S.AGE(STUDENT4.BIRTHDATE) FROM STUDENT4 S S.AGE(STUDENT4.BIRTHDATE) FROM STUDENT4 S

18 Managing Methods n Cannot drop or recreate type that is in use by a table n Use ALTER TYPE to add new methods n Grant execute on type gives priviledges to methods

19 OO ANALYSIS AND DESIGN n Goes beyond normalization (relating each attribute to primary key), seeks groups of columns that define a common object representation n Uses types that are: u reused u will always behave in the same manner


Download ppt "Oracle Objects Object Oriented Database Approach."

Similar presentations


Ads by Google