SlideShare ist ein Scribd-Unternehmen logo
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
Lightweight AOP with CDI and JPA
   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

PPT
Was ist neu in Java 6, 7, 8, ...
PDF
Automatisierungmit NANT
PDF
JPA the Versant Way
ODP
To inject or not to inject: CDI is the question
PDF
Are app servers still fascinating
PPTX
Future of Java EE with SE 8 (revised)
PPTX
Java EE 6 Adoption in One of the World's Largest Online Financial Systems (fo...
PDF
Whats New In Java Ee 6
Was ist neu in Java 6, 7, 8, ...
Automatisierungmit NANT
JPA the Versant Way
To inject or not to inject: CDI is the question
Are app servers still fascinating
Future of Java EE with SE 8 (revised)
Java EE 6 Adoption in One of the World's Largest Online Financial Systems (fo...
Whats New In Java Ee 6

Andere mochten auch (16)

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

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

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

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
  • 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