OBJECTS & DATABASES Arnaud Sahuguet – CIS-550
OO terminology is very loose. Don’t be surprised Contents Why objects Basics of OO class inheritance encapsulation object identity Object-Oriented Database what’s a schema ODL OQL Examples Final remarks OO terminology is very loose. Don’t be surprised Misc.. ORDBMS Arnaud Sahuguet – CIS-550
Why objects? Better modeling DB & programming languages objects seem to be a “friendly” paradigm “Jack” project at PENN (virtual reality) relational modeling 1 table for people’s heads 1 table for people’s arms etc. object-oriented modeling 1 object per person 1 object is composed of sub-objects DB & programming languages embedded query languages C++, Java prefer to speak directly to objects Arnaud Sahuguet – CIS-550
functional programming has no state What’s an object? Object = a human abstraction Object = a black box from the object point of view 1 state some associated methods from the outside point of view 1 hidden state 1 interface (some methods that can be called) functional programming has no state Example a Win’95 window Arnaud Sahuguet – CIS-550
How objects are defined An object is an instance of a CLASS constructor/destructor CLASS type definition (attributes) method signature & implementation abstract class when some implementation is missing an abstract class cannot be instantiated interface only signatures Abstract classes and interfaces are extremely useful. Arnaud Sahuguet – CIS-550
Class Person & Subclass Patient public class Person { String first_name; public String _get_first_name(){return first_name;} public void _set_first_name(String target){first_name = target;} String last_name; public String _get_last_name(){ return last_name;} public void _set_last_name(String target){last_name = target;} /* missing code */ }; public class Patient extends Person { Date dob; char sex; long mrn; String insurance_carrier = new String(); long insurance_number; Provider primary_care_provider; } Arnaud Sahuguet – CIS-550
Encapsulation The inside of the object can be hidden Visibility to make the object appear simple to prevent attempt to change the object’s state Visibility attribute and methods can be set to public full visibility from the outside private cannot be accessed from the outside “restricted” access granted through methods getXXX() setXXX() Arnaud Sahuguet – CIS-550
!!! Multiple Inheritance can create AMBIGUITY !!! Inheritance (I) Rationale better modeling “factoring” common features specialization code reuse Inheritance of attributes methods Single/Multiple inheritance !!! Multiple Inheritance can create AMBIGUITY !!! Arnaud Sahuguet – CIS-550
Inheritance (II) Class hierarchy Method overriding super-class(es) sub-class(es) casting/coercion Method overriding methods can be inherited a class can rely on a method form its super-class a class can redefine inherited methods (overriding) e.g. toString() in Java, display for o2 Arnaud Sahuguet – CIS-550
Object identity Objects type + method OID objects have a state objects have a unique object identifier (OID) objects have a life time from their construction to their destruction OID Person p1 = new Person(“Peter”, “Buneman”); Person p2 = new Person(“Peter”, “Buneman”); p1 and p2 are NOT the same Each time a constructor is called, a new OID is created. Because of the OID, there is no need for keys, or is there? Arnaud Sahuguet – CIS-550
What is a schema Entities Relations Constraints Documentation 1-1, 1-many, many-1, many-many, Constraints referential integrity (key, foreign keys) null unique cardinality other rules Documentation Arnaud Sahuguet – CIS-550
How to define a schema? using words using diagrams it’s always a good start using diagrams standard representation (see Derby) can be used with computer tools (CASE,etc.) e.g ER diagrams using Data Definition Languages (DDL) ODL for object-oriented schema schema description should be independent of any implementation easily mappable to any implementation easily mappable to any programming language (binding) Arnaud Sahuguet – CIS-550
ODMG (www.odmg.org) Object Model Object Definition Language (ODL) The ODMG Object Model provides the unifying basis for the entire ODMG standard. The ODMG Object Model extends the OMG Object Model with capabilities like relationships and transactions to support database functionality. Object Definition Language (ODL) ODL creates a layer of abstraction such that an ODL-generated schema is independent of both the programming language and the particular ODMG-compliant DBMS. ODL considers only object type definitions and ignores the actual implementation of methods. An ODL-generated schema can be freely moved between compliant DBMSs, different language implementations, or even translated into other DDLs, such as those proposed by SQL3. Object Query Language (OQL) OQL is an SQL-like declarative language that provides a rich environment for efficient querying of database objects, including high-level primitives for object sets and structures. Language bindings Arnaud Sahuguet – CIS-550
ODL The key concepts of the object model include: Attributes and relationships object properties Object operations (behavior) and exceptions Multiple inheritance Extents and keys Object naming, lifetime and identity Atomic, structured and collection literals List, set, bag and array collection classes Concurrency control and object locking Database operations Once again, there are different flavors of ODL Arnaud Sahuguet – CIS-550
Some ODL features class attribute struct relationship/inverse “collection” set, bag, list, array, dictionary enum keys exception extents they define object containers for each class used by queries Arnaud Sahuguet – CIS-550
OQL OQL syntax (previously presented) Use of extents Advantages of OQL various terminologies: names, containers Advantages of OQL OQL take advantage of object-oriented features methods path-expressions (“->”) de-referenciation queries are more elegant than in SQL Examples movie database http://www.unidata.com/derby/firstpage.html Arnaud Sahuguet – CIS-550
Final Remarks OO-DBMS are not studied in the book about ORDBMS they are not really OO, whatever you can read about it data is still stored into tables oo is something like a macro-layer http://www.cis.upenn.edu/~sahuguet/ORDBMS/contents.html Bibliography “A First Course in Database Systems”, by Ullman & Widow Prentice-Hall 1997 “The ODS standard: ODMG-2.0” Morgan Kaufmann 1997 Questions Arnaud Sahuguet – CIS-550