CSC/ECE 517 Fall 2007/wiki2 2 d4: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
== Topic ==
== Topic ==


Line 8: Line 7:
== Object Relational Mapping (ORM)  ==
== Object Relational Mapping (ORM)  ==


This is technique for mapping object-oriented (O-O) class structures to relational database storage structures.
[http://en.wikipedia.org/wiki/Object_Relational_Mapping Object-relational mapping] (ORM) is the technique used to marshal database records into classes of object-oriented (OO) languages and vice-versa. The technique is usually developed into a tool that can be used by the developer to alleviate some of the complexity in this mapping. The complexity derives from the inherently different data types that are used by relational databases and OO languages. Database data types are typically scalar in nature while classes are more typically composed of a mix of non-scalar and scalar types.
 
[[Image:ORM_Flowchart.jpg]]


=== Why these techniques are necessary? ===
=== Why these techniques are necessary? ===

Revision as of 18:45, 22 October 2007

Topic

Object-relational mapping. Ruby's ActiveRecord is one attempt to allow an object-oriented program to use a relational database. The Crossing Chasms pattern is another. Look up several approaches to mapping relational databases to o-o programs, include hyperlinks to all of them, and explain how they differ. Report on the strengths of various approaches (making sure to credit the authors for their insights)


Object Relational Mapping (ORM)

Object-relational mapping (ORM) is the technique used to marshal database records into classes of object-oriented (OO) languages and vice-versa. The technique is usually developed into a tool that can be used by the developer to alleviate some of the complexity in this mapping. The complexity derives from the inherently different data types that are used by relational databases and OO languages. Database data types are typically scalar in nature while classes are more typically composed of a mix of non-scalar and scalar types.

Why these techniques are necessary?

  1. There is not a one-to-one relationship between database object types and O-O language types

Definition

Need

Approaches

Popular Approaches

Crossing the Chasm Pattern Language

One of the first ORMs (see http://www.agiledata.org/essays/mappingObjects.html)

Active Record

Limitations

  1. No Foreign Key Support: Although RoR lets you define has_many relationships, it makes no effort to create foreign key constraints in the underlying database to ensure relational integrity.
  2. No Multi-column Primary Key Support: Multi-column primary keys are a staple of relational database schema definition.


Data Mapper

Lafcadio

  1. Another ORM for Ruby that currently only supports MySQL databases
  2. Treats each table row as a class object
  3. see http://lafcadio.rubyforge.org/ and http://www.zenspider.com/dl/rubyconf2003/lafcadio.pdf

Popular Products

These patterns in practice can be found in

Hibernate

Oslick

Perl's DBIx::Class

References

  1. ORM articles
  2. Active Record was mentioned in this book
  3. A video from RailsEnvy giving a quick and clean introduction to Active Record
  4. A comparison of datamapper and Active Record implementations in Ruby
  5. A blog entry by Dev411 on limitations of Active Record