SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Prof. Dr. Michael Helbig
     Montag, 18.02.2013
   IT-Berater

   Professor Mathematik & Informatik
   CCC
   AOP
   CDI
   JPA
   CCC
   AOP
   CDI
   JPA
   Wikipedia: http://de.wikipedia.org/wiki/Cross-Cutting_Concern
   Wikipedia: http://de.wikipedia.org/wiki/Cross-Cutting_Concern
   DZone: http://architects.dzone.com/articles/example-cross-cutting-concerns
   8 Core Concerns with 5 CCC
    ◦   Database Access
    ◦   Data Entities
    ◦   Worker
    ◦   Result Processing
    ◦   Process Flow Manager
    ◦   Email/Notification
    ◦   Error Handling
    ◦   Logging
   HINWEIS: nur Servlet Container (Tomcat 7)
   JSF mit Mojarra und Primefaces
   CDI mit Weld
   JPA mit Hibernate
   CCC
   AOP
   CDI
   JPA
   Wikipedia:
    http://de.wikipedia.org/wiki/Aspektorientierte_Programmierung
   CCC
   AOP
   CDI
   JPA
   more than a DI framework…
   JEE, auch Java-SE
   DI (Hollywood Principle: „Don‘t call us, we‘ll
    call you“)
   Producer Methods (Factory-Method-Pattern)
   Events (lokales Messaging)
   Interceptors (AOP)
   Decorators (Decorator-Pattern,
    „domainnahes“ AOP)
   JSR-299 auf JSR-330

   Prominente Implementierungen
    ◦ JBoss Weld (RI)
    ◦ Apache Open WebBeans
    ◦ Resin CanDI
   Annotation für das InterceptorBinding:

@InterceptorBinding
@Target({TYPE, METHOD})
@Retention(RUNTIME)
public @interface MyCCC {}
   Interceptor-Implementierung

@Interceptor @MyCCC
public class MyCCCInterceptor {

    @AroundInvoke
    public Object doCCC(InvocationContext context) {
      Object result = null;

        // logic before method call
        …

        // method call
        result = context.proceed();

        // logic after method call                    Aktivierung in beans.xml (Reihenfolge!)
        …

                                                  <beans>
        return result;
    }                                                 <interceptors>
}                                                      <class>de.bigdev.MyCCCInterceptor</class>
                                                      </interceptors>
                                                  </beans>
   Verwendung des Interceptors

@MyCCC
public class AnotherClass {…}

- oder -

@MyCCC
public void myMethod(){…}
   Interceptor: DebugMethod
   Interceptor: Transactional
   CCC
   AOP
   CDI
   JPA

    @PostLoad -„After Select Trigger“, z.B. Filtern


    @PrePersist - „Before Insert Trigger“

    @PostPersist - „After Insert Trigger“


    @PreUpdate -„Before Update Trigger“ (Dirty Check)

    @PostUpdate - „After Update Trigger“ (Dirty Check)


    @PreRemove - „Before Delete Trigger“

    @PostRemove - „After Delete Trigger“

    Verwendung direkt in Entity:

@Entity
public class MyEntity {
  …
  Date creationDate;
  …
  @PrePersist
  public void setCreationDate() {
      this.creationDate = new Date();
      }
  }
}

    Separate EntityListener-Klasse

public class MyEntityListener {
  @PrePersist
  public void setCreationDate(Object entity) {
      if (entity instanceof Person) {
               Person person = (Person) entity;
               person.setCreatedAt(new Date()); }}}

    Registrierung an den Entities

@Entity
@EntityListeners(MyEntityListener.class)
public class Person { … }
   Account: User und TS ergänzen
   AccountAudit: Schreiben des Logs
   Bspe von CCCs
   Heraustrennung mittels AOP
   AOP mit CDI
   AOP mit JPA
Lightweight AOP with CDI and JPA

Weitere ähnliche Inhalte

Andere mochten auch

Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesAntonio Goncalves
 
Come and Play! with Java EE 7
Come and Play! with Java EE 7Come and Play! with Java EE 7
Come and Play! with Java EE 7Antonio Goncalves
 
Case Study of Financial Web System Development and Operations with Oracle Web...
Case Study of Financial Web System Development and Operations with Oracle Web...Case Study of Financial Web System Development and Operations with Oracle Web...
Case Study of Financial Web System Development and Operations with Oracle Web...Hirofumi Iwasaki
 
Java EE 7 for Real Enterprise Systems
Java EE 7 for Real Enterprise SystemsJava EE 7 for Real Enterprise Systems
Java EE 7 for Real Enterprise SystemsHirofumi Iwasaki
 
Java one 2015 [con3339]
Java one 2015 [con3339]Java one 2015 [con3339]
Java one 2015 [con3339]Arshal Ameen
 
50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutesAntonio Goncalves
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Ray Ploski
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Hirofumi Iwasaki
 
IBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) ConceptIBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) Conceptejlp12
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuseejlp12
 

Andere mochten auch (16)

Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutes
 
Come and Play! with Java EE 7
Come and Play! with Java EE 7Come and Play! with Java EE 7
Come and Play! with Java EE 7
 
Case Study of Financial Web System Development and Operations with Oracle Web...
Case Study of Financial Web System Development and Operations with Oracle Web...Case Study of Financial Web System Development and Operations with Oracle Web...
Case Study of Financial Web System Development and Operations with Oracle Web...
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
Move from J2EE to Java EE
Move from J2EE to Java EEMove from J2EE to Java EE
Move from J2EE to Java EE
 
Java EE 7 for Real Enterprise Systems
Java EE 7 for Real Enterprise SystemsJava EE 7 for Real Enterprise Systems
Java EE 7 for Real Enterprise Systems
 
Java one 2015 [con3339]
Java one 2015 [con3339]Java one 2015 [con3339]
Java one 2015 [con3339]
 
50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes
 
Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7
 
Just enough app server
Just enough app serverJust enough app server
Just enough app server
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
IBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) ConceptIBM WebSphere Application Server (Clustering) Concept
IBM WebSphere Application Server (Clustering) Concept
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
RESTful web service with JBoss Fuse
RESTful web service with JBoss FuseRESTful web service with JBoss Fuse
RESTful web service with JBoss Fuse
 
What's new in Java EE 6
What's new in Java EE 6What's new in Java EE 6
What's new in Java EE 6
 

Ähnlich wie Lightweight AOP with CDI and JPA

MicroProfile 2.x: Der alternative Standard
MicroProfile 2.x: Der alternative StandardMicroProfile 2.x: Der alternative Standard
MicroProfile 2.x: Der alternative StandardOPEN KNOWLEDGE GmbH
 
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...GFU Cyrus AG
 
Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)
Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)
Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)Michael Kurz
 
2009 03 17 Spring101
2009 03 17 Spring1012009 03 17 Spring101
2009 03 17 Spring101gueste4be40
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit RustJens Siebert
 
Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?Josef Adersberger
 
Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?QAware GmbH
 
Legacy Code refaktorisieren
Legacy Code refaktorisierenLegacy Code refaktorisieren
Legacy Code refaktorisierenHendrik Lösch
 
JPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEJPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEhwilming
 
Hands-on Hystrix - Best Practices und Stolperfallen
Hands-on Hystrix - Best Practices und StolperfallenHands-on Hystrix - Best Practices und Stolperfallen
Hands-on Hystrix - Best Practices und Stolperfalleninovex GmbH
 
Enterprise Java Batch mit Spring
Enterprise Java Batch mit SpringEnterprise Java Batch mit Spring
Enterprise Java Batch mit Springdenschu
 
Python builds mit ant
Python builds mit antPython builds mit ant
Python builds mit antroskakori
 
WPF Dos n Don'ts - der WPF Rundumschlag
WPF Dos n Don'ts - der WPF RundumschlagWPF Dos n Don'ts - der WPF Rundumschlag
WPF Dos n Don'ts - der WPF RundumschlagHendrik Lösch
 
Einführung in ASP.NET Core Middlewares
Einführung in ASP.NET Core MiddlewaresEinführung in ASP.NET Core Middlewares
Einführung in ASP.NET Core MiddlewaresMatthias Jauernig
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013Maxim Zaks
 
Best Practices für TDD in JavaScript
Best Practices für TDD in JavaScriptBest Practices für TDD in JavaScript
Best Practices für TDD in JavaScriptSebastian Springer
 
Microprofile-Anwendungen mit Quarkus
Microprofile-Anwendungen mit Quarkus Microprofile-Anwendungen mit Quarkus
Microprofile-Anwendungen mit Quarkus gedoplan
 

Ähnlich wie Lightweight AOP with CDI and JPA (20)

MicroProfile 2.x: Der alternative Standard
MicroProfile 2.x: Der alternative StandardMicroProfile 2.x: Der alternative Standard
MicroProfile 2.x: Der alternative Standard
 
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
Java Code Quality: Gute Software braucht guten Code - Regeln für verständlich...
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)
Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)
Go Fullstack: Webanwendungen mit Java EE 6 bauen (W-JAX 2011)
 
2009 03 17 Spring101
2009 03 17 Spring1012009 03 17 Spring101
2009 03 17 Spring101
 
Microservices mit Rust
Microservices mit RustMicroservices mit Rust
Microservices mit Rust
 
Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?Cloud Native und Java EE: Freund oder Feind?
Cloud Native und Java EE: Freund oder Feind?
 
Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?Cloud Native & Java EE: Freund oder Feind?
Cloud Native & Java EE: Freund oder Feind?
 
Legacy Code refaktorisieren
Legacy Code refaktorisierenLegacy Code refaktorisieren
Legacy Code refaktorisieren
 
JPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SEJPA – Der Persistenz-­Standard in der Java EE und SE
JPA – Der Persistenz-­Standard in der Java EE und SE
 
Hands-on Hystrix - Best Practices und Stolperfallen
Hands-on Hystrix - Best Practices und StolperfallenHands-on Hystrix - Best Practices und Stolperfallen
Hands-on Hystrix - Best Practices und Stolperfallen
 
Enterprise Java Batch mit Spring
Enterprise Java Batch mit SpringEnterprise Java Batch mit Spring
Enterprise Java Batch mit Spring
 
Python builds mit ant
Python builds mit antPython builds mit ant
Python builds mit ant
 
WPF Dos n Don'ts - der WPF Rundumschlag
WPF Dos n Don'ts - der WPF RundumschlagWPF Dos n Don'ts - der WPF Rundumschlag
WPF Dos n Don'ts - der WPF Rundumschlag
 
Feature Flags mit Togglz
Feature Flags mit TogglzFeature Flags mit Togglz
Feature Flags mit Togglz
 
Einführung in ASP.NET Core Middlewares
Einführung in ASP.NET Core MiddlewaresEinführung in ASP.NET Core Middlewares
Einführung in ASP.NET Core Middlewares
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013
 
Best Practices für TDD in JavaScript
Best Practices für TDD in JavaScriptBest Practices für TDD in JavaScript
Best Practices für TDD in JavaScript
 
Microprofile-Anwendungen mit Quarkus
Microprofile-Anwendungen mit Quarkus Microprofile-Anwendungen mit Quarkus
Microprofile-Anwendungen mit Quarkus
 
GWT – Google Web Toolkit in der Praxis
GWT – Google Web Toolkit in der PraxisGWT – Google Web Toolkit in der Praxis
GWT – Google Web Toolkit in der Praxis
 

Lightweight AOP with CDI and JPA

  • 1. Prof. Dr. Michael Helbig Montag, 18.02.2013
  • 2. IT-Berater  Professor Mathematik & Informatik
  • 3. CCC  AOP  CDI  JPA
  • 4. CCC  AOP  CDI  JPA
  • 5. Wikipedia: http://de.wikipedia.org/wiki/Cross-Cutting_Concern
  • 6. Wikipedia: http://de.wikipedia.org/wiki/Cross-Cutting_Concern
  • 7. DZone: http://architects.dzone.com/articles/example-cross-cutting-concerns
  • 8. 8 Core Concerns with 5 CCC ◦ Database Access ◦ Data Entities ◦ Worker ◦ Result Processing ◦ Process Flow Manager ◦ Email/Notification ◦ Error Handling ◦ Logging
  • 9. HINWEIS: nur Servlet Container (Tomcat 7)  JSF mit Mojarra und Primefaces  CDI mit Weld  JPA mit Hibernate
  • 10.
  • 11. CCC  AOP  CDI  JPA
  • 12. Wikipedia: http://de.wikipedia.org/wiki/Aspektorientierte_Programmierung
  • 13. CCC  AOP  CDI  JPA
  • 14. more than a DI framework…  JEE, auch Java-SE  DI (Hollywood Principle: „Don‘t call us, we‘ll call you“)  Producer Methods (Factory-Method-Pattern)  Events (lokales Messaging)  Interceptors (AOP)  Decorators (Decorator-Pattern, „domainnahes“ AOP)
  • 15. JSR-299 auf JSR-330  Prominente Implementierungen ◦ JBoss Weld (RI) ◦ Apache Open WebBeans ◦ Resin CanDI
  • 16. Annotation für das InterceptorBinding: @InterceptorBinding @Target({TYPE, METHOD}) @Retention(RUNTIME) public @interface MyCCC {}
  • 17. Interceptor-Implementierung @Interceptor @MyCCC public class MyCCCInterceptor { @AroundInvoke public Object doCCC(InvocationContext context) { Object result = null; // logic before method call … // method call result = context.proceed(); // logic after method call  Aktivierung in beans.xml (Reihenfolge!) … <beans> return result; } <interceptors> } <class>de.bigdev.MyCCCInterceptor</class> </interceptors> </beans>
  • 18. Verwendung des Interceptors @MyCCC public class AnotherClass {…} - oder - @MyCCC public void myMethod(){…}
  • 19. Interceptor: DebugMethod  Interceptor: Transactional
  • 20. CCC  AOP  CDI  JPA
  • 21. @PostLoad -„After Select Trigger“, z.B. Filtern  @PrePersist - „Before Insert Trigger“  @PostPersist - „After Insert Trigger“  @PreUpdate -„Before Update Trigger“ (Dirty Check)  @PostUpdate - „After Update Trigger“ (Dirty Check)  @PreRemove - „Before Delete Trigger“  @PostRemove - „After Delete Trigger“
  • 22. Verwendung direkt in Entity: @Entity public class MyEntity { … Date creationDate; … @PrePersist public void setCreationDate() { this.creationDate = new Date(); } } }
  • 23. Separate EntityListener-Klasse public class MyEntityListener { @PrePersist public void setCreationDate(Object entity) { if (entity instanceof Person) { Person person = (Person) entity; person.setCreatedAt(new Date()); }}}  Registrierung an den Entities @Entity @EntityListeners(MyEntityListener.class) public class Person { … }
  • 24. Account: User und TS ergänzen  AccountAudit: Schreiben des Logs
  • 25. Bspe von CCCs  Heraustrennung mittels AOP  AOP mit CDI  AOP mit JPA