1 / 22

Nate Clark

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

luciano
Download Presentation

Nate Clark

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Nate Clark

  2. 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

  3. A little history…

  4. 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

  5. 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++

  6. 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”

  7. The object/relational conflict

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. [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

  16. 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

  17. 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

  18. 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

  19. 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

  20. Step 4: User Interface Tasks • Create business model objects • Create an NHibernate session object • Insert/Update to DBMS • Session.save(object) • Retrieve business model data from the DBMS as business model objects • Session.load(type, id) • Session.find(query)

  21. 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!

  22. Questions ?

More Related