Upload
juniper-davidson
View
219
Download
0
Tags:
Embed Size (px)
Citation preview
Chapter 18Chapter 18Object Database Management Systems
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
OutlineOutline
Motivation for object database management
Object-oriented principles Architectures for object database
management Object database definition and
manipulation in SQL:1999Object database definition and
manipulation in Oracle 9i
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Motivation: Complex DataMotivation: Complex Data
Most relational DBMSs support only a few data types.
Many business applications require large amounts of complex data such as images, audio, and video.
The need to integrate complex data with simple data drives the demand for object database technology.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Motivation: Type System Motivation: Type System MismatchMismatchIncreasing use of database access in
procedural codeDifferent data types used in programming
languages versus DBMSsData type mismatch makes software more
difficult to develop. A relational DBMS cannot perform
elementary operations on complex data.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Application ExamplesApplication Examples
Dental Office Support Real Estate Listing Service Auto Insurance Claims
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Object-Oriented PrinciplesObject-Oriented Principles
An object is a combination of data and procedures.
A class is a prototype that defines the variables and methods common to all objects of the class.
Three underlying principles: encapsulation, inheritance and polymorphism.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Encapsulation Encapsulation
Objects can be accessed only through their interfaces.
Classes can be reused rather than just individual procedures.
More complex classes can be defined using simpler classes.
Provides a form of data independence.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Bond Class ExampleBond Class Example
CLASS Bond {// VARIABLES: ATTRIBUTE Float IntRate; ATTRIBUTE Date Maturity;// METHODS: Float Yield();// Computes the Bond’s Yield };
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Inheritance Inheritance Sharing of data and code among similar
classes (classes and subclasses). Inherit variables and methods from parent
classesWhen using the subclasses, the methods in
the parent classes can be used.Inheritance provides an improved
organization of software and incremental reusability.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Inheritance ExamplesInheritance Examples
ColorPointColor
Brighten
Pointx,y
DistanceEquals
CorporateRating
TheCompanyJunk
InheritanceRelationships
SubClasses
BondIntRateMaturity
Yield
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Multiple Inheritance ExampleMultiple Inheritance Example SecuritySymbol
SecNameLastClose
StockOutShares
IssuedSharesYield
BondIntRateMaturity
Yield
Inheritanceconflict
ConvertibleConvPriceConvRatio
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
PolymorphismPolymorphism Ability of a computing system to choose
among multiple implementations Benefits
– Fewer, more reusable methods– incremental modification of code
Requesting a method execution involves sending a message to an object
Client-server processing and object-oriented computing are closely related.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Processing a MessageProcessing a Message
Message sent to ColorPointobject (CP1) to computedistance
ColorPoint classCP1 object
Point classDistance code
Message forwardedto parent class
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
BindingBinding
Associating an implementation with a message
Static binding– Performed at compile-time– More efficient but less flexible
Dynamic binding– Performed at run-time (late binding)– More flexible but less efficient
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Strong Type CheckingStrong Type Checking
Complex expressions can involve many methods and objects
Incompatibility errors common in codeAbility to ensure that programming code
contains no incompatibility errors An important kind of error checking for
object-oriented coding
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Programming Languages Programming Languages versus DBMSsversus DBMSs Programming languages have used object-
oriented principles for many years.Programming languages emphasize
software maintenance and code reusability.Object DBMSs are more recent.Encapsulation usually is relaxed so that an
object’s data can be referenced in a query. Inheritance mechanisms usually are simpler
in DBMSs
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Architectures for Object Architectures for Object Database ManagementDatabase Management Adding object-oriented features to a DBMS is a
good idea Many approaches about the features to add and
how features should be added. Some approaches provide small extensions that
leave object features outside the DBMS. Other approaches involve a complete rewrite of
the DBMS to accommodate objects Marketplace will determine best approaches
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Large Objects and External Large Objects and External SoftwareSoftware Storage of large objects in a database
along with external software to manipulate large objects.
Complex data are stored in a field using the BLOB (binary large object) data type.
The large object approach is simple to implement and universal.
The large object approach suffers from serious performance drawbacks.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Large Object ArchitectureLarge Object Architecture External software formanipulating complex data
Relational database
SQL statements
Simpledata
Complexdata
Database server
Simple andcomplex data
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Specialized Media ServersSpecialized Media Servers The use of a dedicated server to manage
complex data outside of a database. Programmers use an application
programming interface (API) to access complex data.
Provide good performance for specific kinds of complex data.
The range of operations may be limited. May perform poorly when combining
simple and complex data.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Specialized Media Server Specialized Media Server ArchitectureArchitecture
Database
SQL statementsand results
Database server Media serverMedia base
API calls and results
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Object database middleware Object database middleware
The use of middleware to manage complex data stored outside of a database along with traditional data stored in a database.
Provides a way to integrate complex data stored on PCs and remote servers with relational databases.
Object middleware can suffer performance problems because of a lack of integration with a DBMS.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Object Middleware ApproachObject Middleware Approach
DatabaseDatabase server Media server
Media base
Object middleware
SQL statementsand results
API callsand results
SQL statements and results
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Object Relational DBMS for Object Relational DBMS for User-Defined TypesUser-Defined Types A relational DBMS extended with an object
query processor for user-defined data types. Complex data is added as a user-defined
type.User-defined functions can be defined and
then used in SQL statements.SQL:1999 provides the standard for object
relational DBMSs. Provide good integration of complex data
but reliability may be a concern.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Component Architecture for Component Architecture for Object Relational DBMSsObject Relational DBMSs
Database
Object query processor(parser, optimizer, display
manager)
API calls and results
SQL statementsand results
Relational kernel(transaction processing,
storage management, buffermanagement)
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Object-Oriented DBMSObject-Oriented DBMS
A new kind of DBMS designed especially for objects.
Object-oriented DBMSs have an object query processor and an object kernel.
The Object Data Management Group (ODMG) provides the standard for object-oriented DBMSs.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Component Architecture for Component Architecture for Object-Oriented DBMSsObject-Oriented DBMSs
Database
Object query processor(parser, optimizer, display
manager)
API calls and results
OQL statementsand results
Relational kernel(transaction processing,
storage management, buffermanagement)
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Summary of ArchitecturesSummary of Architectures Architecture Example Products Comments
Large objects Most SQL-92 DBMSs
Poor performance; no query language support; universal storage capability
Media servers Oracle 7.3 with text and spatial data servers
No query language support; poor performance involving simple and complex data; good performance on complex data
Object database middleware
Microsoft Universal Data Access
Uncertain performance when combining simple and complex data; Ability to combine diverse data sources
Object relational (SQL3)
IBM UniData Data Blades, IBM DB2 Extenders, Oracle 9i
Uncertain reliability; good query language support; some type mismatch with programming languages; good support with specialized storage structures
Object-oriented (ODMG)
ObjectStore, UniSQL, O2, Versant, Gemstone
Good query language support; uncertain performance for traditional applications; good type match with programming languages
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Object Database Features in Object Database Features in SQL:1999SQL:1999Very large standardCore language partPackagesDetails about basic and enhanced object
supportTwo levels of conformance
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
SQL:1999 PackagesSQL:1999 Packages SQL3 Package Scope
Core SQL environment, SQL implementation, tables, views, predefined data types, SQL statements, conformance specifications
Persistent Stored Modules Computational completeness, stored modules, function overloading
Call Level Interface Call interface for SQL
Enhanced Datetime Facilities
Time zone specification, interval data type
Enhanced Integrity Management
Assertions, triggers, constraint management
OLAP Facilities Cube and roll-up operators, row and table constructors, FULL JOIN and INTERSECT operators
Basic Object Support User-defined data types, single inheritance, reference types, arrays
Enhanced Object Support Path expressions, subtable definition, subtable search, subtypes
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
User-Defined TypesUser-Defined Types Bundles data and proceduresSupport definition of structured types, not
just extensions of standard typesUser-defined types can be used as data types
for columns in tables, passed as parameters, and returned as values.
User-defined functions can be used in expressions in the SELECT, the WHERE, and the HAVING clauses.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
User-Defined Type ExampleUser-Defined Type Example
Example 1: Point Type
CREATE TYPE Point AS ( x FLOAT, -- X coordinate y FLOAT ) -- Y coordinate METHOD Distance(P2 Point) RETURNS FLOAT, -- Computes the distance between 2 points METHOD Equals (P2 Point) RETURNS BOOLEAN -- Determines if 2 points are equivalent NOT FINAL INSTANTIABLE;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Explicit MethodsExplicit Methods
Return single values and use input parameters
Implicit first parameter: part of user-defined type
CREATE METHOD statement for method body
Mutation methods: change valuesProcedures and functions not associated
with types
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Implicit MethodsImplicit Methods
Automatically exist for all user-defined types
Constructor method: creates an empty instance
Observer methods: retrieve valuesMutation methods: change values
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
User-Defined Type using an User-Defined Type using an ArrayArray
Example 2: Polygon type using an ARRAYCREATE TYPE Polygon AS( Corners Point ARRAY[10], Color INTEGER ) METHOD Area() RETURNS FLOAT, -- Computes the area METHOD Scale (Factor FLOAT) RETURNS Polygon -- Computes a new polygon scaled by factorNOT FINAL;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Table Definitions Table Definitions Traditional style: foreign keys to link
tablesTyped tables: supports object identifiers
and object referencesRow type constructor: supports rows as
variables and parameters
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Example of table definition with Example of table definition with a row type a row type
Example 3: Property table definition with a row type
CREATE TABLE Property (PropNo INTEGER, Address ROW (Street VARCHAR(50), City VARCHAR(30), State CHAR(2), Zip CHAR(9) ), SqFt INTEGER, View BLOB, AgentNo INTEGER, Location Point, CONSTRAINT PropertyPK PRIMARY KEY(PropNo), CONSTRAINT AgentFK FOREIGN KEY(AgentNo) REFERENCES Agent );
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Table Definition with a User-Table Definition with a User-Defined TypeDefined Type
Example 4: Definition of AgentType, followed by the Agent table based on AgentType
CREATE TYPE AddressType AS (Street VARCHAR(50), City VARCHAR(30), State CHAR(2), Zip CHAR(9) ) NOT FINAL; CREATE TYPE AgentType AS (AgentNo INTEGER, Name VARCHAR(30), Address AddressType, Phone CHAR(13), Email VARCHAR(50) ) NOT FINAL; CREATE TABLE Agent OF AgentType (REF IS AgentOId SYSTEM GENERATED, CONSTRAINT AgentPK PRIMARY KEY(AgentNo) );
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Subtable FamiliesSubtable Families A table can be declared as a subtable of
another table. A subtable inherits the columns of its
parent tables.SQL:1999 limits inheritance for tables to
single inheritance. Set inclusion determines the relationship
of a table to its subtables.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Subtable ExampleSubtable ExampleExample 5: Subtable of Property Table
CREATE TYPE ResidentialType UNDER PropertyType (BedRooms INTEGER, BathRooms INTEGER, Assessments DECIMAL(9,2) ARRAY[6] ) NOT FINAL INSTANTIABLE; CREATE TABLE Residential OF ResidentialType UNDER Property; CREATE TYPE IndustrialType UNDER PropertyType (Zoning VARCHAR(20), AccessDesc VARCHAR(20), RailAvailable BOOLEAN, Parking VARCHAR(10) ) NOT FINAL INSTANTIABLE; CREATE TABLE Industrial OF IndustrialType UNDER Property;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Side effects when manipulating Side effects when manipulating rows in subtable familiesrows in subtable familiesOn insert into a subtable, a corresponding
row is inserted into each parent table.On update in a parent table, the column is
also updated in all direct and indirect subtables that inherit the column.
On update of an inherited column, the column is changed in the corresponding rows of direct and indirect parent tables.
On delete, every corresponding row in both parent and subtables is also deleted.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Manipulating Complex Objects Manipulating Complex Objects and Subtable Familiesand Subtable Families Path expressions to manipulate columns
with row references.References to methods in expressions
using the dot notation Testing membership in a specific table
without being a member of any subtables.
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Using the ROW KeywordUsing the ROW KeywordExample 6: Using the ROW keyword in an INSERT statement.
INSERT INTO Agent (AgentNo, Name, Address, Email, Phone) VALUES (999999, 'Sue Smith', ROW('123 Any Street', 'Denver', 'CO', '80217'), '[email protected]', '13031234567') Example 7: Using a type name in an INSERT statement.
INSERT INTO Agent (AgentNo, Name, Address, Email, Phone) VALUES (999999, 'Sue Smith', AddressType('123 Any Street', 'Denver', 'CO', '80217'), '[email protected]', '13031234567');
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Obtaining Object IdentifiersObtaining Object Identifiers
Example 8: Using a SELECT statement to retrieve the
object identifier of the related Agent row.
INSERT INTO Residential (PropNo, Address, SqFt, AgentRef, BedRooms, BathRooms, Assessments) SELECT 999999, AddressType('123 Any Street', 'Denver', 'CO', '80217'), 2000, AgentOID, 3, 2, ARRAY[190000, 200000] FROM Agent WHERE AgentNo = 999999;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Example of Example of path expression path expression versus traditional expressionversus traditional expression
Example 9: SELECT statement with path expressions and the
dereference operator
SELECT PropNo, P.Address.City, P.AgentRef->Address.City FROM Property P WHERE AgentRef->Name = 'John Smith'
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Oracle 9i Object FeaturesOracle 9i Object Features
Supports most parts of the SQL:1999 object packages
User-defined typesTyped tablesOther object features
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
User-Defined Type ExampleUser-Defined Type ExampleExample 10: Point type in Oracle 9i
CREATE TYPE Point AS OBJECT ( x FLOAT(15), y FLOAT(15), MEMBER FUNCTION Distance(P2 Point) RETURN NUMBER, -- Computes the distance between 2 points MEMBER FUNCTION Equals (P2 Point) RETURN BOOLEAN, -- Determines if 2 points are equivalent MEMBER PROCEDURE Print ) NOT FINAL INSTANTIABLE;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
InheritanceInheritanceExample 11: ColorPoint type in Oracle 9i
CREATE TYPE ColorPoint UNDER Point (Color INTEGER, MEMBER FUNCTION Brighten (Intensity INTEGER) RETURN INTEGER, -- Increases color intensity MEMBER FUNCTION Equals (CP2 ColorPoint) RETURN BOOLEAN, -- Overriding is not used because the two -- Equals methods have different signatures. OVERRIDING MEMBER PROCEDURE Print ) NOT FINAL INSTANTIABLE;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Typed TablesTyped TablesExample 12: Typed table example
CREATE TYPE PropertyType AS OBJECT (PropNo INTEGER, Address AddressType, SqFt INTEGER, AgentRef REF AgentType, Location Point ) NOT FINAL INSTANTIABLE; CREATE TABLE Property OF PropertyType ( CONSTRAINT PropertyPK PRIMARY KEY(PropNo), CONSTRAINT AgentRefFK FOREIGN KEY(AgentRef) REFERENCES Agent ) OBJECT IDENTIFIER IS SYSTEM GENERATED ;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Inheritance for Typed TablesInheritance for Typed TablesExample 13: Typed table example with inheritance
CREATE TYPE AssessType AS VARRAY(6) OF DECIMAL(9,2); CREATE TYPE ResidentialType UNDER PropertyType (BedRooms INTEGER, BathRooms INTEGER, Assessments AssessType ) NOT FINAL INSTANTIABLE; CREATE TABLE Residential OF ResidentialType (CONSTRAINT ResidentialPK PRIMARY KEY(PropNo), CONSTRAINT AgentRefFK1 FOREIGN KEY(AgentRef) REFERENCES Agent ) OBJECT IDENTIFIER IS SYSTEM GENERATED ;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Inserting into Typed TablesInserting into Typed TablesExample 14: Insert rows into the residential and property tables
INSERT INTO Residential (PropNo, Address, SqFt, AgentRef, BedRooms, BathRooms, Assessments) SELECT 999999, AddressType('123 Any Street', 'Denver', 'CO', '80217'), 2000, REF(A), 3, 2, AssessType(190000, 200000) FROM Agent A WHERE AgentNo = 999999; INSERT INTO Property (PropNo, Address, SqFt, AgentRef) SELECT 999999, AddressType('123 Any Street', 'Denver', 'CO', '80217'), 2000, REF(A) FROM Agent A WHERE AgentNo = 999999;
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Path ExpressionsPath ExpressionsExample 15: Path expression using the DEREF function
SELECT PropNo, P.Address.City, DEREF(AgentRef).Address.City FROM Property P WHERE DEREF(AgentRef).Name = 'John Smith';
Example 16: Path expression using the dot operator
SELECT PropNo, P.Address.City, P.AgentRef.Address.City FROM Property P WHERE P.AgentRef.Name = 'John Smith';
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Other Object FeaturesOther Object Features
Type substitutability for subtablesHierarchical viewsNested tables
McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
SummarySummary
Three principles of object-oriented computing guide the development of object DBMSs.
A number of object DBMS architectures are commercially available.
SQL:1999 supports definition and manipulation of object relational databases.
Oracle 9i is a significant implementation of the SQL:1999 object packages