Nate Clark
1 / 22

Nate Clark - PowerPoint PPT Presentation

  • Updated On :

Nate Clark. 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 SQL queries. A little history…. Origins of Databases and Objects. DBMS technology invented late 1960’s

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Nate Clark' - luciano

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Slide2 l.jpg

Origins of databases and objects l.jpg
Origins of Databases and Objects

  • DBMS technology invented late 1960’s

  • OO technology invented late 1960’s

  • Independent evolution for over 20 years

  • Different audiences

    • DBMS: corporate information systems

    • OO: academic and scientific

The rise of client server l.jpg
The Rise of Client/Server

  • Corporate IT in early ’90s

  • High cost of mainframe hardware

  • Low cost of the IBM PC-based platform

  • Desire to move away from COBOL

  • The “hot” languages were OO

    • Smalltalk

    • C++

Object meets relational l.jpg
Object Meets Relational

  • Corporate IT already deeply invested in RDBMS

  • “We’ll just connect up our new client server applications to these databases!”

  • Efforts to marry the two technologies

  • Discovery of the “O/R Impedance Mismatch”

Dbms representation l.jpg
DBMS Representation

  • Based on the concept of a Relation

    • A set of data values that “go together”

    • Represented as a Row in a Table

  • No two rows should be duplicates

    • Useless to state the same fact twice

  • Very useful for flexible set manipulation

    • SQL queries

Object oriented representation l.jpg
Object-Oriented Representation

  • An object is a model of something in the real world

  • Public interfaces

    • How an object interacts with the rest of the world

  • Private members

    • How an object behaves internally

Object oriented representation10 l.jpg
Object-Oriented Representation

  • Merges data and behavior

    • Allows an object to initiate interactions and respond flexibly to them

    • Important for modeling the real world

  • Effective OO models allow for very high reuse

    • Parcel program logic and data into self-defined and self-consistent bundles

Object oriented representation11 l.jpg
Object-Oriented Representation

  • Each object (instance) is unique

    • even if all data members are equal

  • Object types inherit from other types

    • allows for the creation of rich, powerful models

    • allows opportunities for reuse

O r impedance mismatch l.jpg
O/R “Impedance Mismatch”

  • Impedance matching

    • from electronics theory

    • matching a power source with a power load

  • Mismatch between object and relational technologies

    • Different theoretical foundations

      • Relations are facts about data relatedness

      • Objects are models of reality

O r impedance mismatch13 l.jpg
O/R “Impedance Mismatch”

  • Mismatched uniqueness rules

    • Rows containing identical data are “the same”

      • Considered undesirable

    • Objects containing identical data are different

      • Common and useful

      • “equal”, but not “==“

  • Mismatched data model topologies

    • Relational tables are flat

    • Object types are hierarchical

O r mapping tools l.jpg
O/R Mapping Tools

  • Invented in early 1990’s

  • One of the first came from Cleveland

    • Raleigh Systems’ ObjectPM

  • Shield the OO application from the database paradigm

  • Mappings to tables and columns are localized in configuration files

Enter hibernate l.jpg
[Enter: Hibernate]

  • Initially developed for Java

    • created in late 2001 by Gavin King

    • absorbed by the JBoss Group / Red Hat

  • Ported to .NET 1.1 and 2.0

    • Resulting product called “NHibernate”

  • All popular databases supported

  • XML-based configuration files

What nhibernate does l.jpg
What NHibernate Does

  • Takes as input

    • a C# class with properties that need to be stored in a database and retrieved later

    • an XML file containing mapping information

  • Outputs automatically generated SQL

    • when you tell NHibernate to “save” an object

    • when you ask NHibernate to search/load objects

    • can also create all database tables if desired

How to use nhibernate l.jpg
How to Use NHibernate

  • Step 1: create an object oriented business model

    • Start simple: one or two small classes

    • Note which properties will save in DBMS

  • Implement the model using C#

    • Best kept in a separate C# project

Step 2 the mapping file l.jpg
Step 2: The Mapping File

  • One per business model class

  • Named classname.hbm.xml

  • Tells NHibernate where data is to reside

    • Name of table to store data for this class

    • Name of a column for each property in class

  • Also describes relationships between classes

    • One-to-many, many-to-one, many-to-many

  • Generated SQL is based on this information

Step 3 configuration file l.jpg
Step 3: Configuration File

  • XML-based file for global configuration

  • Usually named “hibernate.cfg.xml”

  • Application-wide settings

  • Database connection string

  • Database “dialect”

    • Specifies database product and version

    • Allows NHibernate to use non-standard features where appropriate

  • Logging options

Step 4 user interface tasks l.jpg
Step 4: User Interface Tasks

  • Create business model objects

  • Create an NHibernate session object

  • Insert/Update to DBMS


  • Retrieve business model data from the DBMS as business model objects

    • Session.load(type, id)

    • Session.find(query)

Step 5 unit test and debug l.jpg
Step 5: Unit Test and Debug

  • Unit tests can be created for each persistent class if desired

    • VSTS unit testing support

    • NUnit

  • Run, test and debug in the usual fashion

  • Sit back and relax….

  • You’re done!