Database Modeling - SCIS Home Page | Florida International

Download Report

Transcript Database Modeling - SCIS Home Page | Florida International

Database Modeling
A Introduction to object definition
language (ODL)
Database Management
COP4540, SCS, FIU
Object-oriented database systems
• New data types and classes are introduced
– Record Structure, collection type, reference type
– Class hierarchies and inheritance
• Data are grouped in objects
– Object Identity (OID)
• Why object-oriented?
– More powerful expressiveness
– High reusability of schemas
– Less misuse of data
Database Management
COP4540, SCS, FIU
ODMG Standard
• ODMG (Object Data Management Group)
– A consortium of OODBMS vendor
• Several parts
–
–
–
–
Object Model
Object Definition Language
Object Query Language
Binding to OO programming language
Database Management
COP4540, SCS, FIU
Overview of Object Model (1)
• Objects and Literal
– Basic building blocks of the object model.
– The key difference: Object Identifier.
• Built-in Interface for Collection Objects
–
–
–
–
–
Set<T> no multiple occurrence allowed
List<T> the order is important
Bag<T> multi-set
Array<T> the size is fixed
Dictionary<K, V> a collection of association pairs
Database Management
COP4540, SCS, FIU
Overview of Object Model (2)
• Interface, Classes, and Inheritance
–
–
–
–
The similar concept can be found in C++/JAVA.
Interface: non-instantiable
Class: instantiable
Question:
• what are the corresponding concepts in C++ and Java?
– Inheritance
• Behavior inheritance: supertype should be an interface.
• EXTENDS: both supertype and subtype must be classes.
• Multiple inheritance is allowed only for behavior
inheritance.
Database Management
COP4540, SCS, FIU
Overview of Object Model (2)
• Extents, Keys
– declare an extent for any object type that is defined
via a class declaration, and it will contain all
persistent objects of the class.
– Extents are also used to automatically enforce the
set/subset relationship between the extents of a
supertype and its subtype.
– A class with an extent can have one or more keys.
• Simple key
• composite key (compound key).
Database Management
COP4540, SCS, FIU
Object Definition Language (ODL)
• A proposed standard language for specifying the structure
in OO terms.
• It is independent of any particular programming language.
• An extension to IDL, which is a component of CORBA.
• A kind of data definition language at conceptual level.
Relational Design
Abstract
ODL
C++
Smalltalk
RDBMS
C++ Based OODBMS
Smalltalk-Based OODBMS
Database Management
COP4540, SCS, FIU
Basic Declarations in ODL
• ODL class declarations
class <name> (extent <name> key <attirbute>…
{
<list of elements = attributes, relationships, methods>
};
• Element declarations
attribute <type> <name>;
relationship <rangetype> <name>;
Database Management
COP4540, SCS, FIU
Relationships in ODL
• A way to connect objects in the database,
either from same class or different classes.
• Inverse relationship
• Multiplicity of relationships
– one to one
– many to one (one to many)
– many to many
Database Management
COP4540, SCS, FIU
Method Example
float gpa (in: Student) raises (noGrades)
• float = return type
• in: indicate Student argument is read-only
– Other options: out, inout
• noGrades is an exception that can be raised
by method gpa.
Database Management
COP4540, SCS, FIU
Types in ODL
• Basic types
– integer, real/float, string, enumerated types and
classes.
• Type constructors
– Four basic collection types:
•
•
•
•
Set:
Bag:
List:
Array:
Set <T>
Bag <T>
List <T>
Array <T>
– Struct for Structures:
• Struct N { T1 F1, T2 F2, …, Fn Tn)
Database Management
COP4540, SCS, FIU
Additional Notes on Types
• Structured types have names and bracketed
lists of field-type pairs.
• Enumerated types have names and
bracketed lists of values.
• An element from another class is indicated
by: <class>::
Database Management
COP4540, SCS, FIU
Additional Notes on Types
• Limitation on nesting
Relationship
class
collection
Attribute
basic,
no class
struct
collection
Database Management
COP4540, SCS, FIU
An Example
class Beers (extent all_beers) {
attribute
string name;
attribute
string manufacturer;
attribute
integer price;
relationship
set <Bars> servedAt inverse Bar::serves;
relationship
set<Drinkers> fans inverse Drinkers::likes;
};
class Bars (extent all_bars) {
attribute
string name;
attribute
struct Add {string street, string city, integer zip} address;
attribute
enum Lic {full, beer, none} licenseType;
relationship
set<Drinkers> customers inverse Drinkers::frequents;
relationship
set<Beers> servers inverse Beers::servedAt;
};
class Drinkers (extent all_drinkers) {
attribute
string name;
attribute
struct Bars::Addr address;
relationship
set <Beers> likes inverse Beers::fans;
relationship
set<Bars> frequents inverse Bars::customers;
};
Database Management
COP4540, SCS, FIU
Another Example
class Person (extent persons key ssn) {
attribute
struct Pname {string fname, string lname, string lname} name;
attribute
string ssn;
attribute
date birthdate;
attribute
enum Gender{F, M} sex;
abbribute
struct Add {short no, string street, short aptno, string city, string state, short zip}
address;
short
age();
};
class Student extends Person (extent students) {
attribute
string class;
relationship
Department majors_in inverse Department::has_majors;
void
change_major(in string dname) raises(dname_not_valid)
};
Database Management
COP4540, SCS, FIU