370 likes | 481 Views
ORDBMS is an advanced database system.<br>in these PPTs, all concepts are included.
E N D
Object Based Databases Overview, Complex data types, Structured types inheritance in SQL,Table inheritance , Array and Multiset types in SQL, Object identity and reference types in SQL , Persistent programming languages , Object oriented versus Object relational Database design for ORDBMS New Challenges in implementing ORDBMS: Storage & access methods, Query processing and Optimization
Motivation • Relational model: • Clean and simple • Great for much enterprise data • But lot of applications where not sufficiently rich • Multimedia, CAD, for storing set data etc • Object-oriented models in programming languages • Complicated, but very useful • Smalltalk, C++, now Java • Allow • Complex data types • Inheritance • Encapsulation • People wanted to manage objects in databases.
Histroy In the 1980s and 90s, DB researchers recognized benefits of objects. Two research thrusts: OODBMS: extend C++ with transactionally persistent objects Niche Market CAD etc ORDBMS: extend Relational DBs with object features Much more common Efficiency + Extensibility SQL:99 support" Postgres – First ORDBMS Berkeley research project Became Illustra, became Informix, bought by IBM
Why ORDBMS – Extending RDBMS Vendors of RDBMSs conscious of threat and promise of OODBMS. Agree that RDBMSs not currently suited to advanced database applications, and added functionality is required. Reject claim that extended RDBMSs will not provide sufficient functionality or will be too slow to cope adequately with new complexity. Can remedy shortcomings of relational model by extending model with OO feature
What is ORDBMS? ORDBMS is a relational database with OO features. OO features being added include: User-extensible types. Encapsulation. Inheritance. Polymorphism. Dynamic binding of methods. Complex objects. Object identity.
Stonebraker’s View Stonebraker’s View Developed by well-respected database pioneer Dr. Michael Stonebraker.
Complex Types and SQL Extensions introduced in SQL:1999 to support complex types: Collection and large object types Nested relations are an example of collection types Structured types Nested record structures like composite attributes Inheritance Object orientation Including object identifiers and references Not fully implemented in any database system currently But some features are present in each of the major commercial database systems Read the manual of your database system to see what it supports
Structured types Structured types ( user-defined types) can be declared and used in SQL create type Name as object(firstname varchar(20), lastname varchar(20)) final create type Address as object (street varchar(20), city varchar(20), zipcode varchar(20)) not final Note: final and not final indicate whether subtypes can be created Structured types can be used to create tables with composite attributes" create table person (name Name,address Address,dateOfBirth date) Dot notation used to reference components: name.firstname
Structured types Contd... User-defined row types create type Person110 as object (name varchar(20), address varchar(20)) not final Type created. desc person110; person110 is NOT FINAL Name Null? Type ----------------------------- -------- -------------------- NAME VARCHAR2(20) ADDRESS VARCHAR2(20) Can then create a table whose rows are a user-defined type create table people1 of person_type Table created. Alternative using unnamed row types."
OO Concepts- Inheritance Subclasses: A class of objects that is defined as a special case of a more general class (the process of forming subclasses is called specialization). Superclass: A class of objects that is defined as a general ase of a number of special classes (the process of forming a superclass is called generalization). All instances of a subclass are also instances of its superclass. Inheritance: By default, a subclass inherits all the properties of its superclass (or it can redefine some (or all) of the inherited methods). Additionally, it may define its own unique properties
OO Concepts- Inheritance 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 the Superclasses have the same attributes and/or methods). Due to its complexity, not all OO languages and database systems support this concept. Repeated inheritance: A special case of multiple inheritance where the multiple Superclasses inherit from a common superclass (note: must ensure that subclasses do not inherit properties multiple times).
Type Inheritance • Suppose that we have the following type definition for people:" • create type Person110 as object (name varchar(20), address varchar(20)) not final • Type created. • Using inheritance to define the student and teacher types • create type Student_type under Person110 (degree varchar(20), department varchar(20)) • Type created. • Subtypes can redefine methods by using overriding method in place of method in the method declaration
Oracle Type Inheritance Supertype/Subtype Subtype is derived from a parent object type, Supertype. Subtype inherits all attributes and methods from its supertype
Oracle Type Inheritance create table people of person_type; Table created. SQL> desc people; Name Null? Type ----------------------------- -------- -------------------- NAME VARCHAR2(20) ADDRESS VARCHAR2(20) create table people of person_type; Table created. SQL> desc people; Name Null? Type ----------------------------- -------- -------------------- NAME VARCHAR2(20) ADDRESS VARCHAR2(20)
Insertion insert into people values('dhana','chembur') 1 row created. insert into people values(person_type('dhana','chembur')) 1 row created. SQL> select * from people; NAME ADDRESS -------------------- -------------------- dhana chembur dhana chembur
Oracle Type Inheritance CREATE OR REPLACE TYPE person_type AS OBJECT (ssn NUMBER,name VARCHAR2(30),address VARCHAR2(20)) 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 );
Overloading/Overriding methods CREATE TYPE Shape_typ AS OBJECT (..., MEMBER PROCEDURE Enlarge(x NUMBER), ...) NOT FINAL; / CREATE TYPE Circle_typ UNDER Shape_typ (..., MEMBER PROCEDURE Enlarge(x CHAR(1))); / --Define the inherited method Enlarge() to deal with different types of --input parameters.
Overloading/Overriding methods CREATE TYPE Shape_typ AS OBJECT (..., MEMBER PROCEDURE Area(), FINAL MEMBER FUNCTION id(x NUMBER)... ) NOT FINAL; / CREATE TYPE Circle_typ UNDER Shape_typ (..., OVERRIDING MEMBER PROCEDURE Area(), ...); / --Redefine an inherited method Area() to make it do something different --in the subtype.
Collection Types ARRAY: ordered 1D array with maximum number of elements without duplicates. LIST:ordered collection that allows duplicates. SET: unordered collection without duplicates. MULTISET: unordered collection that allows duplicates. Similar to those in OODBMS
Oracle Collections Set of data elements VArray - ordered set of data elements. CREATE TYPE phones AS VARRAY(3) of VARCHAR2(20); --Each element has an index, corresponding to its position in --the array Nested Table - unordered set of data elements CREATE TYPE people_type AS TABLE OF person_type; --Declare the table type used for a nested table. CREATE TABLE contacts (contact people_type,c_date DATE ) NESTED TABLE contact STORE AS people_table; --Declare a nested table
Object Types and References REF Datatype REF is a logical "pointer" to a row object. For an object type t, REF t is the reference to the values of type t. SELECT c.contact.name, c.c_date FROM contacts c; --using dot notation to follow the reference.
Methods Definition Functions/procedures declared in the object type definition to implement 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 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++
Member Method Member methods are used to access an object instance values. CREATE OR REPLACE TYPE BODY person_type AS MEMBER FUNCTION get_areacode RETURN VARCHAR2 IS BEGIN RETURN SUBSTR(phone, 1, 3); END get_areacode; END; Define the body of the method using CREATE OR REPLACE TYPE BODY. SELECT c.contact.get_areacode() FROM contacts c; -- Invoke a member method C.CONTACT.GET_AREACODE()
Constructor Method Every object type has a constructor method implicitly defined by system. Returns a new instance of the user-defined object type and sets up the values of its attributes. The name of constructor method is the same as the name of the object type. p = person_type(‘Scott Tiger’, ‘321-123-1234’); --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’, ‘321-123-1234’), ’10 Feb 2004’)); --Same thing occurs here.
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_table VALUES (person_type (‘Scott Tiger’, ‘321-123-1234’)); SELECT VALUE(p) FROM person_table p WHERE p.name = ‘Scott Tiger’; -- Single-column table: each row is a person_type object -- Perform object-oriented operations
Methods to Compare Objects Define a special kind of member methods to compare objects. Define either a map method or an order method in an object type. Map Method:Map object instances into one of the scalar types DATE, CHAR, NUMBER,.. CREATE TYPE circle_type AS OBJECT (x NUMBER, y NUMBER,r NUMBER,MAP MEMBER FUNCTION get_area RETURN NUMBER ); / CREATE TYPE BODY circle_type AS MAP MEMBER FUNCTION get_area RETURN NUMBER IS BEGIN RETURN 3.14 * r * r; END get_area; END;
Array and multiset Types inSQL • Example of array and multiset declaration:" • create type Publisher as object (name varchar(20), branch varchar(20)); • create type Book as (title varchar(20), author_array varchar(20) array [10], pub_date date, publisher Publisher, keyword-set varchar(20) multiset); • create table books of Book;
creation of collection values • Array construction • array [ʻSilberschatzʼ,`Korthʼ,`Sudarshanʼ] • Multisets" • multiset [ʻcomputerʼ, ʻdatabaseʼ, ʻSQLʼ] • To create a tuple of the type defined by the books relation: • "(ʻCompilersʼ, array[`Smithʼ,`Jonesʼ], new Publisher (`McGraw-Hillʼ,`New Yorkʼ), multiset [`parsingʼ,`analysisʼ ]) • To insert the preceding tuple into the relation books" • insert into books values (ʻCompilersʼ, array[`Smithʼ,`Jonesʼ],new Publisher (`McGraw-Hillʼ,`New Yorkʼ),multiset [`parsingʼ,`analysisʼ ]);
Querying creation of collection values To find all books that have the word “database” as a keyword, select title !from books where ʻdatabaseʼ in (unnest(keyword-set )) We can access individual elements of an array by using indices E.g.: If we know that a particular book has three authors, we could write: select author_array[1], author_array[2], author_array[3] from books where title = `Database System Conceptsʼ To get a relation containing pairs of the form “title, author_name for each book and each author of the book select B.title, A.author from books as B, unnest (B.author_array) as A (author ) To retain ordering information we add a with ordinality clause select B.title, A.author, A.position! ! !from books as B, unnest (B.author_array) with rdinality as A (author, position )
Path Expression • Find the names and addresses of the heads of all departments: • select head –>name, head –>address from departments • An expression such as “head–>name” is called a path expression! • Path expressions help avoid explicit joins • If department head were not a reference, a join of departments with people would be required to get at the address • Makes expressing the query much easier for the user
An Alternative :OODBMS • Persistent OO programming • Imagine declaring a Java object to be Persistent • Everything reachable from that object will also be persistent • You then write plain old Java code, and all changes to the persistent objects are stored in a database • When you run the program again, those persistent objects have the same values they used to have • Solves the impedance mismatch between programming languages and query languages • E.g. converting between Java and SQL types, handling rowsets, etc. • But this programming style does not support declarative queries • For this reason (??), OODBMShaven't proven popular" • OQL: A declarative language for OODBMS • Was only implemented by one vendor in France (Altair)
OODBMS Currently a Niche Market Engineering, spatial databases, physics etc… Main issues: Navigational access Programs specify go to this object, follow this pointer Not declarative Though advantageous when you know exactly what you want, not a good idea in general Kinda similar argument as network databases vs relational databases
Comparison of OO and ORDBMS • Relational systems • simple data types, powerful query languages, high protection. • Persistent-programming-language-based OODBs • complex data types, integration with programming language, high • performance. • Object-relational systems • complex data types, powerful query languages, high protection. • Object-relational mapping systems • complex data types integrated with programming language, but built as a layer on top of a relational database system • Note: Many real systems blur these boundaries • E.g. persistent programming language built as a wrapper on a relational database offers first two benefits, but may have poor performance
Advantages of ORDBMS ORDBMS offers many new features but not clear how to use them schema design techniques not well understood No good logical design theory for non-1st-normal-form query processing techniques still in research phase a moving target for OR DBAs OODBMS Has its advantages Niche market Lot of similarities to XML as well…
Advantages of ORDBMS Resolves many of known weaknesses of RDBMS. Reuse and sharing: reuse comes from ability to extend server to perform standard functionality centrally; Preserves significant body of knowledge and experience gone into developing relational applications.
Thank You ??? Kingsoft Office