Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.

Slides:



Advertisements
Similar presentations
An Object/Relational Mapping tool Free and open source Simplifies storage of object data in a relational database Removes the need to write and maintain.
Advertisements

Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Object Relational Mapping. What does ORM do? Maps Object Model to Relational Model. Resolve impedance mismatch. Resolve mapping of scalar and non-scalar.
Geographic Information Systems
RELATIONSHIP  THE WAY TABLES ARE RELATED  A TABLE MUST PARTICIPATE IN AT LEAST ONE RELATIONSHIP  IN A BINARY RELATIONSHIP TWO ENTITIES PARTICIPATE 
Chapter 11 Data Management Layer Design
Chapter 4: Object-Oriented Data Modeling
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Academic Year 2014 Spring.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Chapter 14: Object-Oriented Data Modeling
Enterprise Object Framework. What is EOF? Enterprise Objects Framework is a set of tools and resources that help you create applications that work with.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
Introduction –All information systems create, read, update and delete data. This data is stored in files and databases. Files are collections of similar.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Concepts and Terminology Introduction to Database.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
6 Chapter Databases and Information Management. File Organization Terms and Concepts Bit: Smallest unit of data; binary digit (0,1) Byte: Group of bits.
.NET Database Technologies: Data Models and Patterns.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
1 CS 430 Database Theory Winter 2005 Lecture 17: Objects, XML, and DBMSs.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
1 Part 2: EJB Persistency Jianguo Lu. 2 Object Persistency A persistent object is one that can automatically store and retrieve itself in permanent storage.
Object Persistence (Data Base) Design Chapter 13.
Object Persistence Design Chapter 13. Key Definitions Object persistence involves the selection of a storage format and optimization for performance.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Lecture # 3 & 4 Chapter # 2 Database System Concepts and Architecture Muhammad Emran Database Systems 1.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
1 Mapping to Relational Databases Presented by Ramona Su.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Oct * Brad Tutterow. VS 2008.NET 3.5LINQ Entity Framework  The ADO.NET Entity Framework is part of Microsoft’s next generation of.NET technologies.
Creating and Maintaining Geographic Databases. Outline Definitions Characteristics of DBMS Types of database Relational model SQL Spatial databases.
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
Switch off your Mobiles Phones or Change Profile to Silent Mode.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Object-Oriented Database Management Systems The goal of all inanimate objects is to resist man and ultimately to defeat him Russell Baker, 1968.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Object storage and object interoperability
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
Introduction to Databases Angela Clark University of South Alabama.
Lecture 4: Logical Database Design and the Relational Model 1.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Data Access Patterns Problems with data access from OO programs: 1.The object-relational impedance mismatch 2.Decoupling domain logic from database technology.
Geographic Information Systems GIS Data Databases.
OpenAccess ORM Advanced Topics Kevin Babcock April 9, 2009.
New Technology: Why, What ,How
Architecture & Data Models
Geographic Information Systems
ADO.NET Entity Framework Marcus Tillett
MS Access Database Connection
MANAGING DATA RESOURCES
Lec 3: Object-Oriented Data Modeling
Physical Database Design
Databases.
Data Model.
ITEC 3220A Using and Designing Database Systems
Object Relational Mapping Tools
Geographic Information Systems
Presentation transcript:

Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling domain logic from database technology

Problems in Data Access (1) –Problem: Data sources and OO programs use different data modeling concepts: –OO programs: class, object, attribute; relations: association, aggregation, inheritance –XML: tags, elements, attributes –SQL: tables, rows, columns; relations: foreign key references –Solution: mapping OO concepts to concepts specific for each data source type –Mapping patterns –XML OO –SQL OO –Automatic mapping tools: –XML data binders: ex: JAXB; see a list of more examples: –Object-Relational Mappers: ex: Java Persistence API, Hibernate, LINQ to SQL; see a list of more examples:

Bibliography Lecture notes based on: Wolfgang Keller, Mapping Objects to Tables – apers/mappings04

Mapping Object Oriented to Relational Concepts The object-relational impedance mismatch: conceptual and technical difficulties that are often encountered when a relational database management system is being used by a program written in an object-oriented programming language or style Object-oriented model: – Aggregation – Inheritance and polymorphism – Associations between classes Relational model: – Tables – Foreign key references to another table

Mapping Object Oriented to Relational Concepts General rules: – Class Table – Object Row – Attribute Column – Works well only for simple classes with scalar attributes only Problems: – Aggregations: one domain object contains other domain objects – Associations: objects have references to other objects (m:n) – Inheritance: How do you map an inheritance hierarchy of classes to database tables?

Solutions for Mapping Aggregation (1): Single Table Aggregation Solution: Put the aggregated object's attributes into the same table as the aggregating object’s. Figure from : Wolfgang Keller, Mapping Objects to Tables

Single Table Aggregation Example & Consequences Performance: +, only one table needs to be accessed for queries Flexibility: -, if the aggregated object type is aggregated in more than one object type, the design results in poor maintainability Figure from : Wolfgang Keller, Mapping Objects to Tables

Solutions for Mapping Aggregation (2): Foreign Key Aggregation Solution: Use a separate table for the aggregated type. Insert an Synthetic Object Identity into the table and use this object identity in the table of the aggregating object to make a foreign key link to the aggregated object.

Foreign Key Aggregation Example & Consequences Performance: -, needs a join operation or at least two database accesses Maintenance: +, Factoring out objects into tables of their own makes them easier to maintain and hence makes the mapping more flexible. Consistency of the database: !, Aggregated objects are not automatically deleted on deletion of the aggregating objects.

Solution for Mapping Associations: Association Table Solution: Create a separate table containing the Object Identifiers (or Foreign Keys) of the two object types participating in the association. Map the rest of the two object types to tables using any other suitable mapping patterns presented in this paper.

Association Table Example n:m association between Employees and Departments An Employee may work with m Departments A Department comprises n Employees

Solutions for Mapping Inheritance (1): One Class – One Table Solution: Map the attributes of each class to a separate table. Insert a Synthetic OID into each table to link derived classes rows with their parent table's corresponding rows.

One Class – One Table Example & Consequences Performance: -, reading a SalariedEmployee instance in our example costs 3 (=depth of inheritance tree) database read operations

Solutions for Mapping Inheritance (2): One Inheritance Tree – One Table Use the union of all attributes of all objects in the inheritance hierarchy as the columns of a single database table. Use Null values to fill the unused fields in each record.

One Inheritance Tree – One Table Example & Consequences Performance: +, needs one database operation to read or write an object. Space consumption: -, optimal space consumption. Balancing database load across tables: -

Solutions for Mapping Inheritance (3): One Inheritance Path – One Table Solution: Map the attributes of each concrete class to a separate table. To a classes’ table add the attributes of all classes the class inherits from.

One Inheritance Path – One Table Example & Consequences Performance: +, needs one database operation to read or write an object. Space consumption: +, optimal space consumption. Maintenance cost: +/-: inserting a new subclass means updating all polymorphic search queries. The structure of the tables remains untouched. Adding or deleting attributes of a superclass results in changes to the tables of all derived classes.