PA165: Service Tier I. Introduction Petr Adámek 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 2PA165: Service Tier BASIC CONCEPTS 3PA165: Service Tier Components Lifecycle • We need to control component lifecycle and configuration • Possible approaches – Hardcoded – Controlled by some container PA165: Service Tier 4 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 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 AOP • Template method – OOP approach – You need new class for each operation • AOP/Interceptors – Incompatible with pure OOP – More practical PA165: Service Tier 7 ARCHITECTURE PA165: Service Tier 8 Architecture Design Patterns • DAO • Service Façade • Adapter PA165: Service Tier 9 TRANSACTION MANAGEMENT PA165: Service Tier 10 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 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 Transactions Control • Usually global transactions • Usually declarative approach • Usually on Service Façade or Adapter level PA165: Service Tier 13 Questions ? 14PA165: Service Tier