• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Lightweight AOP with CDI and JPA
 

Lightweight AOP with CDI and JPA

on

  • 905 views

 

Statistics

Views

Total Views
905
Views on SlideShare
677
Embed Views
228

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 228

http://www.bigdev.de 228

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Lightweight AOP with CDI and JPA Lightweight AOP with CDI and JPA Presentation Transcript

    • 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 @MyCCCpublic 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@MyCCCpublic class AnotherClass {…}- oder -@MyCCCpublic 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:@Entitypublic class MyEntity { … Date creationDate; … @PrePersist public void setCreationDate() { this.creationDate = new Date(); } }}
    •  Separate EntityListener-Klassepublic 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