logo_EMBEDIT_RGB.jpg PA165: Service Tier I. Introduction Petr Adámek logo_EMBEDIT_RGB.jpg Content: Service Tier •Basic Concepts –Component lifecycle and configuration, IoC –AOP, Interceptors •Architecture of Application Tier –Overview –DAO, Services, Service Façade, Adapters •Transaction Management –Where and How control transactions –Local vs. Global Transactions –JTA 2 PA165: Service Tier logo_EMBEDIT_RGB.jpg BASIC CONCEPTS • 3 PA165: Service Tier logo_EMBEDIT_RGB.jpg Components Lifecycle •We need to control component lifecycle and configuration •Possible approaches –Hardcoded –Controlled by some container PA165: Service Tier 4 logo_EMBEDIT_RGB.jpg Component Configuration •Components needs some resources (other components, data sources, etc.) and configuration •Configured statically –Hardcoded •Configured dynamically at runtime (IoC) –Lookup •JNDI •ServiceLoader •NetBeans Lookup –IoC •Configured by anotations •Configured by XML descriptor • PA165: Service Tier 5 logo_EMBEDIT_RGB.jpg AOP •We often need to include some aspects that affects lots of our application parts –Transaction management –Authorization –Validation –Logging or auditing –Exception handling or translation • PA165: Service Tier 6 logo_EMBEDIT_RGB.jpg AOP •Template method –OOP approach –You need new class for each operation •AOP/Interceptors –Incompatible with pure OOP –More practical PA165: Service Tier 7 logo_EMBEDIT_RGB.jpg ARCHITECTURE • PA165: Service Tier 8 logo_EMBEDIT_RGB.jpg Architecture Design Patterns •DAO •Service Façade •Adapter PA165: Service Tier 9 logo_EMBEDIT_RGB.jpg TRANSACTION MANAGEMENT • PA165: Service Tier 10 logo_EMBEDIT_RGB.jpg Local vs. Global Transactions •Local transactions –Controlled by API of given low-level technology –Depend on given technology – •Global transactions –Controlled independently on persistent technology –Allows to include more operations into single transaction –Distributed Transaction support (transaction could include operations on different databases or other transactional resources) –JTA – PA165: Service Tier 11 logo_EMBEDIT_RGB.jpg Transactions and threads •Problem with the scope of the transaction –Different requests must be processed in different transactions (we can’t share transaction between threads) –One transaction includes more operations in different components (we can’t create new transaction for each operation) •Solution –Transaction is bound to thread –EntityManager proxy, ThreadLocal variable PA165: Service Tier 12 logo_EMBEDIT_RGB.jpg Transactions Control •Usually global transactions •Usually declarative approach •Usually on Service Façade or Adapter level PA165: Service Tier 13 logo_EMBEDIT_RGB.jpg Questions •? 14 PA165: Service Tier