Object Relational Mapping John M. Miller Perpetual Data Systems.
-
Upload
dwayne-ancell -
Category
Documents
-
view
217 -
download
0
Transcript of Object Relational Mapping John M. Miller Perpetual Data Systems.
Object Relational Mapping Object Relational Mapping
John M. MillerJohn M. Miller
Perpetual Data SystemsPerpetual Data Systems
John M. MillerJohn M. [email protected]@pdata.com
Independent Software Architect, Designer & DeveloperIndependent Software Architect, Designer & Developer PDC 2002 SpeakerPDC 2002 Speaker Collaborator on adding advanced business rule support Collaborator on adding advanced business rule support
to a commercial .Net application frameworkto a commercial .Net application framework Member of a team submitting a response to the OMG Member of a team submitting a response to the OMG
request for a method for formalizing business rulesrequest for a method for formalizing business rules XSLT transformations from ORM conceptual models into XSLT transformations from ORM conceptual models into
.NET entity business object implementation .NET entity business object implementation
OverviewOverview
What is Object Relational Mapping What is Object Relational Mapping Why did Microsoft back away? Why did Microsoft back away? Is OR Mapping dead? Is OR Mapping dead? What if it isn't? What if it isn't? What does it mean for .NET application What does it mean for .NET application
architectures?architectures? Which comes first the data chicken or Which comes first the data chicken or
object egg?object egg?
What is Object Relational Mapping What is Object Relational Mapping
Something that persists objects into Something that persists objects into relational databasesrelational databases
Can be Can be a software layer using dynamic SQL a software layer using dynamic SQL
generationgeneration a method of generating static SQL a method of generating static SQL
Implicit with Domain object modelsImplicit with Domain object models DataSets need not applyDataSets need not apply
Why are domain models important?Why are domain models important? BecauseBecause
Why is OR Mapping Important?Why is OR Mapping Important?
I said soI said so They abstract the data access code hiding the database They abstract the data access code hiding the database
detailsdetails They encapsulate the database in an interface that more They encapsulate the database in an interface that more
closely matches the conceptual domain.closely matches the conceptual domain. Object Models are more expressive for certain kinds of object Object Models are more expressive for certain kinds of object
interactionsinteractions Constraints become easier to implementConstraints become easier to implement
Object notation is a natural way of navigating a join pathObject notation is a natural way of navigating a join pathACustomer.Orders[Number=1001].Items[Item=33].Product.Price
Constraints become easier to implementConstraints become easier to implementIf AProduct.OnHand < AItem.Quantity Then raise BizRuleXceptn
MappersMappers
Domain models put the responsibility of Domain models put the responsibility of reconciling design differences between the reconciling design differences between the object and data models on the persistence object and data models on the persistence layerlayer
Persistence LayersPersistence Layers StaticStatic
Hand codedHand coded GeneratedGenerated
DynamicDynamic
Problems with OR MappingProblems with OR Mapping
A weakness in the mapper limits the A weakness in the mapper limits the capability of the object model and in turn capability of the object model and in turn the capability of the applicationthe capability of the application
No standard object query languageNo standard object query language It can’t be done, not practical, a waste of It can’t be done, not practical, a waste of
time, etc.time, etc. It costs time and moneyIt costs time and money The dread impedance mismatchThe dread impedance mismatch
Wikipedia, C2
The Impedance MismatchThe Impedance Mismatch
"When you notice that you're experiencing "When you notice that you're experiencing considerable pain, and you recognize that a considerable pain, and you recognize that a substantial amount of the pain occurs in and substantial amount of the pain occurs in and around the interface between your code and the around the interface between your code and the relational database, then you've found the relational database, then you've found the Object/Relational Impedance Mismatch."Object/Relational Impedance Mismatch."
The Impedance MismatchThe Impedance Mismatch
TechnicalTechnical Object Modeling and Data Modeling model Object Modeling and Data Modeling model
fundamentally different thingsfundamentally different things Objects = ProcessObjects = Process
Data persistence is secondaryData persistence is secondary
Data = StructureData = Structure What about static class diagrams?What about static class diagrams?
Fundamentally flawed for complex structural Fundamentally flawed for complex structural modelingmodeling
Different OptimizationsDifferent Optimizations Identification schemes are a problemIdentification schemes are a problem
The Impedance MismatchThe Impedance Mismatch
CulturalCultural Created by different campsCreated by different camps
Software ArchitectsSoftware Architects The equally dread Database AdministratorThe equally dread Database Administrator Night & Day, Oil & Water, Pickles & KetchupNight & Day, Oil & Water, Pickles & Ketchup
The Impedance MismatchThe Impedance Mismatch
RealityReality Neither domain models nor relational Neither domain models nor relational
databases are going away.databases are going away. Mappers are the price we pay for playingMappers are the price we pay for playing Does it really exist?Does it really exist?
So why did Microsoft back away? So why did Microsoft back away?
ObjectSpacesObjectSpaces Billed as the Microsoft OR MapperBilled as the Microsoft OR Mapper Due to ship with Visual Studio 2005Due to ship with Visual Studio 2005 Rolled into WinFSRolled into WinFS
BecauseBecause Overlapped with some of the WinFS persistence storyOverlapped with some of the WinFS persistence story Different APIs and Microsoft wanted to unify the APIsDifferent APIs and Microsoft wanted to unify the APIs Microsoft didn’t want to publish ObjectSpaces and then Microsoft didn’t want to publish ObjectSpaces and then
release an incompatible WinFSrelease an incompatible WinFS
So why did Microsoft back away? So why did Microsoft back away?
WinFSWinFS Windows object storeWindows object store Due to ship with LonghornDue to ship with Longhorn Pushed back until after LonghornPushed back until after Longhorn
BecauseBecause It wasn’t going to be ready in timeIt wasn’t going to be ready in time Object Persistence is harder than they thoughtObject Persistence is harder than they thought
E12E12
So why did Microsoft back away? So why did Microsoft back away?
To the net effect of leaving the market To the net effect of leaving the market without a Microsoft OR Mapper until?without a Microsoft OR Mapper until? 2008? 2008?
2009?2009?2010?2010?
After first creating a buzz with the initial After first creating a buzz with the initial previews of ObjectSpaces and generating previews of ObjectSpaces and generating significant market momentumsignificant market momentum
Leaving the development world to wonderLeaving the development world to wonder Is OR Mapping dead?Is OR Mapping dead?
Is OR Mapping Dead? Is OR Mapping Dead?
In the Microsoft communityIn the Microsoft community AlmostAlmost
There are several implementations that were There are several implementations that were available before ObjectSpaces that are still aroundavailable before ObjectSpaces that are still around
And a few created sinceAnd a few created since One that emulates the ObjectSpaces preview APIOne that emulates the ObjectSpaces preview API
In the Java communityIn the Java community Not even closeNot even close
Widely adoptedWidely adopted Not if, but which oneNot if, but which one
What if it isn't? What if it isn't?
You could miss out on a technology that could You could miss out on a technology that could make an application easier to design, implement make an application easier to design, implement and maintainand maintain
What is the .NET OR faithful to do?What is the .NET OR faithful to do? Wait for MicrosoftWait for Microsoft Adopt an existing .NET OR Mapper until Microsoft Adopt an existing .NET OR Mapper until Microsoft
does somethingdoes something Try WORMTry WORM
Adopt an existing .NET OR Mapper permanentlyAdopt an existing .NET OR Mapper permanently nHibernate is hot right nownHibernate is hot right now
Switch to JavaSwitch to Java Like you, they get OR mappersLike you, they get OR mappers
What does it mean for .NET What does it mean for .NET application architectures?application architectures?
XML and DataSets will continue to rule the DAL XML and DataSets will continue to rule the DAL world until a dominate OR mapper for .NET world until a dominate OR mapper for .NET appearsappears
OR Mapping will continue to be used sparingly OR Mapping will continue to be used sparingly and grow as the mappers matureand grow as the mappers mature
Adoption rate in the .NET community should Adoption rate in the .NET community should mimic the adoption rate for OR mappers in the mimic the adoption rate for OR mappers in the Java community, but at faster paceJava community, but at faster pace
Should be widely adopted in the .NET Should be widely adopted in the .NET community in 3-4 yearscommunity in 3-4 years
Hold your breath when WinFS shipsHold your breath when WinFS ships
Which comes first the data chicken or object egg?Which comes first the data chicken or object egg?
Lets say you are starting a new project with:Lets say you are starting a new project with: Complex business logicComplex business logic Complex data relationshipsComplex data relationships Interested in creating a domain model and and Interested in creating a domain model and and
relational database.relational database. What do you do first?What do you do first?
1.1. Call meCall me2.2. Create the object model you want to persistCreate the object model you want to persist3.3. Create the data model that you know you needCreate the data model that you know you need
If you do either 2 or 3 you have to deal with the If you do either 2 or 3 you have to deal with the dread impedance mismatchdread impedance mismatch
The Object EggThe Object Egg
You create the domain object model first You create the domain object model first using standard OOA&D methodsusing standard OOA&D methods
Then derive the data structure from the Then derive the data structure from the object modelobject model
ProblemsProblems Number of tablesNumber of tables NormalizationNormalization Fragile StructuresFragile Structures
The Data ChickenThe Data Chicken
You create the data model first using You create the data model first using standard data modeling methodsstandard data modeling methods
The derive the domain model from the The derive the domain model from the data modeldata model
ProblemsProblems You tell me?You tell me? Fidelity LossFidelity Loss
What then?What then?
Conceptual ModelsConceptual Models Design the structures conceptually first using a formal Design the structures conceptually first using a formal
conceptual modeling methodconceptual modeling method Derive both the entity object model and data model Derive both the entity object model and data model
from the conceptual modelfrom the conceptual model
ProblemsProblems Your domain object model needs to collaborate with Your domain object model needs to collaborate with
the entity objectsthe entity objects No standardsNo standards Complex transformationComplex transformation
What next?What next?
2/1/2005 - San Diego .NET Developer 2/1/2005 - San Diego .NET Developer Group MeetingGroup Meeting Implementing .NET Applications using Implementing .NET Applications using
Conceptual Models Conceptual Models
Thank You!Thank You!
[email protected]@pdata.com pdata.com/jMMpdata.com/jMM shrinkster.com/3btshrinkster.com/3bt en.wikipedia.org/wiki/Object-relational_mappingen.wikipedia.org/wiki/Object-relational_mapping c2.com/cgi/wiki?ObjectRelationalMappingc2.com/cgi/wiki?ObjectRelationalMapping theserverside.com/books/review/HibernateReview.tsstheserverside.com/books/review/HibernateReview.tss devx.com/vb2themax/Article/19894devx.com/vb2themax/Article/19894 sddotnetdg.org/Events/SDDOTNET+Meetings/default.aspxsddotnetdg.org/Events/SDDOTNET+Meetings/default.aspx