Post on 14-Jan-2016
description
FEN 16-09-2007 NOEA/IT - Databases/ODB2 1
ODB and the ODMG(Object Data Management Group)
Object (Oriented) Databases (ODB)
The ODMG standard:
Object model
ODL
OQL
Language-bindings
FEN 16-09-2007 NOEA/IT - Databases/ODB2 2
ODMG: The Object Model
• Object:– Objects have identity (OID) and state, OID
never changes, state may change over time– Objects may have names (entry points to the
Database)– Objects have a lifetime (either persistent or
transient
FEN 16-09-2007 NOEA/IT - Databases/ODB2 3
ODMG: The Object Model
• Object:– Objects have structure (atomic or Collection)– The structure specifies how to create the object
using a type constructor• Atomic objects are any objects that are not
collections• They may be composite (have internal structure)• They are not tuples in the relational sense of the
word tuple
FEN 16-09-2007 NOEA/IT - Databases/ODB2 4
Literals
• Have state, but no OID, state is never changed (”constant objects”)
• State may be atomic or complex:– Atomic literals are simple, predefined types– Structured literals (roughly records or structs)– Collection literals (collections like in the Java or
.NET API, but persistent)
FEN 16-09-2007 NOEA/IT - Databases/ODB2 5
Standardinterfaces i ODMG
FEN 16-09-2007 NOEA/IT - Databases/ODB2 6
FEN 16-09-2007 NOEA/IT - Databases/ODB2 7
FEN 16-09-2007 NOEA/IT - Databases/ODB2 8
FEN 16-09-2007 NOEA/IT - Databases/ODB2 9
FEN 16-09-2007 NOEA/IT - Databases/ODB2 10
FEN 16-09-2007 NOEA/IT - Databases/ODB2 11
FEN 16-09-2007 NOEA/IT - Databases/ODB2 12
Atomic (domain) Objects• Called atomic, but are often composite
(structured)
• Corresponds to entities in a conceptual model
• Objects have:– Properties (state):
• Attributes• Relationships
– Operations (behaviour)
FEN 16-09-2007 NOEA/IT - Databases/ODB2 13
OBS! Inverse =>
automatisk integritet
FEN 16-09-2007 NOEA/IT - Databases/ODB2 14
Inheritance
• Between interfaces:– only (abstract) behaviour (specification) – Any properties defined in an interface are not
inherited– “keyword”: ”:”
• Between classes:– both state and behaviour– Keyword: “extends
• Like Java or C#
FEN 16-09-2007 NOEA/IT - Databases/ODB2 15
The Extension of a Class (extent)
• All objects belonging to a class is automatically stored persistently in the extension of the class
• The extension of a class is the set of all objects of that class
• The extension is declared using the keyword extent (not extends, which specifies inheritance)
• The extension of some class T is an object of type Set<T>
FEN 16-09-2007 NOEA/IT - Databases/ODB2 16
Inheritance and Class Extension
• class B extends A
Means (among other things) that
• The extension of B is a subset of the extension of A
FEN 16-09-2007 NOEA/IT - Databases/ODB2 17
ODL: Object Definition Language
• Graphical notation:
FEN 16-09-2007 NOEA/IT - Databases/ODB2 18
FEN 16-09-2007 NOEA/IT - Databases/ODB2 19
Note! extends extent
FEN 16-09-2007 NOEA/IT - Databases/ODB2 20
FEN 16-09-2007 NOEA/IT - Databases/ODB2 21
FEN 16-09-2007 NOEA/IT - Databases/ODB2 22
FEN 16-09-2007 NOEA/IT - Databases/ODB2 23
Inheritance between Interfaces
FEN 16-09-2007 NOEA/IT - Databases/ODB2 24
Only operations are
inherited
Must be repeated
FEN 16-09-2007 NOEA/IT - Databases/ODB2 25
OQL: Object Query Language
• Based on SQL– Non-procedural– Supports object navigation using references– Embedded or stand-alone
• For instance departments in an Engineering College:SELECT d.dnameFROM d IN departmentsWHERE d.college = ’Engineering’
• Returns a Bag of dname, SELECT DISTINCT returns a Set
Entry point is the extension of class
Department
FEN 16-09-2007 NOEA/IT - Databases/ODB2 26
Path-Expressions
• departments; – //returns a reference to the extension of Department
• csdepartment;– //a reference to the CS-dept-object
• csdepartment.chair;– //a path to the chair object of the CS-dept-object (type Faculty)
• csdepartment.chair.rank;– //the rank attribute of the chair -object of the CS-dept-object
• csdepartment.has_faculty;• //returns Set<Faculty>
– etc. etc.
FEN 16-09-2007 NOEA/IT - Databases/ODB2 27
Java-binding - FastObjectsDatabase db = new Database();Transaction txn = new Transaction();db.open("addressDB",Database.OPEN_READ_WRITE);txn.begin();OQLQuery query = new OQLQuery( "select x from Person x where x.name = \"Doug Barry\"");Collection result = (Collection) query.execute();Iterator iter = result.iterator();while ( iter.hasNext() ){ Person person = (Person) iter.next(); person.address.street = "13504 4th Avenue South"; }txn.commit();db.close();...
FEN 16-09-2007 NOEA/IT - Databases/ODB2 28
try{ MyClass myObject = new MyClass(); db.bind(myObject, "myName"); //root } catch (ObjectNameNotUniqueException exc){ txn.abort(); System.out.println( exc); } try{ MyClass myObject = (MyClass)db.lookup("myName"); System.out.println(myObject); } catch(ObjectNameNotFoundException exc){ System.out.println(exc); txn.abort(); }
FEN 16-09-2007 NOEA/IT - Databases/ODB2 29
Using Extension
//...
db.makePersistent( new MyClass() );
//…
// print all stored instances of MyClass
Extent myClasses = new Extent(MyClass.class);
while ( myClasses.hasNext() ) {
System.out.println( myClasses.next() );
}
//...
FEN 16-09-2007 NOEA/IT - Databases/ODB2 30
Conclusion:
OOPL
+ embedded ”SQL”
+ persistent Collection
==
ODB
More on: http://www.versant.com/