OODB by Shantanu Narang

Download Report

Transcript OODB by Shantanu Narang

By
Shantanu Narang
CS 157b
 Relational Model  Object Model
 Object Oriented Databases(OOD)
 Object Query Language(OQL)
 OOD pros and cons
Relation database
Java Representation
Relation
Class
Tuple
Object
Composite Attribute
struct
Multi Valued Attributes
Collection Objects
Foreign Key
Reference to an Objects
•Preserve Referential Integrity(Important to update relationships)
Relation database
Java Representation
One to One
Store worksAt = new Store(“BB”, UC);
One to many
Employee.worksOn = new Set<Projects>();
Many to Many
Almost all ORMs do not support many to many
relationship. So most people have to hack there
way around it.
OR
An easier way is to represent an the M-t-M as an
entity class in the ERD.
// To make an employee a manager of a store
/*
*@param store is the store that the employee will manage
*@return whether transaction was completed.
*/
protected boolean createManagerRelationsShip(Store store)
{
if(store.getManager() != null) return false;
this.worksAt = store;// if different
this.setManagerOf(store);
store.setManager(this);
return true;
}
Single Inheritance
Class Employee extends Person
Multiple Inheritance
Not allowed in java!!
You have to create class variables, and
manipulate them.(p. 442)
Or
Let interfaces simulate classes
Three ways to do it:
1. Write to file(text files, serialization in java)
Impossible to load desired objects only.
2. Relational DBs.
3. Object DBs
 The traditional Relational DBMS stores data in tables,
rows, and columns
 Objects have several complex structures that cannot be
represented in tables, rows, or columns.
 These structures include executable statements (i.e.,
methods) and pointers
 An object database is a collection of persistent objects
that act like a database.
 Object-relational mapping (aka ORM, O/RM, and
O/R mapping) is a programming technique for
converting data between incompatible type systems in
relational databases and object-oriented programming
languages. This creates, in effect, a "virtual object
database" which can be used from within the
programming language.
 Ex. Hibernate, LINQ, nHibernate.
OO vs. RM DBs
 Based on SQL for an easier transition for
programmers.
 Not as explicit as SQL, does not have command
equivalent to the SQL-update.
 Example:
Select distinct e.ssn from Employees e where e.lastname =
“Booyaa”
 It will return a set<string> object.
 Select PayStatement(emp.id,
emp.hours * emp.hourlySalary)
from Employees emp
where emp.isTemp() == true;
#returns a set of new Paystatements
object for all tempEmps
 Supports
 Unions
 Intersections
 Except
 For all
 Exists
 Count
 Sum
 Nested statements
 Min
 Max
 Group by
 …………
The End