Agenda  TMA03  M877 Block 3 Databases with Objects.

Slides:



Advertisements
Similar presentations
Oracle Object-Relational Model. - Structures : tables, views, indexes, etc. - Operations : actions that manipulate data stored in structures - Integrity.
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Why Object-Oriented DBMS? Abstract data types Interface with host programming language (the impedance mismatch). Object identity: (peter, 40, {(john, 15,
Jane Reid, BSc/IT DB, QMUL, 25/2/02 1 Object-oriented DBMS Background to ODBMS ODBMS requirements Object components ODB conceptual design –Graphical ODB.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Object Databases Baochuan Lu. outline Concepts for Object Databases Object Database Standards, Languages, and Design Object-Relational and Extended-Relational.
ODMG Standard: Object Model1 OBJECT-ORIENTED DATABASE SYSTEMS ODMG Standard: Object Model Susan D. Urban and Suzanne W. Dietrich Department of Computer.
Object-Oriented Databases v OO systems associated with – graphical user interface (GUI) – powerful modeling techniques – advanced data management capabilities.
Chapter Object-Oriented Practices. Agenda Object-Oriented Concepts Terminology Object-Oriented Modeling Tips Object-Oriented Data Models and DBMSs.
©Silberschatz, Korth and Sudarshan8.1Database System Concepts Chapter 8: Object-Oriented Databases Need for Complex Data Types The Object-Oriented Data.
Chapter 9: Object-Relational Databases
Object-Oriented Databases
Fundamentals, Design, and Implementation, 9/e Chapter 16 Object-Oriented Database Processing.
Object Oriented Databases - Overview
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object and Object- Relational Databases.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 18 Object Database Management Systems.
1 Announcements Research Paper due Monday November 22.
Databases Illuminated Chapter 7 The Object-Oriented Model.
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
Chapter 4 Object and Object-Relational Databases (Part ½: Object-Oriented Concepts) Lecturer: H.Ben Othmen Department of Computer Science, Umm Al-Qura.
EER vs. UML Terminology EER Diagram Entity Type Entity Attribute
Object and object-relational databases 1. Object databases vs. Object-relational databases Object databases Stores complex objects – Data + functions.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Practical Object-Oriented Design with UML 2e Slide 1/1 ©The McGraw-Hill Companies, 2004 PRACTICAL OBJECT-ORIENTED DESIGN WITH UML 2e Chapter 2: Modelling.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
Chapter 4 The Relational Model.
Object Query Language (OQL) and Language Binding
DBMS Lecture 9  Object Database Management Group –12 Rules for an OODBMS –Components of the ODMG standard  OODBMS Object Model Schema  OO Data Model.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Lecture 17 Object relational databases. 2 Example Table Creation based on UDT CREATE TABLE Person ( info PersonType, CONSTRAINT DOB_Check CHECK(dateOfBirth.
Object-Oriented Database Management Systems (ODBMS)
1 Advanced Databases (CM036): Lecture # 5 ( Object-Relational and Nested-Relational Databases) Introduction to Object-Relational features of Oracle 9i.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
ADVANCED DATABASE SYSTEMS DR. FATEMEH AHMADI- ABKENARI SEPTEMBER Object Databases.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1 Chapter 1 Introduction. 2 Introduction n Definition A database management system (DBMS) is a general-purpose software system that facilitates the process.
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
Relational Database. Database Management System (DBMS)
1 Advanced Databases (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Chapter 2 Object-Relational DBMSs Chapter 28 in Textbook.
Object Relational Features
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
11-1 CHAPTER 11 Concepts for Object-Oriented Databases.
Object Oriented Programming
© D. Wong Security and User Authorization in SQL 8.7 pp. 410  Authorization ID = user name  Special authorization ID: PUBLIC  Privileges for:
Object-Relational Model. Review: Data Models Hierarchical Network ER (Pure) Relational (Pure) Object-oriented (ODMG) Object-relational (since SQL:1999)
AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.
Lecture 16 Object relational databases. 2 Objectives How relational model has been extended to support advanced database applications. Features proposed.
The ODMG Standard for Object Databases
Object storage and object interoperability
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
More SQL: Complex Queries,
Chapter 4: Logical Database Design and the Relational Model
Object-Oriented Database Management System (ODBMS)
Object-Relational DBMSs
Chapter 12 Outline Overview of Object Database Concepts
Lec 3: Object-Oriented Data Modeling
Data Model.
Object Databases: Logical Data Modeling
ITEC 3220A Using and Designing Database Systems
Object – relational database
Presentation transcript:

Agenda  TMA03  M877 Block 3 Databases with Objects

Object-Oriented Technology

Objects  An object has state and behaviour.  The state of an object is given by its instance variables.  The behaviour of an object is given by its methods.  Each object has an unique identifier - OID.

Classes  Each object is an instance of a class.  Objects which are instances of the same class have the same instance variables and methods. class Salaried_employee instance variables staff_no string name string address Address department Department annual_salary Payment deduction_rates Deduction_rates cumulative_totals Cumulative_totals methods monthly_payment() "Answer the monthly payment due the employee using annual_salary and deduction_rates of receiver. Update cumulative_totals of receiver." Method heading

Instance Variables  Instance variables are references to objects. For example,  Object referenced by an instance variable has a class. For example,  staff_no references object that is an instance of the class string. name := 'Patricia Pantani'

Object Identifier - OIDs

Relationships  In object-oriented language, relationship (association) between classes are represented via instance variables. Department Salaried Employee DepartmentHeadDepartmentMembers Merit Salaried Employee

Department Class class Department instance variables department_name string department_head Salaried_employee department_members set (Salaried_employee) methods transfer_to(aSalaried_employee, aDepartment) "If aSalaried_employee is department_head of the receiver then answer false; else if aSalaried_employee is an element in department_members of the receiver then delete aSalaried_employee from department_members of the receiver and insert aSalaried_employee as an element in department_members in aDepartment, set department in aSalaried_employee to reference aDepartment and answer true; else answer false."

1:1 and 1:N Relationships  1:1 Relationship - DepartmentHead Define department_head instance variable in Department instances.  1:N Relationship - DepartmentMembers From :N side to :1 side,  Define the department instance variable in Salaried_employee instanaces From :1 side to :N side,  Define the department_members instance variable in Department instances

Messages  Objects communicate with each others via message and message answer. A message is a request to a receiver (an object) for some behaviour (method) A message answer is the requested behaviour sent back to the originated object.  Instance variable has a pair of assessor methods Get method : department_name() Set method : department_name(aString)

Encapsulation  Instance variables (state) and methods (behaviour) of an object instance are encapsulated and hidden from any other object instances.  Encapsulation separates the external behaviour (messages) from the details of implementation (instance variables and methods).  Public methods can be invoked via messages from other objects, but NOT for private methods.

Subclasses and Inheritance  A subclass inherits all instance variables and methods of the superclass.  Additional instance variables and methods can be defined for the subclasses.  Methods defined in the superclass will be overridden if the methods are re-defined in the subclass. class Meritorious_Salaried_employee as subclass of Salaried_employee instance variables merit_award Payment methods monthly_payment() "Answer the monthly payment of the employee using annual_salary, deduction_rates and merit_award of the receiver. Update cumulative_totals of receiver."

Polymorphism  An instance of a subclass is also an instance of its superclass.  Overriding polymorphism:-  The version of a method to be used is determined by the class of the object receiving the message – if the method exists in the most specific class, then it is used, else the superclass is searched for the method, and so on until the method is found.

Object-Oriented Database Technology

Schema  An object-oriented DBMS manages a stored collection of objects.  Each object has a unique OID.  A schema in object-oriented DBMS gives a logical definition of the stored data.  A schema contains NO implementation details.  Classes have attributes and operations.  In terms of the ODMG (Object Data Management Group), a schema is specified using the Object Definition Language (ODL).  A class definition consists of properties (attributes followed by relationships) and operations. Optionally it may include an extent and keys.

Extent, Keys & Relationships  An extent is a object reference to the set containing all instances of the class in the database. e.g. Salaried_employees is a reference to all instances of the class Salaried_employee  Keys are uniqueness constraints that are enforced by the DBMS for all instances of the class.  Relationship :- Defined by a pair of named traversal paths that allow user processes to navigate between objects in the relationship: DBMS maintains the consistency of traversal paths and their inverses and provides public operations that permit the insertion and deletion of member instances and the navigation between instances

Schema Class Definition: Salaried Employees class Salaried_employee ( extent salaried_employees keys staff_no, (name, address)) { attribute string staff_no; attribute string name; attribute Address address; attribute Payment annual_salary; attribute Deduction_rates deduction_rates; attribute Cumulative_totals cumulative totals; relationship Department is_member_of inverse Department::has_members; relationship Department is_head_of inverse Department::head_is; Payment monthly_payment() "Answer the monthly payment due to the employee using annual_salary and deduction_rates of receiver. Update cumulative_totals of receiver."; };

Schema Class Definitions: Departments class Department ( extent departments) { attribute string department_name; relationship Salaried_employee head_is; inverse Salaried_employee::is_head_of relationship set has_members inverse Salaried_employee::is_member_of; Boolean transfer_to(in Salaried_employee transfer_employee, in Department to_department) "If transfer_employee is head_is of the receiver then answer false; else if transfer_employee is in has_members of the receiver then delete transfer_employee from has_members of the receiver and insert transfer_employee into has_members of to_department, and answer true; else answer false." };

Operations  Behaviour of a schema classs is specified as a set of operation signatures (type of value returned, name of operation and type & name of each argument).  Operations merely consist of an operation signature without codes. The language binding will represent operations by methods which have appropriate codes in the corresponding object-oriented programming language.

Constraints and Inheritance  Apart from uniqueness constraints, other constraints (such as participation conditions) need to be represented via operations.  Extends mechanism is used for a class to inherit both behaviour and state from another class. class Meritorious_Salaried_employee extends Salaried_employee ( extent merits) { attribute Payment merit_award; Payment monthly_payment() "Answer the monthly payment of the employee using annual_salary, deduction_rates and merit_award of the receiver. Update cumulative_totals of receiver."; };

Data Manipulation  OQL (Object Query Language): It is not computationally complete but is easy to use (and has strong similarities with SQL). It does not provide explicit update operators.  OML (Object Manipulation Language) It is defined for each object-oriented programming language for which a language binding has been given by the ODMG 3.0 specification. It extends the programming language so that it can retrieve and modify objects from database.

Why Objects and Databases?

Perceived Problems of Relational Database Technology  Lack of support of new data type. E.g. audio, image and video  Separation of data and process.  Structural limitations Each value represented in a relation is atomic – the value is always one value and never a group of values.  Impedance mismatch SQL manipulates collections of occurrences (tables made up of rows) whereas host language manipulates individual occurrences (individual rows).

Why Object-Oriented Database?  Attractive characteristics of object-oriented technology: Components-based development  Complex objects are built from simple objects.  Reuse code. Encapsulation – data semantics A computationally complete DML  Avoid impedance mismatch between SQL and host language. Subclasses and inheritance Direct representation of M:N relationship.

SQL 'Objects' – (Object Relational Database)

User-Defined Types  Object capabilities of SQL are provided by User- Defined Types (UDT).  There are two kinds of UDT: Distinct type Structured type

Distinct Types  A distinct type is defined in terms of its source type, which represents the values of the distinct type.  It provides encapsulation – a distinct type has both state and behaviour.  Implicit creation of an ordering based on the source type.  Cast and transform functions are created implicitly. Cast functions converts values of distinct type to and from its source type. Transform functions converts values of distinct type to and from host variable.  Functions, such as arithmetic or comparison, for manipulating values are created explicitly.

Distinct Type CREATE TYPE ids_of_students AS CHAR(3) student_id ids_of_students student_id < CAST('s51' AS ids_of_students) SELECT student_id INTO :s_identifier FROM student WHERE student_name = 'John'

Structured Types  A structured type is defined as having a number of attributes and a number of methods.  The creation of a structured type includes the implicit creation of special kind of function, called constructor function, which has the same name as the structured type, has no parameter and returns a value of that type.  Cast and transform functions need to be created explicitly.

Structured Types  For each attribute of a structured type, two methods are implicitly created. An observer method has a name that is the same as that of the attributes; it has no parameter; when invoked it returns the value of the attribute for the instance of the structured type for which the method is invoked. A mutator method has a name that is the same as that of the attributes; it has a single parameter whose type is the same as that of the attributes; when invoked, it returns the instance of the structured type that is the same as the instance for which the method is invoked apart from that attributes having a value given by the argument on invocation.

Structured Type CREATE TYPE st_address AS ( location VARCHAR(30),-- name or number place VARCHAR(30),-- road, street, etc site VARCHAR(30),–- town, city, etc area VARCHAR(30),–- county, state, etc mail_code VARCHAR(20) –- postcode, zipcode, etc ) DECLARE var_address st_address SET var_address = NEW st_address() -- Constructor function SET var_address = var_address.location('Meadowfield') SET var_address.location = 'Meadowfield' -- Mutator var_address.location() -- Observer ALTER TYPE st_address ADD METHOD string_address() RETURNS VARCHAR(150) CREATE METHOD string_address() FOR st_address RETURN SELF.location()||', '||SELF.place()||','|| SELF.site() ||', '||SELF.area()||', '||SELF.mail_code()

Subtypes  Subtypes provides Inheritance (single inheritance) Overriding Extension  Substitutablility allows an instance of a subtype to substitute an instance of the supertype.  An instance of a type is also an instance of all its supertypes.  Cast and transform functions are required for a subtype that has additional attributes.

Subtypes CREATE TYPE world_address UNDER st_address AS (country VARCHAR(30)) OVERRIDING METHOD string_address() RETURNS VARCHAR(150) CREATE METHOD string_address() FOR world_address RETURN (SELF AS st_address).string_address||',' ||SELF. country()

Composite Values – Collection Types  Collection type includes arrays and multisets.  Collection Is a value of a collection type Comprises zero or more elements The number of elements in a collection is its cardinality A collection type is defined by a type constructor and an element data type Each element in a collection is a value of the element data type

Arrays  Array is an ordered collection. Every element has an ordinal position.  An array has a maximum cardinality.  Two arrays are equal if the elements in the same position in each array are the same.

Multisets  A multiset is an unordered collection.  No means to reference individual element in a multiset.  Duplicate elements are allowed.  No maximum cardinality.  Two multisets are equal if they both contain the same elements, and the same number of each element.

Rows  A row type is defined as a sequence of fields where a field has a field name and data type.  A row type does not have any object-oriented properties – no methods and no encapsulation.  Main benefits: Enabling function to return multiple values. Collection of row type Collection of rows with column being a row type, this nested table.

Array, Multiset, Row Type --Array tel_nums VARCHAR(15) ARRAY[5] SET tel_num = ARRAY[' ', ' ', ' '] ARRAY(SELECT DISTINCT staff_name FROM staff, student WHERE staff_no = counsellor_no) --Multiset SELECT counsellor_no, COLLECT(student_name) AS students FROM student GROUP BY counsellor_no --Row type DECLARE row_address ROW( position VARCHAR(30), place VARCHAR(30), site VARCHAR(30, area VARCHAR(30), mail_code VARCHAR(20))

Using Structured Types with Tables

Usage of Structured Type  Structured type can be used in two different ways when defining tables: Define columns of a table  Capable of representing 'objects' in tables.  Require Cast and Transform functions to support interaction with application processes. Define rows of a table  Attributes of the structured type becomes columns of the table (typed table).  Capable of being a referenceable table using the REF type.

Structured Types for Columns CREATE TABLE staff ( staff_no CHAR(4), staff_name VARCHAR(12) NOT NULL, staff_address st_address, staff_region CHAR(1), PRIMARY KEY (staff_no) ) SELECT staff_name, staff_address.location() AS location, staff_address.place() AS place, staff_address.site() AS site FROM staff WHERE staff_address.area() = 'Wessex'

Structured Types for Tables CREATE TYPE st_student AS ( student_id CHAR(3), student_name VARCHAR(12) NOT NULL, student_address st_address, registration_date DATE NOT NULL, student_region CHAR(1) ) METHOD derive_region() RETURNS CHAR(1) CREATE TABLE student OF st_student ( PRIMARY KEY(student_id), REF IS row_id SYSTEM GENERATED )