1 Persistence as an Aspect: TopLink and AOP Shaun Smith Product Manager Jim Clark Solution Architect Merrick Schincariol Senior Engineer.

Slides:



Advertisements
Similar presentations
Simplifications of Context-Free Grammars
Advertisements

1 Senn, Information Technology, 3 rd Edition © 2004 Pearson Prentice Hall James A. Senns Information Technology, 3 rd Edition Chapter 7 Enterprise Databases.
C2: Introduction to OpenEdge® Integration Technologies
Chapter 1: The Database Environment
Chapter 7 System Models.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide.
Chapter 8 Software Prototyping.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
January 30, 2014 Copyright Jim Farley Beyond JDBC: Java Object- Relational Mappings Jim Farley e-Commerce Program Manager GE Research and Development
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
1 Hyades Command Routing Message flow and data translation.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination. Introduction to the Business.
21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
18 Copyright © 2005, Oracle. All rights reserved. Distributing Modular Applications: Introduction to Web Services.
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
15 Copyright © 2005, Oracle. All rights reserved. Container-Managed Relationships (CMRs)
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
Create an Application Title 1A - Adult Chapter 3.
Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity.
Chapter 6 File Systems 6.1 Files 6.2 Directories
Database Systems: Design, Implementation, and Management
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
Week 2 The Object-Oriented Approach to Requirements
Information Systems Today: Managing in the Digital World
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Database Performance Tuning and Query Optimization
Database Design Process
© Paradigm Publishing, Inc Access 2010 Level 1 Unit 1Creating Tables and Queries Chapter 2Creating Relationships between Tables.
Microsoft Confidential. We look at the world... with our own eyes...
Microsoft Access.
Displaying Data from Multiple Tables
Chapter Information Systems Database Management.
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
1 tRelational/DPS Overview. 2 ADABAS Data Transfer: business needs and issues tRelational & DPS Overview Summary Questions? Demo Agenda.
XML and Databases Exercise Session 3 (courtesy of Ghislain Fourny/ETH)
R12 Assets A Look Inside SM. Copyright © 2008 Chi-Star Technology SM -2- High-Level Overview R12 Setups –Subledger Accounting –ADI Templates –XML Reports.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Database System Concepts and Architecture
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Executional Architecture
Chapter 2 Entity-Relationship Data Modeling: Tools and Techniques
TopLink: Now and in the future, O-R Mapping Product of Choice Doug Clarke Principal Product Manager, Oracle9iAS TopLink Oracle Corporation.
Chapter 10: The Traditional Approach to Design
Analyzing Genes and Genomes
Systems Analysis and Design in a Changing World, Fifth Edition
Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 12 View Design and Integration.
Chapter 12: Designing Databases
Essential Cell Biology
Chapter 15 A Table with a View: Database Queries.
Intracellular Compartments and Transport
PSSA Preparation.
Chapter 11 Component-Level Design
Essential Cell Biology
Chapter 13 The Data Warehouse
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 13 Slide 1 Application architectures.
Energy Generation in Mitochondria and Chlorplasts
Management Information Systems, 10/e
Introduction Peter Dolog dolog [at] cs [dot] aau [dot] dk Intelligent Web and Information Systems September 9, 2010.
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
Hibernate Persistence. What is Persistence Persist data to database or other storage.  In OO world, persistence means persist object to external storage.
Presentation transcript:

1 Persistence as an Aspect: TopLink and AOP Shaun Smith Product Manager Jim Clark Solution Architect Merrick Schincariol Senior Engineer

2 Agenda TopLink in a Nutshell Indirection Change Tracking Enforcing Read-Only Semantics Solutions Summary

3 TopLink in a Nutshell O/R, and now O/X, framework. Object-relational mappings maintained external to the object model, typically in a language such as XML Java reflection leveraged to query and update object state without coupling the domain class to the persistence implementation Requests to query and persist objects are routed through a persistence manager that interprets the metadata and maintains the domain object graph

4 Meta-Data Driven Persistence Application Database SQL Rows Objects Query TopLink Cache Cache Hit? Cache Results? JDBCJDBC SQL EJB QL OO (API/MW) Query By Example Query Framework Stored Procs Object Builder Mapping Meta-Data

5 Mapping The activity of Mapping is the process of connecting objects/attributes to tables/columns Customer id: int name: String creditRating: int CUST IDNAMEC_RATING

6 Mapping Workbench (MW) For graphically assembling and managing metadata information, a user inputs information that is required to store or retrieve objects from database.

7 Associating a Class to a Table Multiple-table mapping is supported.

8 Mappings in Workbench 1.Select the attribute. 2.Select the mapping type. 3.Enter the mapping information. Mapping properties 1 2 3

9 ORM Metadata <attribute-mapping xsi:type="toplink:one-to-one-mapping"> detective com.toplink.Detective <source-field table= CRIME_SCENE name= DETECTIVE_ID" xsi:type="column"/> <target-field table= DETECTIVE name= ID" xsi:type="column"/> …

10 Simple Object Model Customer id: int name: String creditRating: int Address id: int city: String zip: String 1:1 Relationship

11 Typical 1-1 Relationship Schema CUST IDNAME A_ID C_RATING ADDR IDCITYZIP

12 Many possible Schemas… CUST IDNAMEC_RATE C_ID ADDR IDCITYZIP CUST IDNAMEC_RATING C_ID ADDR IDCITYZIP A_ID CUST_ADDR C_ID CUST IDNAMECITY ZIPC_RATING CUST IDNAME A_ID C_RATING ADDR IDCITYZIP

13 Even More … CUST IDNAME A_ID ADDR IDCITYZIP CUST_CREDIT ID C_RATING CUST IDNAME ADDR IDCITYZIP CUST_CREDIT ID C_RATING A_ID CUST IDNAME ADDR IDCITYZIP CUST_CREDIT ID C_RATING A_ID CC_ID CUST IDNAME CUST_CREDIT IDC_RATING ADDR IDCITYZIPC_ID CUST IDNAME CUST_CREDIT ID C_RATING ADDR IDCITYZIPC_ID

14 Mapping Summary Just showed nine valid ways a 1-1 relationship could be represented in a database Without good support, designs will be forced Imagine the flexibility needed for other mappings like 1-M and M-M TopLink gives J2EE developers and DBAs the flexibility to do what they need to do

15 Challenges of Persistence Performancedata access is expensive Persistence framework APIs have a habit of working their way into the domain model and business logic. Object References – References map to foreign key relationships How can we ensure that read-only or shared objects are not accidentally modified? How can we control when queries are executed in response to operations on the domain model?

16 Using TopLink Map Java objects to database using Mapping Workbench Write queries using Mapping Workbench Output: XML metadata and Java objects Concerns have already been separated OR HAVE THEY?!?!!!?!!

17 Separable Concern: Indirection Defers expensive joins to infrequently used data from slowing down the overall performance of an application. The entire state of an object is not necessarily required at the point when it is first retrieved. We may only want basic fields to be retrieved with relationships to other persistence objects resolved only when they are accessed.

18 One-to-one public class DomainA { ValueHolderInterface relation; public DomainB getRelation() { return (DomainB) relation.getValue(); } public void setRelation(DomainB newRel) { relation.setValue(newRel); } }

19 Lazy Loading of Collections Traditional Solution: introduce proxy collection – The persistence manager transparently introduces proxies to handle lazy loading of collection relationships. – Non-intrusivebut domain objects must define collection attributes as interfaces (e.g., List), not concrete classes. Metadata used successfully for years to introduce advice on: technique predates Java This technique has been used successfully for years using to modify object structure transparently!

20 Transparent One-to-Many Lazy Loading

21 Still tangled for one-to-ones public class DomainA { ValueHolderInterface relation; public DomainB getRelation() { return (DomainB) relation.getValue(); } public void setRelation(DomainB newRel) { relation.setValue(newRel); } }

22 Lazy One-to-One with Aspects Java source free of persistence code Choice of Lazy or Active loading of one-to-one relationships is orthogonal to application behaviorpersistence concern Benefits of Aspect approach – Aspects replace hard coded behavior with a declarative specification – Persistence performance tuning usually involves adjusting loading behavior

23 Typical user code public void calcDateRange() { // … Date startDate = this.start; // … this.start = newStart; // … }

24 Relevant Join Points Method Joinpoints – around advice on method execution pointcuts can be leveraged to implement lazy loading – Many programmers dont self-encapsulate field access Field Joinpoints – Field interception is the most effective way of providing transparent persistence operations. – Field interception may introduce unintended side effects for performance or data consistency. – Field join point usage is often discouraged for new AOP developers.

25 Higher level concerns Session management Transaction demarcation Application profiles – Read only – Read mostly

26 Read Mostly Problem Most use cases are read mostly – Read 1000 objects, modify one and commit Persistence is never free TopLink approach – Client session for reads – UnitOfWork for writes

27 Historic Approach

28 Aspect Approach

29 Change Tracking Advice public void setValue(String value) { this.value = value; markFieldDirty(); }

30 Read Only Profile How to ensure maximum performance in the read only case? – What about caching?

31 Enforcing Read Only Semantics Caches in persistence frameworks are essential standard components that help to maximize performance. Shared caches are vulnerable to data corruption. Protection aspects may be implemented to ensure that read-only objects stay that way. – Putfield join point

32 The Challenge Separate persistence concerns from domain model without changing core TopLink behavior or implementation Leverage existing TopLink object-relational metadata to generate aspects so the customer doesnt have to Provide a solution that is transparent for most customers

33 Writing Persistence Aspects Persistence advice needs access to low level/internal apis that are not typically useful for developers. – The method calls to correctly synchronize this work with the persistence manager are likely internal and certainly not portable. Meta-data identifies all relevant joinpoints and allows us to know what is the correct adviceexisting meta data is enoughdidnt need to add anything to current TL meta-data. – Evaluating the relationship in an aspect and assigning it to the domain object will confuse the persistence manager when it looks for modified objects. Aspects are still the right answer, but the question is who should be providing them.

34 AspectJ Solution Wrote tool to generate AspectJ aspects from XML metadata Pro: Easy to develop, leverages existing technology Con: Not transparent, requires build changes

35 Custom Solution Customer interests best reflected through Load Time Weave architecture No desire to produce yet another AOP framework Fixed set of aspects implemented most efficiently through a custom weaver

36 LTW Challenges Lifecycle of persistent objects is different – Objects are frequently serialized – Serialized objects may be reified in an unmanaged environment LTW integration requires custom solution for each deployment environment – Application server integration – Two tier client (primarily for testing) Compile time weave still required for certain deployment scenarios

37 The Future Initial reaction has been positive Exploring other persistence aspects Tracking evolution of AOP frameworks in hope of moving away from custom weaver

38 Summary Provides improvements in performance and simplification of application design. Does not reflect any major change in TopLink direction – Persistence still metadata driven Aspect-based persistence is an option alongside traditional reflection-based solution – Aspects not (currently) accessible to user – Just an implementation technique