Spring Transaction & Spring AOP

Slides:



Advertisements
Similar presentations
AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Advertisements

21 Copyright © 2005, Oracle. All rights reserved. Oracle Application Server 10g Transaction Support.
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
Aspect Oriented Programming - AspectJ Radhika Rajput.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
Copyright © 2008 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. Andrew Stone Common Security.
Spring AOP Aspect Oriented Programming
ASPECT ORIENTED SOFTWARE DEVELOPMENT Prepared By: Ebru Doğan.
Enterprise Applications & Java/J2EE Technologies Dr. Douglas C. Schmidt Professor of EECS.
Aspect Oriented Programming Written by Michael Beder.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Version # Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999 by Carnegie.
TRANSACTION PROCESSING TECHNIQUES BY SON NGUYEN VIJAY RAO.
Agenda What is Hibernate Spring Integration Questions Overview
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
Introduction to the Spring Framework Rajesh. Spring Mission Statement J2EE should be easier to use OO design is more important than any implementation.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Aspect Oriented Programming (AOP) in.NET Brent Krueger 12/20/13.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.
Java Transaction API Sean C. Sullivan
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
Modularizing Web Services Management with AOP María Agustina Cibrán, Bart Verheecke { Maria.Cibran, System and Software Engineering.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Spring Training 17/09/ Dependency Injection.
Aspect Oriented Programming Gülşah KARADUMAN.
A Distributed Aspect-Oriented System for J2EE Applications Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) Background - As benefits.
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Transaction Services in Component Frameworks Bruce Kessler Comp250CBS March 2, 2004.
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
1 Transactions Michael Brockway Sajjad Shami CG0165: Advanced Applications Development in Java Northumbria University School of Computing, Engineering.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
1 Spring Framework April, 2012 Lam Ho Lam To. © 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2 1.Spring Overview 2.Framework.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Aspect Oriented Programming Adlux Consultancy Services Pvt Ltd
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Comparison of Different AOP Approaches Presented by: Xiaojing Wang.
JPA Transactions
Introduction to Yan Cui Aspect Oriented Programming by
Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Spring 2012.
红杉树(中国)信息技术有限公司公司 地址:杭州市天目山路 176 号西湖数源软件园 11 号楼 3 层 电话: (86) Transaction & JAVA Fondy Wang 12/7/07.
Spring Framework BT Team 25/02/ Spring A lightweight framework that addresses each tier in a Web application. Presentation layer – An MVC framework.
Enterprise Java v121030Java EE Transactions1. Enterprise Java v121030Java EE Transactions2 Goals Understand the basic concepts behind a transaction Be.
Developing with the Framework Zach A. Thomas, Texas State University
L’origine dei mali: le dipendenze tra componenti Stefano Leli 14° Workshop DotNetMarche Venerdì 16 aprile
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework.
 Is a programming paradigm  Extends OOP  Enables modularization of cross cutting concerns.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Prepared by Mehmet Küçüksayan Mustafa Ecmel Özdemir
Java Exceptions a quick review….
Software Engineering Lecture 7
Chengyu Sun California State University, Los Angeles
Aspect-Oriented Generation of the API Documentation for AspectJ
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
By Ru Shen Department of Computer Science UAlbany, 2008
Aspect-Oriented Programming
Aspect-Oriented Design and Patterns
Chengyu Sun California State University, Los Angeles
Structuring Adaptive Applications using AspectJ and AOM
CS520 Web Programming Spring – Aspect Oriented Programming
AspectAda Aspect-Oriented Programming for Ada95
Aspect Oriented Software Design
Objectives In this lesson, you will learn about:
Aspect Oriented Programming
Presentation transcript:

Spring Transaction & Spring AOP ศิรส สุภาวิตา @siros_s

Agenda: Spring Transaction Why Spring Transaction Transaction Manager Declarative Transaction with Annotation @Transactional Propagation Exception Handling

Why Spring Transaction? Uniform API Transactional resource synchronization On and off server Declarative Transaction

What about JTA? Require J(2)EE container (server) Require EJB for declarative transaction Necessary for distributed transaction

Uniform API Application Spring Transaction JDBC ORM JCA JTA

Transactional Resource Sync Spring Transaction

On and Off Server Spring Spring Spring Servlet Container J(2)EE Java

Declarative Transaction B C Begin Commit D Begin Commit D B C

Declarative Transaction (cont.) Transaction Demarcation Transaction logic is NOT the main business logic Reuse business logic with different transaction logic Programmatic transaction demarcation is NOT the answer

Transactional Resource Transaction Manager Transactional Resource Transaction Manager

Transaction Annotation Use annotation to declare transaction scope Require just one line of config in XML

Example: MyService

Example: Transactional MyService

Example: Detailed MyService

Propagation Define how transaction manager handles transaction SUPPORTS NOT_SUPPORTED REQUIRED REQUIRES_NEW MANDATORY NEVER NESTED

Example: Propagation A B C D REQUIRED SUPPORTS REQUIRED MANDAROTY REQUIRES_NEW NEVER A B C D REQUIRES_NEW

Exception Handling Default behavior Rollback for unchecked exception No rollback for checked exception Can be changed with @Transactional properties rollbackFor rollbackForClassname noRollbackFor noRollbackForClassname

Example: Exception Handling

Wait!! There is a better way!! Q & A

Agenda: Spring AOP Problems of existing approach AOP Definition AOP Proxy Spring AOP Spring Transaction with AOP

Problems?? Transaction policy is still defined locally on each class rather than globally across all classes. Modularity & Reusability Scattering & Tangling Even a medium sized application has multiple “concerns”.

Example of Transaction Policy All top level service operations must begin a new transaction (REQUIRES_NEW). Lower level service operations must operate under an existing transaction (MANDATORY). Data access operation should operate under a transaction (REQUIRES). The problem is that policies or concerns are usually applied based on neither class nor class hierarchy. They are mostly random.

Scattering obj.lastModified = new Date(); Customer cust = new Customer(); … cust.lastModified = new Date(); saveCustomer(cust); Invoice inv = new Invoice(); … inv.lastModified = new Date(); saveInvoice(inv); Course crs = new Course(); … crs.lastModified = new Date(); saveCourse(crs);

Scattering: Modified obj.lastModifiedBy = currentUser(); obj.lastModified = new Date(); Customer cust = new Customer(); … cust.lastModifiedBy = currentUser(); cust.lastModified = new Date(); saveCustomer(cust); Invoice inv = new Invoice(); … inv.lastModifiedBy = currentUser(); inv.lastModified = new Date(); saveInvoice(inv); Course crs = new Course(); … crs.lastModifiedBy = currentUser(); crs.lastModified = new Date(); saveCourse(crs);

Tangling obj.lastModified = new Date(); Course crs = new Course(); … saveCourse(crs); logger.log(“Start operation”); logger.log(“Start operation”); tx = new Transaction(); tx.begin(); Course crs = new Course(); crs.id = generateUUID(); … crs.lastModified = new Date(); saveCourse(crs); tx.commit(); obj.id = generateUUID(); tx = new Transaction(); tx.begin(); … tx.commit();

Aspect-Oriented Programming Concerns are designed and implemented independently During build time or runtime, concerns are compiled into full functioned application. This process is called “weaving”.

AOP Definition Aspect Join Point Pointcut Advice

Join Point public void createCustomer() { x Customer cust = new Customer(); … saveCustomer(cust); }

Pointcut public void createCustomer() { x Customer cust = new Customer(); … saveCustomer(cust); }

Advice public void createCustomer() { logger.log(“Start create…”); Customer cust = new Customer(); cust.id = generateUUID(); … cust.lastModified = new Date(); saveCustomer(cust); }

AOP Proxy Caller Target Object Advice Proxy Advice Advice

Spring AOP

Supported Pointcuts execution within this target args

execution execution(<modifier> <return-type> <declaring-type> <method-name> (<param>) <throws>) execution(* *(..)) execution(public void set*(..)) execution(public * com.spring66.service.*.*(..)) execution(public * com.spring66.service..*.*(..))

within within(com.spring66.service.*) within(com.spring66.service..*)

Advice before after after-returning after-throwing around

Spring Transaction with AOP

Is that all? Q & A