1 CS 432 Object-Oriented Analysis and Design Week 3 The Design Model.
Object Oriented Analysis and Design 1 Chapter 7 Database Design UML Specification for Data Modeling...
-
Upload
paul-arnold -
Category
Documents
-
view
213 -
download
0
Transcript of Object Oriented Analysis and Design 1 Chapter 7 Database Design UML Specification for Data Modeling...
Object Oriented Analysis and Design 1
Chapter 7 Database Design UML Specification for Data Modeling The Relational Data Model and Object Model Persistence Frameworks Database Design
Object Oriented Analysis and Design 2
UML Specification for Data Modeling
Object Oriented Analysis and Design 3
7.1 UML Specification for Data Modeling UML Notation for Data Modeling Modeling Associations in the Data Model Modeling Aggregation in the Data Model Modeling Inheritance in the Data Model
Object Oriented Analysis and Design 4
UML Notation for Data Modeling
Object Oriented Analysis and Design 5
Modeling Associations in the Data Model Associations between two persistent objects
are realized as foreign keys to the associated objects. A foreign key is a column in one table which
contains the primary key value of associated object
Number Course_ID
678 456789
Name Description Number
Math 101 Algebra 456789
Course Offering table
Course tableCourse
- name- description
- number
CourseOffering
- number : String
0..*0..*
1
Primary Key
Foreign Key
Object Oriented Analysis and Design 6
Modeling Aggregation in the Data Model Aggregation is also modeled using foreign
key relationships Using composition implements a cascading
delete constraint
Student.
- studentID : int
Schedule
- semester : Semester
0..*
1
0..*
1
Student_ID Semester
123456 Spring 2001
Schedule table
Student_ID
123456
Foreign Key
Primary Key
Student table
Object Oriented Analysis and Design 7
Modeling Inheritance in the Data Model A data model does not support modeling
inheritance in a direct way Two options
Use separate tables (normalized data) Duplicate all inherited associations and
attributes (de-normalized data)
Object Oriented Analysis and Design 8
Modeling Inheritance in the Data Model - Example
Personname : Stringage : int
CitizenpassportNumber : int
Residentnationality : StringvisaType : String
Object Oriented Analysis and Design 9
Modeling Inheritance in the Data Model - Example
CitizenpassportNumber : SMALLINTperson_ID : SMALLINT
<<PK>> PK_Citizen1()<<FK>> FK_Citizen0()
Personperson_ID : SMALLINTage : SMALLINTname : VARCHAR(32)type : SMALLINT
<<PK>> PK_Person0()<<Unique>> TC_Person0()
0..11 0..11
<<Identifying>>
Residentnationality : VARCHAR(255)visaType : VARCHAR(255)person_ID : SMALLINT
<<PK>> PK_Resident2()<<FK>> FK_Resident1()
0..1
1
0..1
1
<<Identifying>>
Object Oriented Analysis and Design 10
Modeling Inheritance in the Data Model - Example
CitizenpassportNumber : SMALLINTperson_ID : SMALLINTname : VARCHAR(32)age : SMALLINT
<<PK>> PK_Citizen1()<<FK>> FK_Citizen0()
Personperson_ID : SMALLINTage : SMALLINTname : VARCHAR(32)
<<PK>> PK_Person0()<<Unique>> TC_Person0()
0..11 0..11
<<Identifying>>
Residentnationality : VARCHAR(255)visaType : VARCHAR(255)person_ID : SMALLINTname : VARCHAR(32)age : SMALLINT
<<PK>> PK_Resident2()<<FK>> FK_Resident1()
0..1
1
0..1
1
<<Identifying>>
Object Oriented Analysis and Design 11
Modeling Inheritance in the Data Model - Example
Personperson_ID : SMALLINTage : SMALLINTname : VARCHAR(32)type : SMALLINTpassportNumber : SMALLINTnationality : VARCHAR(255)visaType : VARCHAR(255)
<<PK>> PK_Person0()<<Unique>> TC_Person0()
Object Oriented Analysis and Design 12
Modeling Inheritance in the Data Model - Example
Object Oriented Analysis and Design 13
The Relational Data Model and Object Model
Object Oriented Analysis and Design 14
7.2 The Relational Data Model and Object Model The Relational Data Model The Object Model
Object Oriented Analysis and Design 15
The Relational Data Model The relational model is composed of entities and relations.
An entity may be a physical table or a logical projection of several tables also known as a view.
Object Oriented Analysis and Design 16
The Object Model An object model contains classes. Classes define the structure
and behavior of a set of objects, sometimes called objects instances. The structure is represented as attributes (data values) and associations (relationships between classes).
Object Oriented Analysis and Design 17
The Persistence Frameworks
Object Oriented Analysis and Design 18
7.3 Persistence Frameworks The Purpose of a Persistence Framework Hibernate
Object Oriented Analysis and Design 19
The Purpose of a Persistence Framework
Object Oriented Analysis and Design 20
Hibernate Object / Relational mapping (ORM) and persistence /
query framework i.e. It does even more stuff for you!
Some features of Hibernate HibernateDaoSupport – superclass, easy HibernateTemplate access Database independence - sits between the database and your java code,
easy database switch without changing any code Object / Relational Mapping (ORM) - Allows a developer to treat a database
like a collection of Java objects Object oriented query language (HQL) - *Portable* query language,
supports polymorphic queries etc. You can also still issue native SQL, and also queries by “Criteria”
(specified using “parse tree” of Java objects) Hibernate Mapping - Uses HBM XML files to map value objects (POJOs) to
database tables Transparent persistence - Allows easy saves/delete/retrieve for simple
value objects Very high performance “in general” due to intelligent (2-level) caching,
although in a few cases hand-written SQL might beat it
Object Oriented Analysis and Design 21
Hibernate Hibernate basically sits between the DB and
your code Can map persistent objects to tables
Object Oriented Analysis and Design 22
Database Design
Object Oriented Analysis and Design 23
7.4 Database Design Purpose Overview Steps Map persistent design classes to tables Distribute class behavior to the database
Object Oriented Analysis and Design 24
Purpose To ensure that persistent data is stored consistently
and efficiently. To define behavior that must be implemented in the
database.
Object Oriented Analysis and Design 25
Database Design Overview
SupplementarySpecifications
DatabaseDesign
Use-Case Realization
Design Classes
DesignGuidelines
Data Model
Object Oriented Analysis and Design 26
Steps Map Persistent Design Classes to the Data Model Optimize the Data Model for Performance Optimize Data Access Define Storage Characteristics Define Reference Tables Define Data and Referential Integrity Enforcement Rules Distribute Class Behavior to the Database Review the Results
Object Oriented Analysis and Design 27
Mapping Persistent Classes to Tables In a relational database
Every row is regarded as an object A column in a table is equivalent to a persistent
attribute of a class
Student
- name : String- address : String- studentID : Long
Name Student_ID
Thomas Stuart 123456
Object Instance
Attributes from object type
Object Oriented Analysis and Design 28
Mapping Persistent Classes to Tables - Example
Object Oriented Analysis and Design 29
Map Class Behavior to Stored Procedures Determine if any operations can be
implemented as a stored procedure Candidate operations
Deal with persistent data Any operations where a query is involved in a
computation Need to access the database to validate data
Object Oriented Analysis and Design 30
What Are Stored Procedures? A stored procedure is executable code
which runs under the RDBMS Two types of stored procedures
Procedures: Executed explicitly by an application
Triggers: Invoked implicitly when some database event occurs
Object Oriented Analysis and Design 31
Example: Map Class Behavior to Stored Procedures
Student.
+ getTuition()+ addSchedule()+ getSchedule()+ deleteSchedule()+ hasPrerequisites()# passed()<<class>> + getNextAvailID()+ getStudentID()+ getName()+ getAddress()
Class Candidate Operations• getTuition
• addSchedule
• getSchedule
• deleteSchedule
• getStudentID
• getName
• getAddress
Object Oriented Analysis and Design 32
Example: Map Class Behavior to Stored Procedures