burapha university, 2003 object-oriented analysis basic of object mapping to relational database

18
Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Upload: marylou-sharp

Post on 13-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented Analysis

Basic of Object Mapping to Relational Database

Page 2: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisMapping Classes to Mapping Classes to TablesTables•Class

•map class to table •Mapping Class to table

•map 1 Class to 1 Table•map multiple Classes to 1 Table

•map multiple Classes to multiple Tables

Page 3: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisMapping Attributes to Mapping Attributes to ColumnsColumns•Class Attributes

•map class Attribute to column

•map Column to 0 column or more

Page 4: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisMapping Classes to 1 Mapping Classes to 1 TableTable

BankAccount

- balance : double

+ getBalance( ) : double+ deposit(amt : double)+ withdraw(amt : double)

BankAccount

BankAccountIDbalance

Page 5: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisMapping Classes to 1 Mapping Classes to 1 TableTable

Address

- Street : String- unitNumber : String- city : String- state : String

+ toString( ) : String

ZipCode

- number : String

+ toString( ) : String+ validate( ) : String

has

Address

addressIDStreetunitNumbercitystatezipcode

Page 6: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisMapping Classes to Mapping Classes to TablesTables

Address

- Street : String- unitNumber : String- city : String- state : String

+ toString( ) : String

ZipCode

- number : String

+ toString( ) : String+ validate( ) : String

has

Address

addressIDStreetunitNumbercitystatezipcodeID (FK)

Zipcode

zipcodeIDzipnumber

Page 7: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented Analysis

Mapping RelationshipMapping Relationship• Relationship and Foreign Key• use Foreign Key to maintain relationship between 1

record in one table and another record in another table

• Relationship • One-to-One• One-to-Many and Many-to-One• Many-to-Many

Page 8: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisImplementing One-to-Implementing One-to-One RelationshipOne Relationship

Position

- title : String- salaryRange : double

+ toString( ) : String

Employee

- name : String- salary : double- startDate : Date

+ toString( ) : String+ updateSalary( ) :String

work at

1 1

Position

positionIDtitleRange

Employee

employeeIDPositionID(FK)namesalarystartDate

Page 9: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisImplementing One-to-Implementing One-to-Many RelationshipMany Relationship

Employee

- name : String- salary : double

- startDate : Date

+ toString( ) : String+ updateSalary( ) :String

Job

- description : String

+ toString( ) : String

assigned to

1*

Employee Job

jobID

description

employeeIDnamesalary

startDatejobID(FK)

Page 10: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisImplementing Many-to-Implementing Many-to-Many RelationshipMany Relationship

Customer

- customeID : String- name : String- preference : String

+ toString( ) : String

Account

- accountID : String- balance : double

+ toString( ) : String+ withdraw(b:double ) : void+ deposit(b:double ) : void

acceses

1..n 1..n

Customer

customerIDnamepreference

Account

accountIDbalance : double

Access

objectIDCustomerID (FK)accountID (FK)

Page 11: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisMapping a class Mapping a class inheritance treeinheritance tree• Startegies

•Vertical Mapping•Horizontal Mapping•Filtered Mapping

Page 12: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisOne Table per Concrete One Table per Concrete Class (Horizonal Class (Horizonal

Mapping)Mapping)

Employee

employeeIDnameaddressphoneNostartDatesalary

Customer

customerIDnameaddressphoneNopreference

Person

- personID : String- name : String- address : String- phoneNo : String

Employee

- employeeID : String- startDate : String- salary : double

Customer

- customerID : String- preference : String

Page 13: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisOne Table per Class One Table per Class (Vertical Mapping)(Vertical Mapping)

Person

personIDnameaddressphoneNo

Employee

employeeIDpersonID (FK)startDatesalary

Customer

customerIDpersonID (FK)preference

Person

- personID : String- name : String- address : String- phoneNo : String

Employee

- employeeID : String- startDate : String- salary : double

Customer

- customerID : String- preference : String

Page 14: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented Analysis

SELECT employee.ID, p.name, p.address, e.startDate, e.salaryFROM Person p, Employee eWHERE e.personID=p.personID AND e.personID=100;

Person

personIDnameaddressphoneNo

Employee

employeeIDpersonID (FK)startDatesalary

Customer

customerIDpersonID (FK)preference

instantiating an employee object with OID=100 requires a join of the Person and Employee tables:

Page 15: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisOne Table per Hierarchy One Table per Hierarchy (Filtered)(Filtered)

Person

- personID : String- name : String- address : String

- phoneNo : String

Employee

- employeeID : String- startDate : String- salary : double

Customer

- customerID : String- preference : String

Person

IDnameaddress

phoneNoTypestartDatesalarypreferencesobjectType

Page 16: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented Analysis

SELECT ID, name, address, phoneNo, startDate, salaryFROM Person WHERE Type=1;

The Type column is used as a filter used to distinguish the type of object being stored. For example, assuming that a Type=1 is used for employees, then to retrieve all employees from the Person table we can issue the following query:

Person

IDnameaddressphoneNoTypestartDatesalarypreferencesobjectType

Page 17: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented AnalysisComparing approaches Comparing approaches to mapping Inheritanceto mapping Inheritance

Factors to ConsiderOne table per

hierarchy(Filtered Mapping)

One table per Class(Vertical Mapping)

Reporting

Ease of Implementation

Ease of data access

Coupling

Speed of data access

Support for polymorphism

Simple

Medium / Difficult

Simple

Simple

Difficult

Simple / Medium

Very High Low

Fast Medium / Fast

Medium High

One table perConcrete Class

(Horizontal Mapping)

Medium

Medium

Simple

High

Fast

Low

Page 18: Burapha University, 2003 Object-Oriented Analysis Basic of Object Mapping to Relational Database

Burapha University, 2003

Object-Oriented Analysis

SummarySummary•Basic of mapping object to

Relatoinal Database