SlideShare a Scribd company logo
Business layer
Lecturer: Ondrej Mihályi
Contents
●Multilayered application architecture
●Enterprise Java Beans
●Transaction creation and handling
●Java EE architectural patterns
Layers of Java EE application
Traditional transactions
tx.begin();
try {
// … executing in transaction
tx.commit
} catch (Exception e) {
tx.rollback();
}
How simple can transactions be?
@Inject ServiceBean service;
// before transaction
service.execute(); // running in transaction
// after transaction
What are EJBs?
● Represent service layer
● Components encapsulating business logic
● Automatic handling of transactions
● Accessible remotely outside of application
● Security authorization
Types of EJBs
● Session beans:
– Stateless, Stateful, Singleton
– Accessed directly via a method call
● Message-driven beans
– Exexcuted when message is delivered
Stateful Session Bean
● Stateful instance unique to the client
● Holds state between method calls
● Only one client can access at a time
● Must support serialization (swapping)
● @Stateful
When Stateful?
● The bean's state represents the interaction
between the bean and a specific client.
● The bean needs to hold information about
the client across method invocations.
● Behind the scenes, the bean manages the
work flow of several enterprise beans.
Stateless Session Bean
● State is not held between method calls
● Can be reused by multiple clients
● More efficient than Stateful
– Reused using a pool of beans
● Can implement a web service
● @Stateless
Business layer and transactions
Business layer and transactions
When Stateless?
● The bean does not have state.
● The bean methods are independent.
● The bean implements a web service.
● To improve performance, whenever
Stateful is not necessary.
Singleton Session Bean
● Similar to stateless, but:
– Single instance is reused by all clients
– State is held between method calls
● Can be created on application startup
● @Singleton (javax.ejb.Singleton)
When Singleton?
● When some data is shared by multiple
clients
● To perform an action at application startup
Message-driven Bean
● Single method onMessage(Message msg)
● Called when message received
● Otherwise resembles Stateless
– No state, can be pooled, shared by clients
● @MessageDriven
Business layer and transactions
When Message-driven?
● Asynchronous processing
– Distribute processing on multiple nodes
– Do not block other requests
– Queue execution after pending requests
Transaction management
● @TransactionManagement
● By container (default setting)
– Application server creates and closes transactions
– TransactionManagementType.CONTAINER
● By application
– Application calls methods on transaction object
– TransactionManagementType.BEAN
Container managed Tx
● @TransactionAttribute
● REQUIRED, REQUIRES_NEW,
NOT_SUPPORTED, …
● Configuration on class level, or for each
method
Application managed Tx
● @Inject UserTransaction tx;
● tx.begin(), tx.commit()
Asynchronous invocation
● Execute a business method in another
thread
● Runs in a new transaction
● Method either void or returns Future
● @Asynchronous
Remote business interface
● EJB can be accessible from outside of application
● Needs to implement an interface
– Marked be @Remote
● Exposed in JNDI registry
● Remote method invocation from outside of application
server
DAO pattern
● Data Access Object
● DAO objects are abstraction over persistence
layer
● Provide object-oriented encapsulation
● Single point of querying, entity creation and
persisting
DTO pattern
● Data Transfer Object
● Simple value objects to transfer data
between layers
● Used to transfer data specific to one layer
into another layer in various contexts and
forms
Service facade
● Groups multiple components
● Provides single access methods to execute
complicated business logic
● When multiple business components must run in
single transaction
● Represented by EJBs, which combine logic of multiple
simpler EJBs

More Related Content

PDF
Asynchronous Processing in Java/JEE/Spring
PDF
Thinking in Components
PDF
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
ODP
servlets and jsp
PPTX
Distributed Transaction Management in Spring & JEE
PPTX
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
PPTX
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
PPTX
Spring Transaction Management
Asynchronous Processing in Java/JEE/Spring
Thinking in Components
FRU Kathmandu: Adopting with Change Frontend Architecture and Patterns
servlets and jsp
Distributed Transaction Management in Spring & JEE
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
Spring Transaction Management

Viewers also liked (18)

PDF
Kick Start Jpa
PDF
JPA Optimistic Locking With @Version
ODP
Java Persistence API
PDF
Java persistence api 2.1
ODP
Ruslan Platonov - Transactions
PDF
Optimierung von JPA-­Anwendungen
PPTX
Jpa 2.0 in java ee 6 part ii
PPTX
Евгений Капинос "Advanced JPA (Java Persistent API)"
PDF
JPA 2.1 performance tuning tips
PPTX
JPA For Beginner's
PPS
JPA - Java Persistence API
PDF
Hibernate ORM: Tips, Tricks, and Performance Techniques
PDF
JPA and Hibernate
PDF
Overview of JPA (Java Persistence API) v2.0
PPT
Java Persistence API (JPA) Step By Step
ODP
ORM, JPA, & Hibernate Overview
PPTX
Introduction to JPA Framework
ODP
JPA Best Practices
Kick Start Jpa
JPA Optimistic Locking With @Version
Java Persistence API
Java persistence api 2.1
Ruslan Platonov - Transactions
Optimierung von JPA-­Anwendungen
Jpa 2.0 in java ee 6 part ii
Евгений Капинос "Advanced JPA (Java Persistent API)"
JPA 2.1 performance tuning tips
JPA For Beginner's
JPA - Java Persistence API
Hibernate ORM: Tips, Tricks, and Performance Techniques
JPA and Hibernate
Overview of JPA (Java Persistence API) v2.0
Java Persistence API (JPA) Step By Step
ORM, JPA, & Hibernate Overview
Introduction to JPA Framework
JPA Best Practices
Ad

Similar to Business layer and transactions (20)

PPTX
EJB 3.0 course Sildes and matrial
PDF
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
PDF
Design & Develop Batch Applications in Java/JEE
PDF
Introduction to concurrent programming with akka actors
PDF
Introduction to concurrent programming with Akka actors
PPT
Session 9 Tp9
ODP
Monolithic to Microservices Architecture - STM 6
PDF
OpenWebBeans and DeltaSpike at ApacheCon
PPTX
Transaction and concurrency pitfalls in Java
PDF
Play Framework
PPT
PDF
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
PDF
Java EE 7 Recipes for Concurrency - JavaOne 2014
PPTX
Breaking down a monolith
PPSX
Microsoft Hekaton
PDF
Viktor Turskyi "Effective NodeJS Application Development"
ODP
Hibernate complete Training
PDF
Programming with Threads in Java
PDF
The working architecture of NodeJs applications
PDF
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
EJB 3.0 course Sildes and matrial
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
Design & Develop Batch Applications in Java/JEE
Introduction to concurrent programming with akka actors
Introduction to concurrent programming with Akka actors
Session 9 Tp9
Monolithic to Microservices Architecture - STM 6
OpenWebBeans and DeltaSpike at ApacheCon
Transaction and concurrency pitfalls in Java
Play Framework
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
Java EE 7 Recipes for Concurrency - JavaOne 2014
Breaking down a monolith
Microsoft Hekaton
Viktor Turskyi "Effective NodeJS Application Development"
Hibernate complete Training
Programming with Threads in Java
The working architecture of NodeJs applications
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
Ad

More from Ondrej Mihályi (12)

PDF
Easily scale enterprise applications using distributed data grids
PDF
Elastic and Cloud-ready Applications with Payara Micro
PPTX
Bed con - MicroProfile: A Quest for a lightweight and reactive Enterprise Ja...
PDF
Easily scale enterprise applications using distributed data grids
ODP
How to bake_reactive_behavior_into_your_java_ee_applications
ODP
How to bake reactive behavior into your Java EE applications
ODP
How to bake reactive behavior into your Java EE applications
ODP
How to bake reactive behavior into your Java EE applications
ODP
How to bake reactive behavior into your Java EE applications
ODP
Working with jpa
ODP
Maven in Java EE project
ODP
Java EE web project introduction
Easily scale enterprise applications using distributed data grids
Elastic and Cloud-ready Applications with Payara Micro
Bed con - MicroProfile: A Quest for a lightweight and reactive Enterprise Ja...
Easily scale enterprise applications using distributed data grids
How to bake_reactive_behavior_into_your_java_ee_applications
How to bake reactive behavior into your Java EE applications
How to bake reactive behavior into your Java EE applications
How to bake reactive behavior into your Java EE applications
How to bake reactive behavior into your Java EE applications
Working with jpa
Maven in Java EE project
Java EE web project introduction

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
August Patch Tuesday
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Chapter 5: Probability Theory and Statistics
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
project resource management chapter-09.pdf
PDF
Approach and Philosophy of On baking technology
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Tartificialntelligence_presentation.pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Encapsulation theory and applications.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Enhancing emotion recognition model for a student engagement use case through...
DP Operators-handbook-extract for the Mautical Institute
1 - Historical Antecedents, Social Consideration.pdf
August Patch Tuesday
Univ-Connecticut-ChatGPT-Presentaion.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
A Presentation on Artificial Intelligence
Chapter 5: Probability Theory and Statistics
MIND Revenue Release Quarter 2 2025 Press Release
project resource management chapter-09.pdf
Approach and Philosophy of On baking technology
A novel scalable deep ensemble learning framework for big data classification...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Getting Started with Data Integration: FME Form 101
Tartificialntelligence_presentation.pptx
Hybrid model detection and classification of lung cancer
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Encapsulation theory and applications.pdf

Business layer and transactions

  • 2. Contents ●Multilayered application architecture ●Enterprise Java Beans ●Transaction creation and handling ●Java EE architectural patterns
  • 3. Layers of Java EE application
  • 4. Traditional transactions tx.begin(); try { // … executing in transaction tx.commit } catch (Exception e) { tx.rollback(); }
  • 5. How simple can transactions be? @Inject ServiceBean service; // before transaction service.execute(); // running in transaction // after transaction
  • 6. What are EJBs? ● Represent service layer ● Components encapsulating business logic ● Automatic handling of transactions ● Accessible remotely outside of application ● Security authorization
  • 7. Types of EJBs ● Session beans: – Stateless, Stateful, Singleton – Accessed directly via a method call ● Message-driven beans – Exexcuted when message is delivered
  • 8. Stateful Session Bean ● Stateful instance unique to the client ● Holds state between method calls ● Only one client can access at a time ● Must support serialization (swapping) ● @Stateful
  • 9. When Stateful? ● The bean's state represents the interaction between the bean and a specific client. ● The bean needs to hold information about the client across method invocations. ● Behind the scenes, the bean manages the work flow of several enterprise beans.
  • 10. Stateless Session Bean ● State is not held between method calls ● Can be reused by multiple clients ● More efficient than Stateful – Reused using a pool of beans ● Can implement a web service ● @Stateless
  • 13. When Stateless? ● The bean does not have state. ● The bean methods are independent. ● The bean implements a web service. ● To improve performance, whenever Stateful is not necessary.
  • 14. Singleton Session Bean ● Similar to stateless, but: – Single instance is reused by all clients – State is held between method calls ● Can be created on application startup ● @Singleton (javax.ejb.Singleton)
  • 15. When Singleton? ● When some data is shared by multiple clients ● To perform an action at application startup
  • 16. Message-driven Bean ● Single method onMessage(Message msg) ● Called when message received ● Otherwise resembles Stateless – No state, can be pooled, shared by clients ● @MessageDriven
  • 18. When Message-driven? ● Asynchronous processing – Distribute processing on multiple nodes – Do not block other requests – Queue execution after pending requests
  • 19. Transaction management ● @TransactionManagement ● By container (default setting) – Application server creates and closes transactions – TransactionManagementType.CONTAINER ● By application – Application calls methods on transaction object – TransactionManagementType.BEAN
  • 20. Container managed Tx ● @TransactionAttribute ● REQUIRED, REQUIRES_NEW, NOT_SUPPORTED, … ● Configuration on class level, or for each method
  • 21. Application managed Tx ● @Inject UserTransaction tx; ● tx.begin(), tx.commit()
  • 22. Asynchronous invocation ● Execute a business method in another thread ● Runs in a new transaction ● Method either void or returns Future ● @Asynchronous
  • 23. Remote business interface ● EJB can be accessible from outside of application ● Needs to implement an interface – Marked be @Remote ● Exposed in JNDI registry ● Remote method invocation from outside of application server
  • 24. DAO pattern ● Data Access Object ● DAO objects are abstraction over persistence layer ● Provide object-oriented encapsulation ● Single point of querying, entity creation and persisting
  • 25. DTO pattern ● Data Transfer Object ● Simple value objects to transfer data between layers ● Used to transfer data specific to one layer into another layer in various contexts and forms
  • 26. Service facade ● Groups multiple components ● Provides single access methods to execute complicated business logic ● When multiple business components must run in single transaction ● Represented by EJBs, which combine logic of multiple simpler EJBs