Dbms
Dbms
Suppose we need make all data in a Java program persistent. What are our options?
Operational definition: 1st Normal Form Database consists of relations (tables) Relations are composed of tuples (rows) Tuples are composed of attributes Attributes are constrained by domains Domains are primitive (non-structured) data types
Object databases replace the relational data model with an object-based or object-oriented data model Database consists of class extents (sets of objects) Extents are composed of objects Objects are composed of attributes Attribute values are constrained by data types Data types have arbitrary complexity and structure
ODL
ODL processor
schema (classes)
data (objects)
access structures
Early OODBMS vendors based their systems on several different object models:
Versant, ONTOS: persistent C++ objects O2: object model based on complex value theory Others: persistent Smalltalk objects, Objective-C, etc.
usual OO things: classes, attributes, methods, inheritance database things: relationships, extents, collections, transactions, DBMS control
Languages:
Object Definition Language: ODL Object Query Language: OQL Object Manipulation Language: OML
name DOG
breed OWNS
name PERSON 1
addr phone
license
CREATE TABLE PERSON ( name VARCHAR(20) NOT NULL, addr VARCHAR(50) NOT NULL, phone CHAR(10) NOT NULL; CONSTRAINT PERSON_PK PRIMARY KEY(phone) );
Since phone is the primary key, it becomes the thing that identifies a person.
CREATE TABLE DOG ( name VARCHAR(20) NOT NULL, breed VARCHAR(15) NOT NULL, license VARCHAR(10) NOT NULL; owner_phone CHAR(10) NOT NULL, CONSTRAINT DOG_PK PRIMARY KEY(license), CONSTRAINT DOG_FK FOREIGN KEY (owner_phone)REFERENCES PERSON(phone) );
A dog is identified by its license number. A dog's owner is identified by his/her phone number, since that is a person's primary key.
PERSON phone 222-7777 111-2222 333-9999 name Harsha Charlie Regina addr 22 Lake 16 Pine 801 F
DOG
license 001 004 003 012 name Snoopy Ace Rover Spot breed beagle shepherd poodle mutt owner_phone 111-2222 222-7777 222-7777 333-9999
SELECT P.NAME FROM PERSON AS P, DOG AS D WHERE D.NAME = "Snoopy" AND D.owner_phone = P.phone;
SELECT D.NAME FROM PERSON AS P, DOG AS D WHERE P.NAME = "Harsha" AND D.owner_phone = P.phone;
name DOG
breed OWNS
name PERSON 1
address phone
license
class PERSON (extent people, key phone) { attribute string name; attribute string phone; attribute string addr; relationship set<PET> owns inverse PET::owner; };
extent: set of all instances of the class key: attribute is unique among all instances (not a primary key)
name DOG
breed OWNS
name PERSON 1
address phone
license
class DOG (extent dogs, key license) { attribute string name; attribute string breed; attribute string license; relationship PERSON owner inverse PERSON::owns; };
relationships are references to other objects the inverse relationship implies a consistency constraint
class PERSON : public d_Object { private: d_String name; d_String addr; d_String phone; d_Rel_Set<DOG, "owner"> owns; }; d_Set<d_Ref<PERSON> > people;
the class extent is a set of references
all classes inherit from d_Object (database object) one side of the relationship, defined as a set of relationship references
class DOG : public d_Object { private: d_String name; d_String breed; d_String license; d_Ref_Ref<PERSON, "owns"> owner; }; d_Set<d_Ref<DOG> > dogs;
P188 Charlie 16 Pine 111-2222 {D996} D643 Spot mutt 012 P080
dogs
persons
dogs
persons
P188 Charlie 16 Pine 111-2222 {D996} D643 Spot mutt 012 P080
dogs
persons
P188 Charlie 16 Pine 111-2222 {D996} D643 Spot mutt 012 P080
dogs
persons
The DBMS is responsible for maintaining the consistency of relationships Suppose Regina sells her dog to Harsha:
d_Ref<Person> regina = people.select_element("name='Regina'"); d_Ref<Person> harsha = people.select_element("name='Harsha'"); d_Ref<Dog> spot = regina->owns.select_element("name='Spot'"); regina->owns.clear(); harsha->owns.insert_element(&spot);
P352 D643
harsha
P080
regina
regina->owns.clear();
harsha
regina
harsha->owns.insert_element(&spot);
spot
P352
D643
regina
harsha
P080
Mechanism to specify object-identity Mechanism for encapsulation of operations Mechanism to support inheritance
An array type is specified for attributes whose values are collections Similar to ER multi-valued attribute
Example:
CREATE TYPE Comp_type AS ( comp_name VARCHAR (2), location VARCHAR (20) ARRAY [10] );
A user-defined type can also be used to specify the row types of a table:
CREATE TABLE Company OF Comp_type( REF IS comp_id SYSTEM GENERATED, PRIMARY KEY (comp_name));
Options:
CREATE TYPE Employment_type AS ( employee REF (Emp_type) SCOPE (Employee), company REF (Comp_type) SCOPE (Company));
Keyword SCOPE specifies the table whose tuples can be referenced by a reference attribute
e.company->comp_name
A construct similar to the class definition Users can create a named user-defined type with its own methods in addition to attributes:
CREATE TYPE Addr_type AS ( street VARCHAR (45), city VARCHAR (25), zip CHAR (5) ) METHOD apt_no ( ) RETURNS CHAR(8);
METHOD CREATE FUNCTION apt_no() RETURNS CHAR(8) FOR Addr_type AS EXTERNAL NAME x/y/aptno.class LANGUAGE java;
Manager_type inherits all features of Emp_type and has an additional attribute called dept_managed