Object-to-Relational Mapping: The Crossing Chasms Pattern and Implementation Considerations Use of Meta Data in the Java Persistence Layer Presented by.

Slides:



Advertisements
Similar presentations
January 30, 2014 Copyright Jim Farley Beyond JDBC: Java Object- Relational Mappings Jim Farley e-Commerce Program Manager GE Research and Development
Advertisements

3 Copyright © 2005, Oracle. All rights reserved. Designing J2EE Applications.
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Chapter 10: Designing Databases
COM vs. CORBA.
EJB Entity Beans. Entity Beans Data versus logic Used to represent an instance rather than a collection of data (depending on underlying storage) Represents.
The Hierarchical Model
Introduction to Databases
.NET Database Technologies: Open-Source Frameworks.
GI Systems and Science January 30, Points to Cover  Recap of what we covered so far  A concept of database Database Management System (DBMS) 
Page 1 Building Reliable Component-based Systems Chapter 7 - Role-Based Component Engineering Chapter 7 Role-Based Component Engineering.
Chapter 1 Object-Oriented System Development
Chapter Object-Oriented Practices. Agenda Object-Oriented Concepts Terminology Object-Oriented Modeling Tips Object-Oriented Data Models and DBMSs.
File Systems and Databases
Data Management I DBMS Relational Systems. Overview u Introduction u DBMS –components –types u Relational Model –characteristics –implementation u Physical.
Chapter 11 Data Management Layer Design
1 A Student Guide to Object- Orientated Development Chapter 9 Design.
Database System Concepts and Architecture Dr. Ali Obaidi.
The chapter will address the following questions:
Data Access Patterns. Motivation Most software systems require persistent data (i.e. data that persists between program executions). In general, distributing.
Enterprise Object Framework. What is EOF? Enterprise Objects Framework is a set of tools and resources that help you create applications that work with.
JDBC Session 5 Tonight: Data Access Patterns 1.J2EE Architecture & Design Patterns 2.The Data Access Tier 3.Data Access Patterns –DataAccessObject (DAO)
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Chapter 4 The Relational Model.
CS370 Spring 2007 CS 370 Database Systems Lecture 2 Overview of Database Systems.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
What is Architecture  Architecture is a subjective thing, a shared understanding of a system’s design by the expert developers on a project  In the.
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
Database System Concepts and Architecture Lecture # 2 21 June 2012 National University of Computer and Emerging Sciences.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
2. Database System Concepts and Architecture
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 4th Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
I Information Systems Technology Ross Malaga 4 "Part I Understanding Information Systems Technology" Copyright © 2005 Prentice Hall, Inc. 4-1 DATABASE.
File Processing Concepts – Field – combination of 1 or more characters that is the smallest unit of data to be accessed – Record – group of related fields.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Andrew S. Budarevsky Adaptive Application Data Management Overview.
Lecture # 3 & 4 Chapter # 2 Database System Concepts and Architecture Muhammad Emran Database Systems 1.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
1 Mapping to Relational Databases Presented by Ramona Su.
Domain and Persistence Patterns. Fundamental Pattern Types Design Patterns Business Logic Patterns.
ATLAS Detector Description Database Vakho Tsulaia University of Pittsburgh 3D workshop, CERN 14-Dec-2004.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
3-Tier Client/Server Internet Example. TIER 1 - User interface and navigation Labeled Tier 1 in the following graphic, this layer comprises the entire.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Oct * Brad Tutterow. VS 2008.NET 3.5LINQ Entity Framework  The ADO.NET Entity Framework is part of Microsoft’s next generation of.NET technologies.
Database Design Some of these slides are derived from IBM/Rational slides from courses on UML and object-oriented design and analysis. Copyright to the.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Session 1 Module 1: Introduction to Data Integrity
Elaboration Iteration 3 – Part 3 - Persistence Framework -
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Object storage and object interoperability
Introduction to Active Directory
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 5th Edition Copyright © 2015 John Wiley & Sons, Inc. All rights.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
1 Information Retrieval and Use De-normalisation and Distributed database systems Geoff Leese September 2008, revised October 2009.
1 10 Systems Analysis and Design in a Changing World, 2 nd Edition, Satzinger, Jackson, & Burd Chapter 10 Designing Databases.
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
DBS201: Data Modeling. Agenda Data Modeling Types of Models Entity Relationship Model.
ISC321 Database Systems I Chapter 2: Overview of Database Languages and Architectures Fall 2015 Dr. Abdullah Almutairi.
Chapter 2 Database System Concepts and Architecture
ADO.NET Entity Framework Marcus Tillett
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
Data Model.
Database System Concepts and Architecture
Presentation transcript:

Object-to-Relational Mapping: The Crossing Chasms Pattern and Implementation Considerations Use of Meta Data in the Java Persistence Layer Presented by Toby Sarver

© Copyright 1999, 2001 Thomas W. Sarver 2 Agenda What is a Persistence Layer and why do I want one? Crossing Chasms: storing objects in a relational database. Process for applying the Crossing Chasms pattern. Overview of two implementations.

© Copyright 1999, 2001 Thomas W. Sarver 3 What Is a Persistence Layer? Retrieve Change Store

© Copyright 1999, 2001 Thomas W. Sarver 4 Why Do I Need a Persistence Layer? Objects need to live longer than the program. Change boundary –Protects the application developer from changes in the structure of the database. Encapsulates the business logic rather than simply manipulating the data.

© Copyright 1999, 2001 Thomas W. Sarver 5 Crossing Chasms

© Copyright 1999, 2001 Thomas W. Sarver 6 Recap of “Crossing Chasms” –Do initial object-oriented design, then consider persistence. –Implement a persistence framework as early as possible. –Use the “Broker” pattern rather than placing in the domain objects or subclassing.

© Copyright 1999, 2001 Thomas W. Sarver 7 Additions to “Crossing Chasms” Consider using a class for each ObjectID because what makes an object unique can be different for each class. –Consider EJB’s “FooKey” interface –The ObjectID can interact with the persistence layer for reading and writing itself, as well as searches Differentiate between references to independent objects vs. “owned” objects (containment).

© Copyright 1999, 2001 Thomas W. Sarver 8 Responsibilities of a Persistence Framework Identify transaction boundary (a.k.a. “Unit of Work”), which objects go together Store and retrieve single objects, object references, and collections of objects “Speak” to the persistence mechanism (e.g., call JDBC API) Search for objects based on attributes

© Copyright 1999, 2001 Thomas W. Sarver 9 Why Do I Need a Persistence Framework? Hide complexity –not everyone has to understand the pattern Reduce amount of code Centralize “Best Practices” –Refine the code as you learn more or require more functionality Encapsulate the persistence mechanism –Implements a well-defined interface for persistence –ADO, JDBC, native Oracle, stored procedures, etc.

© Copyright 1999, 2001 Thomas W. Sarver 10 Applying the “Crossing Chasms” Pattern Identify the objects that need to be persisted, and the transaction boundaries. Deal with inheritance, if any. Write mechanism for storing and retrieving individual objects. Overlay a tree structure on the instance graph –tree, parent, and sibling pointers

© Copyright 1999, 2001 Thomas W. Sarver 11 Applying the “Crossing Chasms” Pattern (2) Examine each object relationship and model it in the database and the persistence layer appropriately. –cardinality –ownership

© Copyright 1999, 2001 Thomas W. Sarver 12 Modeling Relationships Owned child (single or multiple) –use standard foreign key of parent in child record Heterogeneous collection of owned children –same as above, but search multiple tables Sibling Pointer –“swizzle” the ObjectID into an object reference one all siblings are retrieved. Many to many –Use a mapping table, possibly a mapping object

© Copyright 1999, 2001 Thomas W. Sarver 13 Modeling Relationships (2) Non-Owned Relationship –Keep a registry of such objects –“Swizzle” the ObjectID to object reference –For example, keep a registry of all publicly-traded stocks. A customer owns the stock, but only stores the reference (e.g., the ticker).

© Copyright 1999, 2001 Thomas W. Sarver 14 Implementation Considerations Implementation considerations: –Use of meta-data, if any –Options in distributing the responsibilities of the persistence layer Storing individual objects –Naïve: delete row and insert new value –Evolved: detect new vs. existing, do Insert or Update –Nirvana: keep dirty bit for each attribute, only Update the changed attributes, skip if no change

© Copyright 1999, 2001 Thomas W. Sarver 15 Implementation Considerations (2) Storing Collections of Objects (same parent) –Naïve: Delete all child rows and re-insert –Evolved: Detect an Add: Insert it, otherwise Update it Detect a Delete: Delete the corresponding row Storing Network of Objects –Naïve: Delete all objects from the root and re-insert –Nirvana: Detect all changes and only make required DB accesses (a.k.a., Partial Persistence)

© Copyright 1999, 2001 Thomas W. Sarver 16 Overview of Implementations Example of JDBC Persistence Example of ADO Persistence Discussion of Partial Persistence Some Similarities Between the Two –e.g., use of meta data –Ref: PLOP 1: “Bridging the Gap Between Objects and Relational Databases” by Kyle Brown et al. –Ref: PLOP 2: “Reflection” by Buschmann et al.

© Copyright 1999, 2001 Thomas W. Sarver 17 JDBC Implementation –Written for a large financial services firm in Boston. –Needed to support a highly functional, Web-deployed application. –Used the Visitor pattern extensively. –Used the meta data to generate some Java classes

© Copyright 1999, 2001 Thomas W. Sarver 18 O2R Mapping Identity –get / set DbId() –Assigned by the persistence layer (DB) Pointers –Tree Pointers Explicit during read Implicit during write –Parent Pointers Implicit (Visitor) –Non-containing Pointers –Sibling Pointers Explicit (Visitor) Subclassing –Data-oriented Used separate tables with overlapping column names –Named Used a Java class name in the table –Visitor handled creating the right subclass

© Copyright 1999, 2001 Thomas W. Sarver 19 How the Responsibilities Are Delegated (JDBC) Visitor: Identify transaction boundary (a.k.a. “Unit of Work”), which objects go together Persistent Row (generated): Store and retrieve single objects, object references, and collections of objects Persistent Row: “Speak” to the persistence mechanism Persistent: Search for objects based on attributes

© Copyright 1999, 2001 Thomas W. Sarver 20 Class Diagram DomainVisitorDomainObject Persistable implements can Visit Relational PersistenceRead Relational PersistenceWrite subclass Persistent Customer Persist Account Persist... Goal Persist PersistentRow Customer PersistRow Account PersistRow... Goal PersistRow Generated from Meta-data

© Copyright 1999, 2001 Thomas W. Sarver 21 Partial Persistence –Original Strategy load the whole Customer and all associated objects when the user logs in save the whole Customer … when the session times out –Problem was that if the server went down in this period, the user loses all the work –Partial Persistence Strategy load the whole Customer on session start, as before save whatever objects changed during each request –after handling a request, the database is in sync with memory

© Copyright 1999, 2001 Thomas W. Sarver 22 Overview Partial Persistence update Delta ’3 64’477 insert 2 delete

© Copyright 1999, 2001 Thomas W. Sarver 23 Delta Rules Update –If an object is being inserted or deleted, ignore update Insert –Always insert Delete –If the object is being inserted, remove it from the inserted list –If the object is being updated, move to deleted list Dependencies –Has rules for dealing with dependencies –Essentially does operations in order from root to leaf

© Copyright 1999, 2001 Thomas W. Sarver 24 Meta Data (JDBC) –Stored as a script –Object Attribute : Type –implied naming conventions, get (), set () –exceptions were possible »for example, is, set (boolean) –Generated to Java classes PersistentRow extends PersistentRow standard interface, fill(), empty() method for each attribute custom coding is possible at the Persistent level

© Copyright 1999, 2001 Thomas W. Sarver 25 ADO Example Architectural objectives –Build domain objects in memory from multiple sources –Encapsulate persistence from other parts of the system –Redeploy the app to another persistence mechanism (ADO, JDBC, ERP) with little effort Meta data present (and interpreted) at run time Introduces View and ViewItem

© Copyright 1999, 2001 Thomas W. Sarver 26 View and ViewItem –Generic concept relating “parts to whole” –Basis for translating between different architectural layers –The concrete instances implement the “Base” layer (see Reflection pattern) DomainViewItem knows how to read and write attributes of a domain object. ADOViewItem knows how to read and write fields in a Recordset.

© Copyright 1999, 2001 Thomas W. Sarver 27 How the Responsibilities Are Delegated (ADO) DomainObject: Identify transaction boundary (a.k.a. “Unit of Work”), which objects go together ADOPersistence: Store and retrieve single objects, object references, and collections of objects ADOPersistence : “Speak” to the persistence mechanism None: Search for objects based on attributes

© Copyright 1999, 2001 Thomas W. Sarver 28 Class Diagram (ADO 1)

© Copyright 1999, 2001 Thomas W. Sarver 29 Class Diagram (ADO 2)

© Copyright 1999, 2001 Thomas W. Sarver 30 Instance Diagram DomainObject DomainView DomainView Items ADOView ADOView Items Recordset readwrite store readwrite retrieve ADOPersistence Connection transfer

© Copyright 1999, 2001 Thomas W. Sarver 31 Wrap Up ADO Met the architectural objectives –Can have multiple instances of PersistenceFactory and implementations of IPersistenceComponent in a system –DomainObject has methods like retrieve(Object) and store() to encapsulate the persistence layer –Can redeploy to another persistence mechanism by implementing IPersistenceComponent, View, and ViewItem

© Copyright 1999, 2001 Thomas W. Sarver 32 Wrap Up –Like all patterns, the “Crossing Chasms” pattern still leaves you with many design decisions. –Use the Broker pattern Avoid having the Domain Objects “know” how to persist themselves This makes it very difficult to redeploy to another persistence mechanism The use of DomainVisitor and DomainView make this possible –Use meta data when possible to represent the object mapping