150 likes | 299 Views
Database Modeling. A Introduction to object definition language (ODL). 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)
E N D
Database Modeling A Introduction to object definition language (ODL)
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
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
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
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.
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).
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 RDBMS Abstract ODL C++ C++ Based OODBMS Smalltalk Smalltalk-Based OODBMS
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>;
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
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.
Types in ODL • Basic types • integer, real/float, string, enumerated types and classes. • Type constructors • Four basic collection types: • Set: Set <T> • Bag: Bag <T> • List: List <T> • Array: Array <T> • Struct for Structures: • Struct N { T1 F1, T2 F2, …, Fn Tn)
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>::
Additional Notes on Types • Limitation on nesting Relationship class collection Attribute basic, no class struct collection
An Example class Beers (extent all_beers) { attribute string name; attributestring manufacturer; attributeinteger price; relationshipset <Bars> servedAt inverse Bar::serves; relationshipset<Drinkers> fans inverse Drinkers::likes; }; class Bars (extent all_bars) { attribute string name; attributestruct Add {string street, string city, integer zip} address; attributeenum Lic {full, beer, none} licenseType; relationshipset<Drinkers> customers inverse Drinkers::frequents; relationshipset<Beers> servers inverse Beers::servedAt; }; class Drinkers (extent all_drinkers) { attribute string name; attribute struct Bars::Addr address; relationshipset <Beers> likes inverse Beers::fans; relationshipset<Bars> frequents inverse Bars::customers; };
Another Example class Person (extent persons key ssn) { attributestructPname {string fname, string lname, string lname} name; attributestring ssn; attributedate birthdate; attributeenum 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) };