ch20 22
ch20 22
ODMG Model
- Name – unique name within database – sometimes used as entry points to database
- Literals – 3 types
- Built-in operations:
- Create_iterator() – creates iterator object that can iterate over each element in
collection
- Next_position(), get_element()
- All objects in the ODMG object model inherit the basic interface Object
- delete
Class Product
( extent all_products
key prod_num)
{
attribute string name;
attribute string prod_num;
attribute string description;
attribute date date_produced;
attribute enum Color{red, blue, green, yellow} color;
attribute set struct Parts {
int quantity,
Part part
} parts;
relationship Purchased Item is_for
inverse PurchasedItem::is_for;
void add_product(string name, string prod_num)
raises (prod_name_not_valid);
void add_part(Part new_part);
}
- ex: In a parts-suppliers database (see EER handout) – specify object type for Product object
- relationship – property that specifies two objects in DB are related to each other
- some relationships (ER type) are modeled as an attribute in an object (ex: parts)
- non-instantiable
- used for specifying abstract operations that will be inherited by classes or other interfaces
- instantiable
- can have multiple inheritance by inheriting any number of interfaces, and at most one class
- Extents
- Keys
- key consists of one or more properties (attributes or relationships) whose values are constrained to
- Factory Object
- Database
- interface Database
- several possible mappings from an object schema diagram (ER or EER) into ODL classes
- some sample queries here – we won’t have time for too much detail
- Sample queries
FROM P IN PRODUCTS
- entry point to database needed for a query – any named persistent object
- in general – result of a query is a bag for select ... from set for select distinct ... from
Q1: products
- any persistent name is a query – result is a reference to that object
- if we give a particular product object a name – “widget” – through bind – we could do the following
Q1a: widget
- Once an entry point is specified – path expression can be used to specify a path to related attributes
Q2: widget.color
Q2a: widget.parts
Q2b: widget.is_for
- can specify a query that results in a complex structure using struct keyword
Q3: order123.customer.custname
from c in order123.customer
SELECT P
FROM P IN PRODUCTS
WHERE P.COLOR = color
from p in products
- guaranteed to return a single element – if more than one is in the result, exception is raised
from pi in PurchasedItem
- membership condition
from c in customer
where “blue” in
(select p.name
from p in c.orders.consists_of.is_for)
-