Java Reference
In-Depth Information
by the container. The evolution continues in EJB 3 (described later in this
chapter), which simplifies the programming model considerably by enabling
POJOs to be EJB s.
1.1.2
A typical EJB 2 application architecture
Let's look at an example of a typical EJB 2 application architecture. Imagine that
you work for a bank and you have to write a service to transfer money between two
accounts. Figure 1.1 shows how you might use EJB to implement the money trans-
fer service.
The business logic consists of the TransferService EJB and data access objects
( DAO s). The TransferService EJB is a session bean that defines the interface that
the business logic exposes to the presentation tier. It also implements the busi-
ness logic.
The TransferService EJB calls the AccountDAO to retrieve the two accounts, and
performs any necessary checks and other business logic. For example, it verifies
that fromAccount contains sufficient funds and will not become overdrawn. The
TransferService EJB calls AccountDAO again to save the updated accounts in the
database. It records the transfer by calling TransactionDAO . The TransferService
<<session bean>>
TransferService
TransferResult transfer(fromAccountId, toAccountId, amount)
AccountDAO
TransactionDAO
<<dto>>
TransferResult
AccountDTO loadAccount(accountId)
saveAccount(AccountDTO)
createTransaction()
findRecentTxns()
AccountDTO
<<dto>>
Transaction
Details
accountId
balance
txnId
date
Figure 1.1
The money transfer service implemented using a typical EJB-based design
 
 
 
 
Search WWH ::




Custom Search