Fundamentals of Database Systems
Seventh Edition
Chapter 12
Object and Object-Relational Databases
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
If this PowerPoint presentation contains mathematical equations, you may need to check that your computer has the following installed:
1) MathType Plugin
2) Math Player (free versions available)
3) NVDA Reader (free versions available)
1
Learning Objectives
12.1 Overview of Object Database Concepts
12.2 Object-Relational Features
12.3 Object Database Extensions to S Q L
12.4 O D M G Object Model and the Object Definition Language O D L
12.5 Object Database Conceptual Design
12.6 The Object Query Language O Q L
12.7 Overview of the C + + Language Binding
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Object and Object-Relational Databases
Object databases (O D B)
Object data management systems (O D M S)
Meet some of the needs of more complex applications
Specify:
Structure of complex objects
Operations that can be applied to these objects
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Overview of Object Database Concepts (1 of 2)
Introduction to object-oriented concepts and features
Origins in O O programming languages
Object has two components:
State (value) and behavior (operations)
Instance variables (attributes)
Hold values that define internal state of object
Operation is defined in two parts:
Signature (interface) and implementation (method)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Overview of Object Database Concepts (2 of 2)
Inheritance
Permits specification of new types or classes that inherit much of their structure and/or operations from previously defined types or classes
Operator overloading
Operation’s ability to be applied to different types of objects
Operation name may refer to several distinct implementations
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Object Identity, and Objects Versus Literals
Object has Unique identity
Implemented via a unique, system-generated object identifier (O I D)
Immutable
Most O O database systems allow for the representation of both objects and literals (simple or complex values)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Complex Type Structures for Objects and Literals (1 of 2)
Structure of arbitrary complexity
Contain all necessary information that describes object or literal
Nesting type constructors
Generate complex type from other types
Type constructors (type generators):
Atom (basic data type – int, string, etc.)
Struct (or tuple)
Collection
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Complex Type Structures for Objects and Literals (2 of 2)
Collection types:
Set
Bag
List
Array
Dictionary
Object definition language (O D L)
Used to define object types for a particular database application
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.1 Specifying the Object Types EMPLOYEE, DATE, and DEPARTMENT Using Type Constructors
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.2 Adding Operations to the Definitions of EMPLOYEE and DEPARTMENT
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Encapsulation of Operations (1 of 2)
Encapsulation
Related to abstract data types
Define behavior of a class of object based on operations that can be externally applied
External users only aware of interface of the operations
Can divide structure of object into visible and hidden attributes
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Encapsulation of Operations (2 of 2)
Constructor operation
Used to create a new object
Destructor operation
Used to destroy (delete) an object
Modifier operations
Modify the state of an object
Retrieve operation
Dot notation to apply operations to object
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Persistence of Objects
Transient objects
Exist in executing program
Disappear once program terminates
Persistent objects
Stored in database, persist after program termination
Naming mechanism: object assigned a unique name in object base, user finds object by its name
Reachability: object referenced from other persistent objects, object located through references
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.3 Creating Persistent Objects by Naming and Reachability
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Type (Class) Hierarchies and Inheritance (1 of 3)
Inheritance
Definition of new types based on other predefined types
Leads to type (or class) hierarchy
Type: type name and list of visible (public) functions (attributes or operations)
Format:
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Type (Class) Hierarchies and Inheritance (2 of 3)
Subtype
Useful when creating a new type that is similar but not identical to an already defined type
Subtype inherits functions
Additional (local or specific) functions in subtype
Example:
EMPLOYEE subtype-of PERSON: Salary, Hire_date, Seniority
STUDENT subtype-of PERSON: Major, Gpa
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Type (Class) Hierarchies and Inheritance (3 of 3)
Extent
A named persistent object to hold collection of all persistent objects for a class
Persistent collection
Stored permanently in the database
Transient collection
Exists temporarily during the execution of a program (e.g. query result)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Other Object-Oriented Concepts
Polymorphism of operations
Also known as operator overloading
Allows same operator name or symbol to be bound to two or more different implementations
Type of objects determines which operator is applied
Multiple inheritance
Subtype inherits functions (attributes and operations) of more than one supertype
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Summary of Object Database Concepts
Object identity
Type constructors (type generators)
Encapsulation of operations
Programming language compatibility
Type (class) hierarchies and inheritance
Extents
Polymorphism and operator overloading
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Object-Relational Features: Object D B Extensions to S Q L
Type constructors (generators)
Specify complex types using U D T
Mechanism for specifying object identity
Encapsulation of operations
Provided through user-defined types (U D T s)
Inheritance mechanisms
Provided using keyword UNDER
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
User-Defined Types (U D Ts) and Complex Structures for Objects (1 of 2)
U D T syntax:
Can be used to create a complex type for an attribute (similar to struct – no operations)
Or: can be used to create a type as a basis for a table of objects (similar to class – can have operations)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
User-Defined Types (U D Ts) and Complex Structures for Objects (2 of 2)
Array type – to specify collections
Reference array elements using []
CARDINALITY function
Return the current number of elements in an array
Early S Q L had only array for collections
Later versions of S Q L added other collection types (set, list, bag, array, etc.)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Object Identifiers Using Reference Types
Reference type
Create unique object identifiers (O I D s)
Can specify system-generated object identifiers
Alternatively can use primary key as O I D as in traditional relational model
Examples:
REF IS SYSTEM GENERATED
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Creating Tables Based on the U D T s
INSTANTIABLE
Specify that U D T is instantiable
The user can then create one or more tables based on the U D T
If keyword INSTANTIABLE is left out, can use U D T only as attribute data type – not as a basis for a table of objects
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Encapsulation of Operations
User-defined type
Specify methods (or operations) in addition to the attributes
Format:
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.4a Illustrating Some of the Object Features of S Q L. Using U D T S as Types for Attributes Such as Address and Phone
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.4b Illustrating Some of the Object Features of S Q L. Specifying U D T for PERSON_TYPE
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Specifying Type Inheritance (1 of 2)
NOT FINAL:
The keyword NOT FINAL indicates that subtypes can be created for that type
UNDER
The keyword UNDER is used to create a subtype
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.4c Illustrating Some of the Object Features of S Q L. Specifying U D Ts for STUDENT_TYPE and EMPLOYEE_TYPE as Two Subtypes of PERSON_TYPE (1 of 2)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.4c Illustrating Some of the Object Features of S Q L. Specifying U D Ts for STUDENT_TYPE and EMPLOYEE_TYPE as Two Subtypes of PERSON_TYPE (2 of 2)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Specifying Type Inheritance (2 of 2)
Type inheritance rules:
All attributes/operations are inherited
Order of supertypes in UNDER clause determines inheritance hierarchy
Instance (object) of a subtype can be used in every context in which a supertype instance used
Subtype can redefine any function defined in supertype
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Creating Tables Based on U D T
UDT must be INSTANTIABLE
One or more tables can be created
Table inheritance:
UNDER keyword can also be used to specify supertable/subtable inheritance
Objects in subtable must be a subset of the objects in the supertable
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.4d Illustrating Some of the Object Features of S Q L. Creating Tables Based on Some of the U D Ts, and Illustrating Table Inheritance
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Specifying Relationships via Reference
Component attribute of one tuple may be a reference to a tuple of another table
Specified using keyword R E F
Keyword SCOPE
Specify name of table whose tuples referenced
Dot notation
Build path expressions
Used for dereferencing
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.4e Illustrating Some of the Object Features of S Q L. Specifying Relationships Using R E F and SCOPE
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Summary of S Q L Object Extensions
U D T to specify complex types
INSTANTIABLE specifies if U D T can be used to create tables; NOT FINAL specifies if U D T can be inherited by a subtype
R E F for specifying object identity and inter-object references
Encapsulation of operations in U D T
Keyword UNDER to specify type inheritance and table inheritance
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
O D M G Object Model and Object Definition Language O D L (1 of 2)
O D M G object model
Data model for object definition language (O D L) and object query language (O Q L)
Objects and Literals
Basic building blocks of the object model
Object has five aspects:
Identifier, name, lifetime, structure, and creation
Literal
Value that does not have an object identifier
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
O D M G Object Model and Object Definition Language O D L (2 of 2)
Behavior refers to operations
State refers to properties (attributes)
Interface
Specifies only behavior of an object type
Typically noninstantiable
Class
Specifies both state (attributes) and behavior (operations) of an object type
Instantiable
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Inheritance in the Object Model of O D M G
Behavior inheritance
Also known as I S – A or interface inheritance
Specified by the colon (:) notation
EXTENDS inheritance
Specified by keyword extends
Inherit both state and behavior strictly among classes
Multiple inheritance via extends not permitted
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Built-In Interfaces and Classes in the Object Model
Collection objects
Inherit the basic Collection interface
Creates an iterator object for the collection
To loop over each object in a collection
Collection objects further specialized into:
set, list, bag, array, and dictionary
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.6 Inheritance Hierarchy for the Built-In Interfaces of the Object Model
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Atomic (User-Defined) Objects
Specified using keyword class in O D L
Attribute
Property; describes data in an object
Relationship
Specifies inter-object references
Keyword inverse
Single conceptual relationship in inverse directions
Operation signature:
Operation name, argument types, return value
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.7 The Attributes, Relationships, and Operations in a Class Definition
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Extents, Keys, and Factory Objects
Extent
A persistent named collection object that contains all persistent objects of class
Key
One or more properties whose values are unique for each object in extent of a class
Factory object
Used to generate or create individual objects via its operations
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Object Definition Language O D L
Support semantic constructs of O D M G object model
Independent of any particular programming language
Example on next slides of a UNIVERSITY database
Graphical diagrammatic notation is a variation of E E R diagrams
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.9a An Example of a Database Schema. Graphical Notation for Representing O D L Schemas
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.9b An Example of a Database Schema. A Graphical Object Database Schema for Part of the UNIVERSITY Database (GRADE and DEGREE Classes Are Not Shown)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.10 Possible O D L Schema for the UNIVERSITY Database in Figure 12.8(b) (1 of 2)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.10 Possible O D L Schema for the UNIVERSITY Database in Figure 12.8(b) (2 of 2)
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Interface Inheritance in O D L
Next example illustrates interface inheritance in O D L
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.11a An Illustration of Interface Inheritance Via “:”. Graphical Schema Representation
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Figure 12.11b An Illustration of Interface Inheritance Via “:”. Corresponding Interface and Class Definitions in O D L
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Object Database Conceptual Design
Differences between conceptual design of O D B and R D B, handling of:
Relationships
Inheritance
Philosophical difference between relational model and object model of data
In terms of behavioral specification
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Mapping an E E R Schema to an O D B Schema (1 of 2)
Create O D L class for each E E R entity type
Add relationship properties for each binary relationship
Include appropriate operations for each class
O D L class that corresponds to a subclass in the E E R schema
Inherits type and methods of its superclass in O D L schema
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Mapping an E E R Schema to an O D B Schema (2 of 2)
Weak entity types
Mapped same as regular entity types
Categories (union types)
Difficult to map to O D L
An n-ary relationship with degree n > 2
Map into a separate class, with appropriate references to each participating class
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
The Object Query Language O Q L
Query language proposed for O D M G object model
Simple O Q L queries, database entry points, and iterator variables
Entry point: named persistent object
Iterator variable: define whenever a collection is referenced in an O Q L query
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Query Results and Path Expressions
Result of a query
Any type that can be expressed in O D M G object model
O Q L orthogonal with respect to specifying path expressions
Attributes, relationships, and operation names (methods) can be used interchangeably within the path expressions
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Other Features of O Q L (1 of 2)
Named query
Specify identifier of named query
O Q L query will return collection as its result
If user requires that a query only return a single element use element operator
Aggregate operators
Membership and quantification over a collection
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Other Features of O Q L (2 of 2)
Special operations for ordered collections
Group by clause in O Q L
Similar to the corresponding clause in S Q L
Provides explicit reference to the collection of objects within each group or partition
Having clause
Used to filter partitioned sets
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Overview of the C + + Language Binding in the O D M G Standard
Specifies how O D L constructs are mapped to C + + constructs
Uses prefix d_ for class declarations that deal with database concepts
Template classes
Specified in library binding
Overloads operation new so that it can be used to create either persistent or transient objects
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Summary
Overview of concepts utilized in object databases
Object identity and identifiers; encapsulation of operations; inheritance; complex structure of objects through nesting of type constructors; and how objects are made persistent
Description of the O D M G object model and object query language (O Q L)
Overview of the C++ language binding
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved
Copyright
Copyright © 2016, 2011, 2007 Pearson Education, Inc. All Rights Reserved