KSK ADS Unit 2
KSK ADS Unit 2
Method Security:
ADTs give users the power to add code to the DBMS;
this power can be abused.
• Method Caching
• Cache of input and output of methods
• Pointer Swizzling
• Technique to reduce cost of cached object
27
Single-Level v. Two-Level Storage Model
29
Single-Level v. Two-Level Storage Model
30
Single-Level v. Two-Level Storage Model
31
Two-Level Storage Model for RDBMS
32
Single-Level Storage Model for OODBMS
33
Pointer Swizzling Techniques
34
Pointer Swizzling Techniques
35
Accessing an Object with a RDBMS
36
Accessing an Object with an OODBMS
37
Chapter Outline
20.1 Overview of O-O Concepts
20.2 O-O Identity, Object Structure and Type
Constructors
20.3 Encapsulation of Operations, Methods and
Persistence
20.4 Type and Class Hierarchies and Inheritance
20.5 Complex Objects
20.6 Other O-O Concepts
20.7 Summary & Current Status
Introduction
However, the states of objects o1 and o3 are identical, even though the
objects themselves are not because they have distinct OIDs. Similarly,
although the states of o4 and o5 are identical, the actual objects o4 and o5 are
equal but not identical, because they have distinct OIDs.
Object Identity, Object
Structure, and Type
Constructors (11)
Figure 20.1 Representation of a DEPARTMENT complex object as a
graph
Encapsulation of Operations,
Methods, and Persistence (4)
Figure 20.3 Adding operations to definitions of Employee
and Department
Encapsulation of Operations, Methods, and
Persistence (5)
Specifying Object Persistence via Naming and
Reachability:
• Naming Mechanism: Assign an object a unique persistent
name through which it can be retrieved by this and other
programs.
• Reachability Mechanism: Make the object reachable
from some persistent object.
• An object B is said to be reachable from an object A if a
sequence of references in the object graph lead from object A
to object B.
Encapsulation of Operations, Methods, and
Persistence (6)
Specifying Object Persistence via Naming and Reachability (cont.):
• In traditional database models such as relational model or EER model, all objects
are assumed to be persistent.
• In OO approach, a class declaration specifies only the type and operations for a
class of objects. The user must separately define a persistent object of type set
(DepartmentSet) or list (DepartmentList) whose value is the collection of
references to all persistent DEPARTMENT objects
Encapsulation of Operations, Methods, and
Persistence (7)
Example:
PERSON: Name, Address, Birthdate, Age, SSN
Type and Class Hierarchies
and Inheritance (2)
• Subtype: when the designer or user must create a new type that is
similar but not identical to an already defined type
Example (1):
EMPLOYEE: Name, Address, Birthdate, Age, SSN, Salary, HireDate, Seniority
STUDENT: Name, Address, Birthdate, Age, SSN, Major, GPA
OR:
EMPLOYEE subtype-of PERSON: Salary, HireDate, Seniority
STUDENT subtype-of PERSON: Major, GPA
Type and Class Hierarchies
and Inheritance (4)
Example (2):
Consider a type that describes objects in plane geometry, which may be defined
as follows:
interface Shape {
attribute struct point {…} reference_point;
float perimeter ();
…
};
94
Defining an Attribute
• Value can be either:
• Object identifier OR Literal
• Types of literals
• Atomic – a constant that cannot be decomposed into components
• Collection – multiple literals or object types
• Structure – a fixed number of named elements, each of which could be a
literal or object type
• Attribute ranges
• Allowable values for an attribute
• enum – for enumerating the allowable values
95
Kinds of Collections
• Set – unordered collection without duplicates
• Bag – unordered collection that may contain duplicates
• List – ordered collection, all the same type
• Array – dynamically sized ordered collection, locatable by position
• Dictionary – unordered sequence of key-value pairs without
duplicates
96
Defining Structures
Structure = user-defined type with components
struct keyword
Example:
struct Address {
String street_address
String city;
String state;
String zip;
};
97
Defining Operations
• Return type
• Name
• Parentheses following the name
• Arguments within the
parentheses
98
Defining Relationships
• Only unary and binary relationships allowed
• Relationships are bi-directional
• implemented through use of inverse keyword
• ODL relationships are specified:
• relationship indicates that class is on many-side
• relationship set indicates that class is on one-side and other class (many)
instances unordered
• relationship list indicates that class is on one-side and other class (many)
instances ordered
99
Figure 15-1: UML class diagram for a university database
100
Figure 15-2: ODL Schema for university database
101
Figure 15-2: ODL Schema for university database (cont.)
102
Figure 15-2: ODL Schema for university database (cont.)
103
Figure 15-2: ODL Schema for university database (cont.)
extent = the set of all instances of the class
104
Figure 15-2: ODL Schema for university database (cont.)
Operation definition:
return type, name,
and argument list.
Arguments include
data types and names
105
Figure 15-2: ODL Schema for university database (cont.)
106
Figure 15-2: ODL Schema for university database (cont.)
107
Figure 15-2: ODL Schema for university database (cont.)
108
In order to capture special features of
assignment, this should be converted into
two 1:N relationships
109
class Employee { Note:
(extent employees key indicates identifier
key emp_id) (candidate key)
………….
Note: attribute set indicates a
attribute set <string> skills_required;
multivalued attribute
};
110
Note:
extends
denotes
subclassing
class HourlyEmployee
extends Employee{
( ………….
………….
}
111
Figure 15-5: UML class diagram showing student generalization
112
Creating Object Instances
• Specify a tag that will be the object identifier
• MBA699 course ();
• Initializing attributes:
• Cheryl student (name: “Cheryl Davis”, dateOfBirth:4/5/77);
• Initializing multivalued attributes:
• Dan employee (emp_id: 3678, name: “Dan Bellon”,
skills {“Database design”, “OO Modeling”});
• Establishing links for relationship
• Cheryl student (takes: {OOAD99F, Telecom99F, Java99F});
113
Querying Objects in the
OODB
• Object Query Language (OQL)
• ODMG standard language
• Similar to SQL-92
• Some differences:
• Joins use class’s relationship name:
• Select x.enrollment from courseofferings x, x.belongs_to y where y.crse_course = “MBA 664” and
x.section = 1;
• Using a set in a query
• Select emp_id, name from employees where “Database Design” in skills;
114
Object Query Language
• OQL is DMG’s query language
• OQL works closely with programming languages such as C++
• Embedded OQL statements return objects that are compatible with
the type system of the host language
• OQL’s syntax is similar to SQL with additional features for objects
The schema defines the types Person and Employee. These types
have the extents Persons and Employees respectively. One of
these persons is the chairman (and there is an entry-point
Chairman to that person). The type Person defines the name,
birth-date, and salary as attributes and the operation age. The
type Employee, a subtype of Person, defines the relationship
subordinates and the operation seniority.