130 likes | 290 Views
Mapping to Relational Databases. Presented by Ramona Su. Overview. Role of the database DB plays dominant role in the data source layers for most systems Storing persistent data Maintain internal records Core part of some scientific investigation What is object-relational mapping?
E N D
Mapping to Relational Databases Presented by Ramona Su
Overview • Role of the database • DB plays dominant role in the data source layers for most systems • Storing persistent data • Maintain internal records • Core part of some scientific investigation • What is object-relational mapping? • Object-relational mapping is used to map object-oriented programming objects to relational databases managed by relational database managers. (http://www.service-architecture.com/object-relational-mapping/)
Overview • Why is object-relational mapping important? • Many systems use a relational DB • SQL has helped make a relational DB successful • Better understood & proven technology over OO DB • Data already exists in a relational DB • Technical or political reasons for using a relational DB • Creating an abstraction • Takes advantage of transparent persistence • Reduces code • Improves performance
Types of Databases • Object Oriented DB • Users can define their own methods of access to data and how it is represented and manipulated • Database objects appear as programming language objects in one or more object programming languages • No problem of O/R Mapping • Improves productivity • Relational DB • Ted Codd’s paper “A Relational Model for Large Shared Data Banks” • “It provides a means of describing data with its natural structure only--that is, without superimposing any additional structure for machine representation purposes. Accordingly, it provides a basis for a high level data language which will yield maximal independence between programs on the one hand and machine representation on the other.” (Codd, 1970)
Architectural Patterns • Important part of design • Types of patterns • Gateway (separating access to DB) • Row Data Gateway • Record Set • Domain Model (incorporates data and behavior) • Active Record • Data Mapper (insulate domain objects and DB from each other)
Loading/Saving Problem • Problem with consistency • Problem with isolated reads • Solutions • Unit of Work • Possible performance degradation • Identity Map • Performance boost • Lazy Load • Performance boost
Structural Problem • Mapping relationships problems • Difference in representation • Multiple references and links • Many-to-many relationship • Solutions • Identity Field • Foreign Key Mapping • Association Table Mapping
Structural Problem Continued • Inheritance • SQL cannot handle inheritance • Solutions • Single Table Inheritance • Concrete Table Inheritance • Class Table Inheritance • Tradeoff between duplication of data and speed of access
Connection Problem • Ensuring connection is opened when it needs to be, or closed when you’re done accessing • Managing connection solutions • Pass it as a parameter • Garbage collection • Tie it to a transaction • Connection can cause concurrency issues
Metadata • Use metafile for mapping • Avoids repetitive code • Can build queries in terms of objects • Query Object • Repository
Discussion • It seems like you must do a lot more work with O/R mapping than if you used a OO DB. How can we make use of OO DB more successful?
Questions? • Any questions or comments?