ODL Sub classes F ollo w name of sub class b y colon and - - PDF document

odl sub classes f ollo w name of sub class b y colon and
SMART_READER_LITE
LIVE PREVIEW

ODL Sub classes F ollo w name of sub class b y colon and - - PDF document

ODL Sub classes F ollo w name of sub class b y colon and its sup erclass. Example: Ales are Beers with a Color class Ales:Beers { attribute string color; } Ob jects of the class acquire all the Ales


slide-1
SLIDE 1 ODL Sub classes F
  • llo
w name
  • f
sub class b y colon and its sup erclass. Example: Ales are Beers with a Color class Ales:Beers { attribute string color; }
  • Ob
jects
  • f
the Ales class acquire all the attributes and relationships
  • f
the Beers class.
  • While
E/R en tities can ha v e manifestations in a class and sub class, in ODL w e assume eac h
  • b
ject is a mem b er
  • f
exactly
  • ne
class. 1
slide-2
SLIDE 2 Keys in ODL Indicate with key(s) follo wing the class name, and a list
  • f
attributes forming the k ey .
  • Sev
eral lists ma y b e used to indicate sev eral alternativ e k eys.
  • P
aren theses group mem b ers
  • f
a k ey , and also group key to the declared k eys.
  • Th
us, (key(a 1 ; a 2 ; : : : ; a n )) = \one k ey consisting
  • f
all n attributes." (key a 1 ; a 2 ; : : : ; a n ) = \eac h a i is a k ey b y itself." Example class Beers (key name) { attribute string name ...
  • R
ememb er : Keys are
  • ptional
in ODL. The \ob ject ID" suces to distinguish
  • b
jects that ha v e the same v alues in their elemen ts. 2
slide-3
SLIDE 3 Example: Multiple Multiattribut e Keys class Courses (key (dept, number), (room, hours)) { ... 3
slide-4
SLIDE 4 T ranslating ODL to Relations 1. Classes without relationships: lik e en tit y set, but sev eral new problems arise. 2. Classes with relationships: a) T reat the relationship separately , as in E/R. b) A ttac h a man y-one relationship to the relation for the \man y ." 4
slide-5
SLIDE 5 ODL Class Without Relationships
  • Problem:
ODL allo ws attribute t yp es built from structures and collecti
  • n
t yp es.
  • Structure:
Mak e
  • ne
attribute for eac h eld.
  • Set:
mak e
  • ne
tuple for eac h mem b er
  • f
the set.

More than
  • ne
set attribute? Mak e tuples for all com binations.
  • Problem:
ODL class ma y ha v e no k ey , but w e should ha v e
  • ne
in the relation to represen t \OID." 5
slide-6
SLIDE 6 Example class Drinkers (key name) { attribute string name; attribute Struct Addr {string street, string city, int zip} address; attribute Set<string> phone; } name street cit y zip phone n 1 s 1 c 1 z 1 p 1 n 1 s 1 c 1 z 1 p 2
  • Surprise:
the k ey for the class (name) is not the k ey for the relation (name, phone).

name in the class determines a unique
  • b
ject, including a set
  • f
phones.

name in the relation do es not determine a unique tuple.

Since tuples are not iden tical to
  • b
jects, there is no inconsistency!
  • BCNF
violati
  • n:
separate
  • ut
name-phone. 6
slide-7
SLIDE 7 ODL Relationships
  • If
the relationship is man y-one from A to B , put k ey
  • f
B attributes in the relation for class A.
  • If
relationship is man y-man y , w e'll ha v e to duplicate A-tuples as in ODL with set-v alued attributes.

W
  • uldn't
y
  • u
really rather create a separate relation for a man y-man y- relationship?

Y
  • u'll
wind up separating it an yw a y , during BCNF decomp
  • sition.
7
slide-8
SLIDE 8 Example class Drinkers (key name) { attribute string name; attribute string addr; relationship Set<Beers> likes inverse Beers::fans; relationship Beers favorite inverse Beers::realFans; relationship Drinkers husband inverse wife; relationship Drinkers wife inverse husband; relationship Set<Drinkers> buddies inverse buddies; } Drink ers(name, addr, b eerName , fa vBeer, wife, budd y) 8
slide-9
SLIDE 9 Decomp
  • se
in to 4NF
  • FD's:
name!addr fa vBeer wife
  • MVD's
name! ! b eerName, name! ! buddy
  • Resulting
decomp
  • sition:
Drinkers(name , addr, favBeer, wife) DrBeer(name , beer ) DrBuddy(name , buddy) 9
slide-10
SLIDE 10 OQL Motiv atio n:
  • Relational
languages suer from imp e danc e mismatch when w e try to connect them to con v en tional languages lik e C
  • r
C++.

The data mo dels
  • f
C and SQL are radically dieren t, e.g. C do es not ha v e relations, sets,
  • r
bags as primitiv e t yp es; C is tuple-at-a-time, SQL is relation-at-a- time.
  • OQL
is an attempt b y the OO comm unit y to extend languages lik e C++ with SQL-lik e, relation-at-a-time dictions. 10
slide-11
SLIDE 11 OQL T yp es
  • Basic
t yp es: strings, in ts, reals, etc., plus class names.
  • T
yp e constructors:

Struct for structures.

Collecti
  • n
t yp es: set, bag, list, arra y .
  • Lik
e ODL, but no limit
  • n
the n um b er
  • f
times w e can apply a t yp e constructor.
  • Set(Struct())
and Bag(Struct()) pla y sp ecial roles akin to relations. 11
slide-12
SLIDE 12 OQL Uses ODL as its Sc hema-Denition P
  • rtion
  • F
  • r
ev ery class w e can declare an extent = name for the curren t set
  • f
  • b
jects
  • f
the class.

Remem b er to refer to the exten t, not the class name, in queries. 12
slide-13
SLIDE 13 class Bar (extent Bars) { attribute string name; attribute string addr; relationship Set<Sell> beersSold inverse Sell::bar; } class Beer (extent Beers) { attribute string name; attribute string manf; relationship Set<Sell> soldBy inverse Sell::beer; } class Sell (extent Sells) { attribute float price; relationship Bar bar inverse Bar::beersSold; relationship Beer beer inverse Beer::soldBy; } 13
slide-14
SLIDE 14 P ath Expressions Let x b e an
  • b
ject
  • f
class C .
  • If
a is an attribute
  • f
C , then x:a = the v alue
  • f
a in the x
  • b
ject.
  • If
r is a relationship
  • f
C , then x:r = the v alue to whic h x is connected b y r .

Could b e an
  • b
ject
  • r
a collect i
  • n
  • f
  • b
jects, dep ending
  • n
the t yp e
  • f
r .
  • If
m is a metho d
  • f
C , then x:m(
  • )
is the result
  • f
applying m to x. 14
slide-15
SLIDE 15 Examples Let s b e a v ariable whose t yp e is Sell.
  • s.price
= the price in the
  • b
ject s.
  • s.bar.addr
= the address
  • f
the bar men tioned in s.

Note: cascade
  • f
dots OK b ecause s.bar is an
  • bje
ct, not a collecti
  • n.
Example
  • f
Illegal Use
  • f
Dot b.beersSold.price, where b is a Bar
  • b
ject.
  • Wh
y illegal ? Because b.beersSold is a set
  • f
  • b
jects, not a single
  • b
ject. 15
slide-16
SLIDE 16 OQL Select-F rom-Where SELECT <list
  • f
v alues> FROM <list
  • f
collecti
  • ns
and t ypical mem b ers> WHERE <condition>
  • Collecti
  • ns
in FROM can b e: 1. Exten ts. 2. Expressions that ev aluate to a collecti
  • n.
  • F
  • llo
wing a collecti
  • n
is a name for a t ypical mem b er,
  • ptionally
preceded b y AS. Example Get the men u at Jo e's. SELECT s.beer.name, s.price FROM Sells s WHERE s.bar.name = "Joe's Bar"
  • Notice
double-quoted strings in OQL. 16
slide-17
SLIDE 17 Example Another w a y to get Jo e's men u, this time fo cusing
  • n
the Bar
  • b
jects. SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar"
  • Notice
that the t ypical
  • b
ject b in the rst collecti
  • n
  • f
FROM is used to help dene the second collecti
  • n.
T ypical Usage
  • If
x is an
  • b
ject, y
  • u
can extend the path expression, lik e s
  • r
s.beer in s.beer.name.
  • If
x is a collect i
  • n,
y
  • u
use it in the FROM list, lik e b.beersSold ab
  • v
e, if y
  • u
w an t to access attributes
  • f
x. 17
slide-18
SLIDE 18 T ailoring the T yp e
  • f
the Result
  • Default:
bag
  • f
structs, eld names tak en from the ends
  • f
path names in SELECT clause. Example SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" has result t yp e: Bag(Struct( name: string, price: real )) 18
slide-19
SLIDE 19 Rename Fields Prex the path with the desired name and a colon. Example SELECT beer: s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" has t yp e: Bag(Struct( beer: string, price: real )) 19
slide-20
SLIDE 20 Change the Collectio n T yp e
  • Use
SELECT DISTINCT to get a set
  • f
structs. Example SELECT DISTINCT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar"
  • Use
ORDER BY clause to get a list
  • f
structs. Example joeMenu = SELECT s.beer.name, s.price FROM Bars b, b.beersSold s WHERE b.name = "Joe's Bar" ORDER BY s.price ASC
  • ASC
= ascending (default); DESC = descending.
  • W
e can extract from a list as if it w ere an arra y , e.g. cheapest = joeMenu[1].name; 20