Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lightweight AOP with CDI and JPA

1,547 views

Published on

  • http://dbmanagement.info/Tutorials/Java.htm
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Lightweight AOP with CDI and JPA

  1. 1. Prof. Dr. Michael Helbig Montag, 18.02.2013
  2. 2.  IT-Berater Professor Mathematik & Informatik
  3. 3.  CCC AOP CDI JPA
  4. 4.  CCC AOP CDI JPA
  5. 5.  Wikipedia: http://de.wikipedia.org/wiki/Cross-Cutting_Concern
  6. 6.  Wikipedia: http://de.wikipedia.org/wiki/Cross-Cutting_Concern
  7. 7.  DZone: http://architects.dzone.com/articles/example-cross-cutting-concerns
  8. 8.  8 Core Concerns with 5 CCC ◦ Database Access ◦ Data Entities ◦ Worker ◦ Result Processing ◦ Process Flow Manager ◦ Email/Notification ◦ Error Handling ◦ Logging
  9. 9.  HINWEIS: nur Servlet Container (Tomcat 7) JSF mit Mojarra und Primefaces CDI mit Weld JPA mit Hibernate
  10. 10.  CCC AOP CDI JPA
  11. 11.  Wikipedia: http://de.wikipedia.org/wiki/Aspektorientierte_Programmierung
  12. 12.  CCC AOP CDI JPA
  13. 13.  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)
  14. 14.  JSR-299 auf JSR-330 Prominente Implementierungen ◦ JBoss Weld (RI) ◦ Apache Open WebBeans ◦ Resin CanDI
  15. 15.  Annotation für das InterceptorBinding:@InterceptorBinding@Target({TYPE, METHOD})@Retention(RUNTIME)public @interface MyCCC {}
  16. 16.  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>
  17. 17.  Verwendung des Interceptors@MyCCCpublic class AnotherClass {…}- oder -@MyCCCpublic void myMethod(){…}
  18. 18.  Interceptor: DebugMethod Interceptor: Transactional
  19. 19.  CCC AOP CDI JPA
  20. 20.  @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“
  21. 21.  Verwendung direkt in Entity:@Entitypublic class MyEntity { … Date creationDate; … @PrePersist public void setCreationDate() { this.creationDate = new Date(); } }}
  22. 22.  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 { … }
  23. 23.  Account: User und TS ergänzen AccountAudit: Schreiben des Logs
  24. 24.  Bspe von CCCs Heraustrennung mittels AOP AOP mit CDI AOP mit JPA

×