Download presentation
Presentation is loading. Please wait.
Published byColeen Charles Modified over 9 years ago
1
March 200592.3913 R McFadyen1 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 0321146530
2
March 200592.3913 R McFadyen2 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
3
March 200592.3913 R McFadyen3 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”
4
March 200592.3913 R McFadyen4 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)
5
March 200592.3913 R McFadyen5 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 …
6
March 200592.3913 R McFadyen6 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)
7
March 200592.3913 R McFadyen7 Based on Primer pages 7, 8 :Client pet:Pet :session :UnitOfWork petClone:Pet setID(100) setName(Fluffy) setType(Cat) acquireUnitOfWork() new() registerObject(pet) petClone new() commit() At commit time, the UnitOfWork submits the SQL statement: Insert into Pet (ID, Name, Type, Pet_Own_Id) Values (100, ‘Fluffy’,’Cat’, Null) new()
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.