Class 10: Chapter 13

advertisement
Chapter 13
Future Directions
Class 10: Chapter 13
1
Class Topics
•
•
•
•
•
•
Object-Oriented Databases
Object-Oriented Applications
Object-Relational Databases
SQL3
Careers in Database Management
Assignment 3 Walkthrough (Carry-over
from Class 9)
Class 10: Chapter 13
2
Object Oriented Database
Concepts
(Added Material)
Class 10: Chapter 13
3
1
Object DBMSs
• Underlying concepts:
– Freely sharing data across processing routines
creates unacceptable data dependencies
– All software should be constructed out of
standard, reusable components whenever
possible
Class 10: Chapter 13
4
Advanced Database Applications
• Relational DBMSs have proven inadequate for
applications that store complex data structures:
–
–
–
–
–
–
Computer-aided design (CAD)
Computer-aided manufacturing (CAM)
Computer-aided software engineering (CASE)
Office information systems and multimedia systems
Digital publishing
Geographic information systems (GIS)
Class 10: Chapter 13
5
Object Oriented Concepts
Class 10: Chapter 13
6
2
Object Properties
• Abstraction: process of identifying
essential aspects of an entity and ignoring
unimportant properties (e.g. implementation
details)
• Encapsulation: object contains both the
data structure and the operations (methods)
that can be used to manipulate it
Class 10: Chapter 13
7
Object Properties
• Information Hiding: separate the external
aspects of an object from its internal details;
provides data independence
• Modularization: object can be constructed
and modified independent of the system,
provided the public interface is not changed
Class 10: Chapter 13
8
Objects and Attributes
• Object: A uniquely identifiable entity that
contains both the attributes that describe the
state of the “real world” object and the
actions (methods) associated with it
– Attributes or Instance Variables record the
current state of the object
– Complex Attribute can contain collections or
references, representing a relationship between
objects
Class 10: Chapter 13
9
3
Object Identity
• Object Identifier (OID):
– System generated
– Unique to one object
• Unique across entire system; primary key is unique
only within a relation
– Invariant; cannot be altered during its lifetime
– Independent of the values of its attributes
– Invisible to the user (ideally)
Class 10: Chapter 13
10
Advantages of OIDs
• Efficient: smaller than textual names or
foreign keys
• Fast: points to an actual address
• Cannot be modified by the user
• Independent of content
Class 10: Chapter 13
11
Methods and Messages
• Methods
– Define the behavior of an object
– Can be used to change the object’s state by modifying
attribute values
– Consists of a name and a body
• Messages
– Means by which objects communicate
– A request from one object (sender) to another object
(receiver) to execute a method
Class 10: Chapter 13
12
4
Attributes and Methods
Class 10: Chapter 13
13
Classes
• Class: a grouping of objects that have the
same attributes and respond to the same
messages
– Attributes and methods defined once for class
– Objects in a class called instances
Class 10: Chapter 13
14
Class Definition and Instances
Class 10: Chapter 13
15
5
Inhertiance, Subclasses and
Superclasses
• Inheritance: allows one class to be defined
as a special case of a more general case
• Subclass: special cases of a general class
• Superclass: general class
• Generalization vs Specialization
• Subclass inherits all properties of
Superclass and may define its own
Class 10: Chapter 13
16
Inheritance Options
• Multiple Inheritance: subclass inherits
from more than one superclass
– Can lead to errors if method or variable names
are ambiguous
• Selective Inheritance: limited properties
inherited
• Overriding: Subclass redefines a property
by using the same name as the inherited one
Class 10: Chapter 13
17
Single Inheritance
Class 10: Chapter 13
18
6
Multiple Inheritance
Class 10: Chapter 13
19
Overloading and Polymorphism
• Overloading allows the name of a method
to be reused within a class definition or
across class definitions
• Single message performs different functions
depending on which object receives it
• Permits polymorphism (having many
forms)
Class 10: Chapter 13
20
Complex Objects
• Objects can be combined into Complex
Objects
– Each object can appear independently
– Complex object can encapsulate the component
objects
– Complex objects can be included in other
complex objects
Class 10: Chapter 13
21
7
DBMS Generations
• Hierarchical and Network were first
generation DBMSs
• Relational are second generation DBMSs
• Third generation are Object Oriented
(OODBMS) and Object Relational
(ORDBMS)
Note: Objects are really not that new, OO
began in the 1970’s (Smalltalk at Xerox)
Class 10: Chapter 13
22
Two-level Storage Model
(Relational DBMS)
Class 10: Chapter 13
23
Single-level Storage Model
(OODBMS)
Class 10: Chapter 13
24
8
Accessing an Object
To access object, OODBMS must:
– Determine secondary storage page that contains
the object
– Read page and copy into page cache
– Convert object (swizzle references, etc.)
– Application directly references object in
memory
– OODBMS must convert object back before
storing it
Class 10: Chapter 13
25
Steps in Accessing an Object,
Conventional DBMS
Class 10: Chapter 13
26
Steps in Accessing an Object,
OODBMS
Class 10: Chapter 13
27
9
Advantages of OODMSs
•
•
•
•
•
•
•
Enriched modeling capabilities
Extensibility
No impedance mismatch with OO languages
More expressive query language
Support for schema evolution
Support for long duration transactions
Applicability to advanced database applications
Class 10: Chapter 13
28
Disadvantages of OODBMSs
•
•
•
•
•
•
•
Lack of universal data model
Lack of universally accepted standards
Query optimization compromises encapsulation
Locking at object level may impact performance
Complexity
Lack of support for views
Lack of support for security
Class 10: Chapter 13
29
Comparison of OODM and LDM
Class 10: Chapter 13
30
10
OO Design: Relationships
• 1:1 Relationships: Reference attribute
added to each object
• 1:M Relationships: Reference attribute
added to object on “many” side, attribute
containing a set of references added on the
“one” side
• M:N Relationships: Attribute containing set
of references added to each object
Class 10: Chapter 13
31
OO Design: Referential Integrity
• Referential integrity requires that any
referenced object must exist
• Techniques to handle referential integrity:
– Do not allow user to explicitly delete objects
– Allow user to delete objects when they are no
longer required (referenced)
– Allow user to modify or delete relationships
when they are no longer required
Class 10: Chapter 13
32
OO Design: Behavioral Design
• Constructor Methods: generate new instances
• Destructor Methods: delete instances when no
longer required
• Access Methods: return value of an attribute or
set of attributes
• Transform Methods: change instance state
• Identifying Methods: Determine methods
required to provide required functions
Class 10: Chapter 13
33
11
Object-Oriented Applications
• Object-Oriented (OO) applications are written in
OO programming languages
• OO languages usually come with pre-defined class
structures and methods, which are user extensible
• Some OO languages come with complete
development environments
• OO programming can be done with or without an
OO database
Class 10: Chapter 13
34
Object-Oriented Programming
• Messages are used as the vehicle for object
interaction
• Message composed of :
– Identifier of object to receive the message
– Name of method to be invoked
– Optional parameter(s)
• Methods are program code that define the
behavior of the object
Class 10: Chapter 13
35
Object-Oriented Languages
• Smalltalk
– Developed in 1972 by Software Concepts
Group (lead by Alan Kay) at Xerox PARC
– Alan Kay coined phrase “object-oriented”
– Includes:
•
•
•
•
Language
Programming Environment
Image File System (sort of an OO database)
Extensive Object Library
Class 10: Chapter 13
36
12
Object-Oriented Languages
• Smalltalk (cont.)
– Innovations included:
• Bitmap display
• Windowing system
• Use of a mouse
– Xerox never figured out how to market these
innovations
– Smalltalk is still around: www.smalltalk.org
Class 10: Chapter 13
37
Object-Oriented Languages
• C++
– Based on C Language (++ increments a
variable by 1 in C)
– Superset of C
– Primarily developed by Bjarne Stroustrup at
AT&T Bell Laboratories in 1986
– Classes are implemented as user-defined types
(called a struct in C)
– Methods are implemented as member functions
of a struct
Class 10: Chapter 13
38
Object-Oriented Languages
• C++ (cont.)
– Object purists criticize C++ because
programmer can totally ignore the object
paradigm
– C++ aficionados see that flexibility as a huge
benefit
Class 10: Chapter 13
39
13
Object-Oriented Languages
• Java
– A simple, portable, general-purpose OO
language
– Developed by Sun Microsystems in 1995
– Took market by storm, largely because of
support for Internet programming (applets)
– An interpretive language (unlike Smalltalk and
C++), with “just in time” compilers added to
resolve performance issues
Class 10: Chapter 13
40
Object Persistence
• Persistence: the OO property that preserves
the state of the object between executions of
an application or server shutdown/startup
• Database often used to permanently store
objects (OO, Relational, or O-R)
– Objects must be loaded into memory before use
– Loading is an indirect process
Class 10: Chapter 13
41
Class 10: Chapter 13
42
14
Class 10: Chapter 13
43
Object-Relational (O-R)
Databases
• Evolved in response to mapping objects to
relational databases
• Relational DBMS vendors such as Informix
and Oracle added object capability to
prevent loss of market share to OO DBMS
vendors
• Pure OO databases lack ad hoc query
support
Class 10: Chapter 13
44
O-R Databases
• Advantages
– Complex data types directly supported
– Methods can be stored as functions or stored
procedures, facilitating reuse and sharing
– Ad-hoc query capability is fully supported
Class 10: Chapter 13
45
15
O-R Databases
• Disadvantages
– More complex than either OO or relational
– Objects are table centric
– Relational purists dislike loss of simplicity
– Object purists not impressed with O-R
– Lack of class structure and inheritance
– Object applications are not as data centric as
relational applications, so OO DBMS may be a
better fit
Class 10: Chapter 13
46
ORDBMS Advantages
• Reuse comes from ability to extend DBMS
to perform common functions centrally
• Sharing comes from embedding object
functions in the server, making them
available to all applications
Class 10: Chapter 13
47
ORDBMS Disadvantages
• Complexity and associated increased costs
– Relational purists believe that essential simplicity and
purity are lost on these types of extensions
• Object purists are not attracted to these extensions,
arguing that ORDBMS is little more than userdefined data types
• Object applications are not as data centric as
relational ones
Class 10: Chapter 13
48
16
Early ORDBMSs
• Postgres (‘Post Ingress’)
– Provides predefined atomic types and allows users to
add new atomic and structured types
– Conversion procedures implemented in a high-level
language such as C using a define procedure
command
– INHERITS clause defines table inheritance
• Multiple inheritance supported
• Relation automatically inherits all attributes from parents
– Each relation has implicitly defined OID
Class 10: Chapter 13
49
Early ORDBMSs
• INGRES Object Management Extension
– Allows additional data types and SQL functions
to be created.
• User defined data types can be used anywhere
system defined data types can be used
• New SQL functions can be used in queries and to
manipulate system and user defined data types
– Functions can be written in a language that
conforms to ‘C’ conventions
Class 10: Chapter 13
50
Comparison of ORDBMS and
OODBMS
Class 10: Chapter 13
51
17
Which One to Use?
Class 10: Chapter 13
52
SQL3 (AKA SQL:99)
• Row Type: a sequence of field name / data
type pairs that can represent table rows so
that complete rows can be stored as
variables
– a column of a table may contain row values
using this type
Class 10: Chapter 13
53
SQL3 User-Defined Types
(UDTs)
• May be used in same way as built-in types
• Consists of one or more attribute definitions
• Proposed additions include routine declarations
and operation definitions
• Encapsulation enforced so that implementation
details not externally visible
• Observer (get) and mutator (set) functions
automatically defined for each attribute
• Constructor (create) function automatically
defined
Class 10: Chapter 13
54
18
SQL3: User-Defined Routines
• Defined as part of UDT or separately
• May be procedure, function or iterative
• Provided in standard language such as
C/C++
• SQL-Invoked routine is invoked from an
SQL Call statement
Class 10: Chapter 13
55
SQL3
• Polymorphism: UDT subtype or routine
may redefine a method inherited from
above
• Subtypes and Supertypes: UDTs can
participate in subtype/supertype hierarchies
– Subtype inherits all attributes and behavior of
its supertypes and can define additional
attributes and functions
Class 10: Chapter 13
56
SQL3
• Creating Tables: CREATE TABLE
statement still necessary, even if table
consists of a single UDT
• Querying Data: same syntax as SQL2 for
querying and updating tables with
extensions to handle objects
• Object Identity: aspect of object that never
changes and distinguishes from other
objects
Class 10: Chapter 13
57
19
SQL3: Reference Types
• Can be used to define relationships between row
types and uniquely identify row
• Direct reference to a row in another table
• Allows row to be shared among multiple tables
– Direct path instead of complex join
– Gives optimizer an alternative to joins
• By themselves, do NOT provide referential
integrity
Class 10: Chapter 13
58
SQL3: Collection Types
• Type constructors used to define collections
of other types; multiple values in a single
column can result in nested tables
• Element Types:
– ARRAY: one-dimensional array
– LIST: ordered list allowing duplicates
– SET: unordered collection; no duplicates
– MULTISET: unordered collection allowing
duplicates
Class 10: Chapter 13
59
SQL3: Language Extensions
(for computational completeness):
– Stored modules so object behavior can be
stored and executed from within database
– IF … THEN … ELSE … END IF
– FOR, WHILE and REPEAT
– CALL Statement
– Condition (Error) Handling
Class 10: Chapter 13
60
20
SQL3: Triggers
• Statement executed as a side effect of a
table modification
• Executed implicitly; has no arguments
• Disadvantages:
– Complexity
– Hidden functionality
– Performance overhead
Class 10: Chapter 13
61
SQL3: Large Objects
• Binary Large Object (BLOB): binary string that
does not have a character set or collation
association
• Character Large Object (CLOB): character string
large object
• National Character Large Object (NCLOB):
national language version of CLOB
• SQL3 can perform operations on contents of large
objects (in contrast to older implementations)
Class 10: Chapter 13
62
SQL3 and Object Query
Language (OQL)
• In SQL3, only tables persist; Objects
become persistent only when stored in a
table
• SQL3 collection types cannot be used as
freely as in OQL queries
Class 10: Chapter 13
63
21
Class 10: Chapter 13
64
Careers in Database Management
Class 10: Chapter 13
65
Assignment 3 Walkthrough
(If carried over from Class 9)
Class 10: Chapter 13
66
22
Download