1 / 7

Object Relational Mapping example

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.

quito
Télécharger la présentation

Object Relational Mapping example

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. 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 92.3913 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 92.3913 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” 92.3913 R McFadyen

  4. Patterns of enterprise application architectureUnit 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) 92.3913 R McFadyen

  5. 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 • … 92.3913 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) 92.3913 R McFadyen

  7. Based on Primer pages 7, 8 :Client :session acquireUnitOfWork() new() :UnitOfWork pet:Pet new() registerObject(pet) new() petClone:Pet 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) 92.3913 R McFadyen

More Related