CS代考 www.cardiff.ac.uk/medic/irg-clinicalepidemiology

www.cardiff.ac.uk/medic/irg-clinicalepidemiology

Object–oriented databases

Copyright By PowCoder代写 加微信 powcoder

Information modelling
& database systems

in the previous lecture we learnt how we can use an object oriented language such as Java to communicate with a RDBMS
in this lecture we will focus on the discrepancies between object oriented and relational data models
we will introduce a new type of databases – object oriented databases
for more information:
Database Systems: The Complete Book by -Molina, and

Relational vs. object–oriented model
relational data model (1970s)
good for administrative and transactional data
not as good for other types of complex data,
e.g. multimedia, CAD, spatial data, etc.
object–oriented (OO) model (1980s)
complicated, but popular
naturally supports complex data types
idea: build a DBMS based the OO model

Relational vs. object–oriented model
relations are the key concept
primitive data types, e.g. string, integer, date, etc.
mathematical theory
great performance: query optimization
drawbacks:
handling of complex objects
handling of complex data types
code is not coupled with data
no inherence, encapsulation, etc.

Relational vs. object–oriented model
at query time, things are put back together

Two approaches
object–oriented databases (OODB)
pure OO concepts
object–relational databases (ORDB)
relational model with OO concepts

Database development
conceptual design
implementation
maintenance

Database development
ER diagram
UML class diagram
relational model
object–relational model
object–oriented model
SQL table definitions
extended SQL table definitions
mapping onto relations
mapping onto relations
mapping directly onto classes
normalisation & physical design
normalisation & physical design
optimisation

Object–oriented model
object–oriented DBMS(OODBMS) are DBMS based on an object–oriented data model inspired by OO programming languages
relations are no longer central concepts, classes and objects are
main features:
powerful type system
object identity
inheritance
OODBMS are capable of storing complex objects, i.e. those that are composed of other objects and/or multi-valued attributes

Feature 1: powerful type system
primitive type
integer, string, date, Boolean, float …
structure type
attribute can be a record with a schema, e.g.
Struct{integer x, string y}
collection type
attribute can be a set, bag, list, array of other types
reference type
attribute can be a pointer to another object

Feature 2: classes
classes replace relations
same concept as in OO programming languages
all objects belonging to a same class share the same properties & behaviour
an object can be thought of as tuple
… but with richer content
classes encapsulate data, methods & relationships
… unlike relations, which contain data only

Feature 3: object identity
OID is a unique identity of each object regardless of its content
even if all attributes are the same, objects will still have different OIDs
easier for referencing
an object is made of two things:
state attributes, e.g. name, address, birth date
of a person
behaviour operations, e.g. age of a person can be computed from birth date and current date

Feature 4: inheritance
a class can be defined in terms of another one
Person is super–class
Student is sub–class
Student class inherits attributes and operations from Person

Standards for OO model
Object Data Management Group ODMG, 1991
provide a standard where previously there was none
support portability between products
standardise model, querying & programming issues
completed its work on object data management standards in 2001 and was disbanded

ODMG Standard


languages:
Object Definition Language ODL
Object Query Language OQL

Object Definition Language (ODL)

Classes & attributes
class Movie
attribute string title;
attribute integer year;
attribute string length;
attribute enum Film {colour, blackandWhite} filmType;

class Star
attribute string name;
{string street, string city, string postcode} address;

Relationships
class Movie
attribute string title;
attribute integer year;
attribute string length;
attribute enum Film {colour, blackandWhite} filmType;
relationship Set stars

class Star
attribute string name;
{string street, string city, string postcode} address;

Set set of unsorted objects
Bag like Set, but with
possible duplication
List a sorted list
Array a sort list referenced

Inverse relationships
class Movie
attribute string title;
attribute integer year;
attribute string length;
relationship Set stars inverse Star::starredIn;
relationship Studio ownedBy inverse Studio::owns;
class Star
attribute string name;
attribute string address;
relationship Set starredIn inverse Movie::stars;
class Studio
attribute string name;
attribute string address;
relationship Set owns inverse Movie::ownedBy;

Cardinality of relationships
class Movie
attribute string title;
attribute integer year;
attribute string length;
relationship Set stars inverse Star::starredIn;
relationship Studio ownedBy inverse Studio::owns;
class Star
attribute string name;
attribute string address;
relationship Set starredIn inverse Movie::stars;
class Studio
attribute string name;
attribute string address;
relationship Set owns inverse Movie::ownedBy;

many–to–many
one–to–many
based on the use of collection types: Set, Bag, List and Array

class Movie
attribute string title;
attribute integer year;
attribute string length;
attribute enum {colour, blackAndWhite} filmType;
relationship Set stars inverse Star::starredIn;
relationship Studio ownedBy inverse Studio::owns;
float lengthInHours() raises(noLengthfound);
void starNames(out Set);
void otherMovies(in Star, out Set) raises(noSuchStar);

three method declarations
parameters are either in, out or inout
definition (implementation) is not part of the class

Inheritance
same idea as in OO programming, e.g. Java
subclass inherits all attributes, relationships & methods from its superclass
… plus adds additional ones
class Romance extends Movie
{relationship Set soundtrack};
class Comedy extends Movie
{attribute laughPerMinute float};
class RomCom extends Comedy : Romance;

inherits from two classes

Object Query Language (OQL)

Object Query Language (OQL)
OQL is a language designed to query databases described in ODL
tries to bring some concepts from the relational model to the ODBMs, e.g. SELECT statement, join, aggregation, etc.
references class properties (attributes, relationships, and methods) using:
dot notation e.g. movie.star
arrow notation e.g. movie->star
the two notations are equivalent

OQL overview
queries/subqueries: SELECT … FROM … WHERE
return types: bags, sets or lists
object creation: new objects as well as those
returned from queries
operators on
sets or bags: UNION, INTERSECT, EXCEPT
quantifiers : FOR ALL, EXISTS
aggregation: COUNT, MAX, MIN, AVG, SUM
grouping: GROUP BY with HAVING

When was “Gone with the wind” released?
SELECT m.year
FROM Movie m
WHERE m.title =
“Gone with the wind”;
Who starred in “Casablanca”?
SELECT s.name
FROM Movie m, m.stars s
WHERE m.title = “Casablanca”;
SELECT s.name
FROM m IN Movie, s IN m.stars
WHERE m.title = “Casablanca”;

Who starred in movies owned by “Disney”?
SELECT DISTINCT s.name
FROM Movie m, m.stars s
WHERE m.OwnedBy.name = “Disney”;
SELECT DISTINCT s.name
FROM Movie m
WHERE m.OwnedBy.name = “Disney”
) d, d.stars s;

Quantifiers
Who starred in a movie owned by “Disney”?
FROM Star s
WHERE EXISTS m IN s.starredIn :
m.OwnedBy.name = “Disney”;
Who starred only in movies owned by “Disney”?
FROM Star s
WHERE FOR ALL m IN s.starredIn :
m.OwnedBy.name = “Disney”;

order movies owned by “Disney” by their length & title
FROM Movie m
WHERE m.OwnedBy.name = “Disney”
ORDER BY m.length, m.title;

Which stars live together?
SELECT DISTINCT
Struct(star1: s1, star2: s2)
FROM Star s1, Star s2
WHERE s1.address = S2.address
AND s1.name < s2.name; SQL outputs relations OQL outputs collections (e.g. set, bag, list) of elements elements can be of any type, e.g. SELECT DISTINCT s.name FROM Movies m, m.stars s WHERE m.OwnedBy.name = "Disney"; FROM Movies m WHERE m.OwnedBy.name = "Disney" ORDER BY m.length; SELECT DISTINCT Struct(star1: s1, star2: s2) FROM Stars s1, Stars s2 WHERE s1.address = S2.address AND s1.name < s2.name; Aggregation What is the total annual length of all movies filmed by each studio? SELECT stdo, yr, sumLength: SUM(SELECT p.m.length FROM partition p) FROM Movie m GROUP BY stdo: m.OwnedBy.name, yr: m.year; OQL & programming languages SQL languages suffer from impedance mismatch when we try to connect them to programming languages such as Java the data models of SQL and Java are radically different OQL is an attempt by the OO community to extend procedural languages like Java with declarative SQL–like statements OQL and OO programming languages use the same data model, so they fit naturally returned objects are assigned to variables in the host program movieList = SELECT m FROM Movie m ORDER BY m.title, m.year; number0fMovies = COUNT(Movie); for(i=O; iCS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com