Download presentation
Presentation is loading. Please wait.
1
Object Relational Mapping example
TopLink Part of Oracle environment Provides an Object/Relational Mapping Layer References: pages from: Oracle Toplink Unit of Work Primer Patterns of enterprise application architecture 2003 Martin Fowler Addison-Wesley March 2004 R McFadyen
2
Patterns of enterprise application architecture
A book on enterprise application design Layering Domain/business logic Web user interface Object to relational mapping Session state in a stateless environment Distribution March 2004 R McFadyen
3
Patterns of enterprise application architecture - Architecture
Two common elements to architecture: Highest-level breakdown of a system into its parts Decisions that are hard to change page 2: “The architectural pattern I like the most is that of layers” “Most nontrivial enterprise applications use a layered architecture of some form” March 2004 R McFadyen
4
Patterns of enterprise application architecture Unit of Work Pattern
Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems Mentions 3 variations: caller registration, object registration, unit or work controller (e.g. Toplink) March 2004 R McFadyen
5
unit of work controller variation:
Unit of Work Pattern unit of work controller variation: UoW makes a copy (clone) Application works on the copy UoW compares object and clone at commit time and issues necessary SQL to database … March 2004 R McFadyen
6
Based on Primer pages 7, 8 Code shows how a Java program collaborates with Toplink to ensure a new object persists in the relational database The application gets a Unit of Work. Application creates a new Pet object, but the application works on a clone. At commit time, Toplink issues the necessary SQL based on difference between clones and originals. UnitOfWork uow = session.acquireUnitOfWork(); Pet pet new Pet(); Pet petClone = (Pet)uow.registerObject(pet); petClone.setId(100); petClone.setName(“Fluffy”): petClone.setType(“Cat”); uow.commit(); At commit time Toplink sends the following to the database Insert into Pet (ID, Name, Type, Pet_Own_Id) Values (100, ‘Fluffy’ ,’Cat’ , Null) March 2004 R McFadyen
7
Based on Primer pages 7, 8 :Client :session :UnitOfWork pet:Pet
acquireUnitOfWork() new() :UnitOfWork new() pet:Pet registerObject(pet) petClone:Pet new() petClone setID(100) setName(Fluffy) setType(Cat) commit() At commit time, the UnitOfWork submits the SQL statement: Insert into Pet (ID, Name, Type, Pet_Own_Id) Values (100, ‘Fluffy’ ,’Cat’ , Null) March 2004 R McFadyen
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.