Object Database System By Sudarshan
MCA Sem V
Relational Database (RDBMS) • These system supports a small, fixed collection of data types eg. Integers, date, string • Great for administrative data • These systems offers many features like – – – –
Concurrency control Recovery Indexing support Query capabilities etc
Object Database System
• Object database system have developed along 2 paths: – Object-Oriented Database System – Object-Relational Database System
Object-Oriented Database System (OODBMS) • Object-Oriented Database System are proposed as an alternative to relational systems and are aimed at application domain where complex object play a central role. • It can be understood as an attempt to add DBMS functionality to Programming language. • The ODMG (Object Database Management Group) has developed a standard – –
Object data model (ODM) Object Query Language (OQL)
Object-Relational Database System (ORDBMS) • Object Relational Database can be thought of as an attempt to extend relational database system with the functionality necessary to support a border class of application • It provides a bridge between relational and object oriented paradigms. • The SQL:1999 standard extends SQL to incorporate support for the object relational model of data.
Example • Dinky Entertainment Company – Main Assets : Collection of cartoon character, videos, sounds. – Herbert's film Shows Worldwide – It Licenses : Herbert’s image, voice, video for various purposes • Video Games, • Product Endorsements • Action figures.
• Dinky database consist consist of sales and leasing record for various products and video and audio data to make Herbert film. • DBMS must manage assets, sales and business data
Why not RDBMS create table frames ( frameno integer, image BLOB, category integer) • Binary Large Objects (BLOB) can be stored and fetched • User-Level code must provide the logic for BLOB • Scenario: Client (Machine A) requests “thumbnail” images for all frames in DBMS (Machine B) – Insufficient, too hard to express queries.
Database support : New data types • Dinky database require the support for richer data types. • User-defined data types: – Dinky’s assets consist of image, voice and video to be recorded in database – Special function are required to manipulate these objects. • Compress image • Lower-Resolution image.
• By hiding the detail of the data structure through function that capture the behavior, Data Abstraction can be achieved.
Database support : New data types • Inheritance: – Advantage of common behavior between data types. • Both compressed image and low resolution image, are at some level, just image. Hence we can inherit some feature of image.
• Object identity: – It is important not to store copies of object but reference or pointer to object (video). – This gives rise to the need of giving object a unique object identity, which can be used to refer or point to them from elsewhere in the data.
Solution 1 - OODBMS • Idea: Take OO language and add persistence and collections. class frame { int frameno; jpeg *image; int category; } persistent set frames; foreach ( frame *f, frames) return f->image->thumbnail();
Solution 1 - OODBMS • New collection types – Type constructors: set<>, bag<>,list<> – Iterators to loop through collection type
• Gives rudimentary query language – Selection? Projection? – Can have pointers in this data model, with efficient pointer-based joins.
Solution 1 - OODBMS • Good for – Complex data – Fixed set of manipulations – Special purpose applications
• Problems – No query support – Application bugs trash persistent data – Security problem
Solution 2 - ORDBMS • Idea: Add OO features to the type system of SQL but… – – – – – –
Columns can be of new types (ADTs) User defined methods on ADTs Columns can be of complex types Reference types Inheritance and collection inheritance Old SQL schema still works (backwards compatibility)
DDL statement for Dinky’s schema (SQL:1999) CREATE TABLE Frames // images from the film (frameno integer, image jpeg_image, category integer); CREATE TABLE Categories // pricing (cid integer, name text, lease_price float, comments text); CREATE TYPE theater_t AS // theaters ROW (tno integer, name text, address text, phone text) REF IS SYSTEM GENERATED; CREATE TABLE Theaters OF theater_t REF is tid SYSTEM GENERATED; CREATE TABLE Nowshowing (film integer, theater REF(theater_t) SCOPE Theater,start date, end date); CRAETE TABLE Films // Dinky films (filmno integer ,title text, stars VARCHAR(25) ARRAY[10], director text, budget float); CREATE TABLE Countries (name text, boundary polygon, population integer, language text);
Manipulating New Data : Query • Clog cereal wants to license an image of Herbert in front of a sunrise on the box design. • A query to present a collection of images and their lease price can be expressed as SELECT F.frameno, thumbnail(F.image), C.lease_price From Frame F, Categories C Where F.category = C.cid AND is_sunrise(F.image) AND is_herbert(F.image) • The thumbnail method produce a small image. • The is_sunrise method analyzes an image and return true if image contain sunrise. • The is_Herbert method return true if image contain picture of Herbert.
Manipulating New Data : Query Find theaters showing Herbert films within 100 km of Andorra. SELECT N.theater->name,N.theater->address,F.title From Nowshowing N,Films F,Countries C WHERE N.Film = F.filmno AND overlaps(C.boundary, radius(N.theater->address, 100)) AND C.name=‘Andorra’ AND ‘HERBERT The Worm’=F.star[1] Theater attribute of nowshowing table is a reference to object in another table, which has attribute name,address. Radius:method returns a circle centered at its first argument and radius equal to second argument. Overlap:method test spatial overlap. Star attribute is a set of name of each film star.
Summarize • Traditional relational system offer limited flexibility in data types available. • Data is stored in table and type of each field value is simple atomic type like integer, string • These limited type system can be extended in three main ways: – User-defined abstract data types, – Structured types and – Reference type.
• Collectively we call all these types as complex types.
Structured data types • SQL:1999 introduced 2 type constructors that allows to define new type of internal structure,called structured type. – ROW (n1t1, . . . ,nktk): A type representing a row, or a tuple, of k field with field n1, . . . ,nk and type t1, . . . ,tk . – base ARRAY[i]: A type representing an array of i base-type item.
• Row type in SQL:1999 is quite general, its field can be of any SQL:1999 data type • Array type is restricted; elements of array cannot be array themselves
Collection Types • Other common type constructors not supported by SQL:1999 are – listof (base) – setof (base) – bagof (base)
• These are also known as collection type or bulk data types.
Operation on Structured data • Operation on row: – Given an item i whose type is a ROW (n1t1, . . . ,nntn), the field extraction method allow us to access an individual field nk using traditional dot notation i.nk – If we have a collection of rows, the dot notation gives a collection as a result. – If row construtors are nested in type definition, dots may be nested to access the fields of nested rows eg. i.nk.ml – This nested dot notation is also called path
Operation on Structured data • Operation on array: – ‘array index’ method allows us to access array item at a particular offset. – A postfix square bracket is used. – An operator (CARDINALITY) returns the number of element in array. – We can concatenate elements in the array. SELECT F.filmno, (F.stars || [‘Brando’,’Pacino’]) From Films F Where CARDINALITY(F.stars) < 3 AND F.stars[1] = ‘Redford’
Operations on other Collection types. • Sets and Multisets – Set objects can be compared using the traditional set methods like C , C , = , ∩, U, € , -. – € : ‘Herbert the Worm’ € F.stars – U : U{ {1,2,3,4},{2,3,5} } = {1,2,3,4,2,3,5} – ∩ : ∩{{1,2,3,4},{2,3,5} } = {2,3} – - : - {{1,2,3,4},{2,3,5} } = {1,4}
• Lists
Operations on other Collection types. • Lists – head: returns the first element – tail: returns the list obtained by removing the first element – prepend: takes the element and inserts it as the first element of the list – append: appends one list to another
Encapsulation and ADT’s • Allowing user to define new data type is a key feature of ORDBMS
– Frames table: image (jpeg_image) // compressed image – Countries table: boundary (polygon) //shape of country.
• DBMS allow user to store and retrieve object of type jpeg_image just as any other type like integer, float. • New defined data types usually need to have type-specific operations defined by user. – One might define operation on image data type as compress, rotate, shrink, blur.
• The combination of an atomic data type and associated method is called
Encapsulate • Database system does not know how an ADT’s data is stored nor how the ADT’s method work. • It merely knows what method are available and input and output for these method. • Hiding ADT internals is called encapsulation.
User-Defined Atomic Data Type
CREATE ABSTRACT DATA TYPE jpeg_image (internallength = VARIABLE, input = jpeg_in, output = jpeg_out ); CREATE ABSTRACT DATA TYPE polygon (internallength = VARIABLE, input = poly_in, output = poly_out);
Defining methods • To register a new method for a userdefined data type, user must write the code and the inform database system. • The code to be written depend on language supported by the DBMS. CREATE FUNCTION is_sunrise(jpeg_image) RETURNS boolean AS EXTERNAL NAME ‘a/b/c/dinky.class’ LANGUAGE ‘java’;
• Once the method is registered DBMS uses java virtual m/c to execute code. • The method define return type and location of code.
Defining methods CREATE FUNCTION thumbnail (jpeg_image) RETURNS jpeg_image AS EXTERNAL NAME ‘a/b/c/dinky.class’ LANGUAGE ‘java’; CREATE FUNCTION radius (polygon, float) RETURNS polygon AS EXTERNAL NAME ‘a/b/c/dinky.class’ LANGUAGE ‘java’; CREATE FUNCTION is_herbert(jpeg_image) RETURNS boolean AS EXTERNAL NAME ‘a/b/c/dinky.class’ LANGUAGE ‘java’; CREATE FUNCTION overlaps(polygon,polygon) RETURNS boolean AS EXTERNAL NAME ‘a/b/c/dinky.class’ LANGUAGE ‘java’;
Inheritance • In Object-database inheritance allow type definition to be reused and refined easily. • Inheritance is useful in modeling similar but not identical object. • Defining Types with inheritance:we model theater with theater_t suppose we want to add new marketing technique in theater business theater_café,which server pizza and other meal while screening movies. • Theater café is just like theater with additional attribute theater’s menu
Inheritance CREATE TYPE theatercafe_t UNDER theater-t (menu text); • Theatercafe_t inherits all attribute and method of theater_t plus additional attribute menu of type txt. • There is an explicit relation between object of subtype(theatercafé_t )and super type(theater_t) • An object of the subtype is also considered to be object of super type.(operation on super type apply to the subtype.
The substitution principal • Given a super type A and a sub type B,it is always possible to substitute an object of type B into a legal expression written for object A,without producing any error. • The principal enable easy code reuse because query and method written for super type can be applied to sub type.
Binding methods • It is useful to replace method for super type with a new version that operates differently for sub type. • Consider image_t type and jpeg_image_t • Display() for jpeg images and register it with the data base. CREATE FUNCTION display(jpeg_image) RETURNS jpeg_image AS EXTERNAL NAME ‘a/b/dinky.class LANGUAGE ‘java’; • Registering a new method with same name is call overloading the method.
Binding • We must understand which method is intended in a particular expression • Object type jpeg_image specialized display • Object type image_t standard display • The process of deciding which method to invoke is called as BINDING. • Early binding and Late binding
Collection hierarchies • In dinky schema we have theater, theatercafe_t we would create another table theater cafes to store information about theater café . • Instance of theater café table is an instance of theater table also. • Create table theater_cafes of type theatercafe_t under theater. • This statement tells the system that queries over theater table should actually be run over all tuples in both theater and theater cafes table.,rather than separate query for each tuple.
Collection Hierarchies • In general,the under clause can be used to generate an arbitrary tree of tables called collection hierarchy. • Query over a particular table T in the hierarchy are run over all tuples in T and its descendants. • To restrict query to run only on T use keyword ONLY in from clause. • If subtype have overloading,late binding it ensure that appropriate method get called.