Chapter 10, Mapping Models to Relational Schema

Slides:



Advertisements
Similar presentations
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Advertisements

Chapter 15 A Table with a View: Database Queries.
Modeling the Data: Conceptual and Logical Data Modeling
Designing a Database Unleashing the Power of Relational Database Design.
© 2008 Pearson Prentice Hall, Experiencing MIS, David Kroenke
Chapter 11 Data Management Layer Design
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Distributed Databases
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Code.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 11: Data Management Layer Design Alan Dennis, Barbara.
Using MIS 4e Chapter 5 Database Processing
1 DATABASE TECHNOLOGIES BUS Abdou Illia, Fall 2007 (Week 3, Tuesday 9/4/2007)
Introduction to Accounting Information Systems
Concepts and Terminology Introduction to Database.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 6, System Design Lecture 2.
I Information Systems Technology Ross Malaga 4 "Part I Understanding Information Systems Technology" Copyright © 2005 Prentice Hall, Inc. 4-1 DATABASE.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 11: Data Management Layer Design Alan Dennis, Barbara.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Overview System Design II (slides Part B)
1 Relational Databases and SQL. Learning Objectives Understand techniques to model complex accounting phenomena in an E-R diagram Develop E-R diagrams.
Conquering Complex and Changing Systems Object-Oriented Software Engineering Chapter 6, System Design Lecture 2.
Fanny Widadie, S.P, M.Agr 1 Database Management Systems.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Software Engineering October 10, 2001 System.
Concepts of Database Management, Fifth Edition Chapter 6: Database Design 2: Design Methodology.
In this session, you will learn to: Map an ER diagram to a table Objectives.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 10, Mapping Models to Relational Schema.
Mapping Models to Code. We will skip most of this chapter –It deals with how to go from UML class diagrams to actual code –You should already have a pretty.
Database Basics BCIS 3680 Enterprise Programming.
Falak Nawaz Mapping Models to Code. Object Model activities 1. Reuse: Identification of existing solutions  Use of inheritance  Off-the-shelf components.
Bernd Bruegge & Allen Dutoit Object-Oriented Software Engineering: Conquering Complex and Changing Systems 1 Overview  System Design II 3. Concurrency.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
March 1, 2004CS WPI1 CS 509 Design of Software Systems Lecture #6 Monday, March 1, 2004.
CEN Tenth Lecture Introduction to Software Engineering (CEN-4010) Mapping Models to Code Instructor: Masoud Sadjadi
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
McGraw-Hill/Irwin Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Modeling the Data: Conceptual and Logical Data Modeling.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Copyright © 2014 Pearson Canada Inc. 5-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5a Database Design Part 2: Using Information Technology.
State of the Art: Model-based Software Engineering
Practical Database Design and Tuning
Relational Database Design by ER- and EER-to- Relational Mapping
Business System Development
Chapter 4 Logical Database Design and the Relational Model
Databases Chapter 16.
Chapter 2: Relational Model
Information Systems Today: Managing in the Digital World
Chapter 10, Mapping Models to Code
A Table with a View: Database Queries
CSCI-100 Introduction to Computing
Chapter 4 Relational Databases
Translation of ER-diagram into Relational Schema
CSCE 606: From Models to Implementation
Chapter 3 The Relational Database Model
Basic Concepts in Data Management
Teaching slides Chapter 8.
Physical Database Design
Practical Database Design and Tuning
Relational Database Design by ER- and EER-to-Relational Mapping
Session 2 Welcome: The seventh learning sequence
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Relationships as Primary & Foreign Keys
Adding Multiple Logical Table Sources
A Table with a View: Database Queries
CHAPTER 2 - Database Requirements and ER Modeling
Chapter 10, Mapping Models to Relational Schema
A Table with a View: Database Queries
MIS2502: Data Analytics Relational Data Modeling 3
Advance Software Engineering (CEN-5011)
The Entity-Relationship (ER) Model
© 2008 Pearson Prentice Hall, Experiencing MIS, David Kroenke
Presentation transcript:

Chapter 10, Mapping Models to Relational Schema

Lecture Plan Last lecture: This lecture: Operations on the object model: Optimizations to address performance requirements Implementation of class model components: Realization of associations This lecture: Realizing entity objects based on selected storage strategy, in particular Mapping the object model to a relational database Mapping class diagrams to tables Object design is situated between system design and implementation. Object design is not very well understood and if not well done, leads to a bad system implementation. In this lecture, we describe a selection of transformations to illustrate a disciplined approach to implementation to avoid system degradation

Mapping an Object Model to a Database UML object models can be mapped to relational databases: Some degradation occurs because all UML constructs must be mapped to a single relational database construct - the table Mapping of classes, attributes and associations Each class is mapped to a table Each class attribute is mapped onto a column in the table An instance of a class represents a row in the table A many-to-many association is mapped into its own table A one-to-many association is implemented as buried foreign key Methods are not mapped.

Mapping a Class to a Table User +firstName:String +login:String +email:String firstName:text[25] login:text[8] email:text[32] User table id:long

Primary and Foreign Keys Any set of attributes that could be used to uniquely identify any data record in a relational table is called a candidate key The actual candidate key that is used in the application to identify the records is called the primary key The primary key of a table is a set of attributes whose values uniquely identify the data records in the table A foreign key is an attribute (or a set of attributes) that references the primary key of another table. Litte Primer on Database concepts, a repeat for those of you that have already taken databases.

Example for Primary and Foreign Keys Primary key User tab le login email “am384” “am384@mail.org” “js289” “john@mail.de” fi r stName “alice” “john” “bd” “bobd@mail.ch” “bob” Candidate key Candidate key login “am384” “bd” name “tictactoeNovice” “tictactoeExpert” “js289” “chessNovice” League table Foreign key referencing User table

Buried Association Associations with multiplicity “one” can be implemented using a foreign key For one-to-many associations we add the foreign key to the table representing the class on the “many” end For all other associations we can select either class at the end of the association. 1 * LeagueOwner League owner o wner:long League table ... id:long id:long LeagueOwner table ...

Another Example for Buried Association Portfolio portfolioID ... Transaction transactionID * Transaction Table transactionID portfolioID ... Portfolio Table portfolioID Foreign Key

Mapping Many-To-Many Associations In this case we need a separate table for the association City cityName Airport airportCode airportName * Serves Separate table for the association “Serves” Primary Key cityName Houston Albany Munich Hamburg City Table airportCode IAH HOU ALB MUC HAM Airport Table airportName Intercontinental Hobby Albany County Munich Airport Hamburg Airport cityName Houston Albany Munich Hamburg Serves Table airportCode IAH HOU ALB MUC HAM

Another Many-to-Many Association Mapping We need the Tournament/Player association as a separate table * * Tournament Player id Tournament table 23 name ... no vice 24 e xper t Player table id 56 name ... alice 79 john tournament player TournamentPlayerAssociation table 23 56 79

Realizing Inheritance Relational databases do not support inheritance Two possibilities to map an inheritance association to a database schema With a separate table (”vertical mapping”) The attributes of the superclass and the subclasses are mapped to different tables By duplicating columns (”horizontal mapping”) There is no table for the superclass Each subclass is mapped to a table containing the attributes of the subclass and the attributes of the superclass

Realizing inheritance with a separate table (Vertical mapping) Player User LeagueOwner maxNumLeagues credits name User table id 56 name ... z oe 79 john r ole LeagueOwner Pla y er id LeagueOwner table 56 maxNumLeagues ... 12 Player table id 79 credits ... 126

Realizing inheritance by duplicating columns (Horizontal Mapping) Player User LeagueOwner maxNumLeagues credits name id LeagueOwner table 56 maxNumLeagues ... 12 name z oe Player table id 79 credits ... 126 name john

Comparison: Separate Tables vs Duplicated Columns The trade-off is between modifiability and response time How likely is a change of the superclass? What are the performance requirements for queries? Separate table mapping (Vertical mapping) We can add attributes to the superclass easily by adding a column to the superclass table Searching for the attributes of an object requires a join operation. Duplicated columns (Horizontal Mapping) Modifying the database schema is more complex and error-prone Individual objects are not fragmented across a number of tables, resulting in faster queries

Summary Four mapping concepts: Model transformation improves the compliance of the object design model with a design goal Forward engineering improves the consistency of the code with respect to the object design model Refactoring improves code readability/modifiability Reverse engineering discovers the design from the code. Model transformations and forward engineering techniques: Optimizing the class model Mapping associations to collections Mapping contracts to exceptions Mapping class model to storage schemas. Undisciplined change => degradation of system model

Backup and Example Slides