The Duke's Bank Application
Duke's bank has two clients: a web client used by customers and an application client used by administrators.
The end-user clients access only the session beans. Within the enterprise bean tier, the session beans use Java Persistence entities.
Session Beans
The Duke's Bank application has three session beans: CustomerControllerBean, TxControllerBean, TxControllerBean.
The AccountControllerBean Session Bean
has business methods which perform tasks that creating and removing entities, managing the account-customer relationship and getting the account information.
Using createAccount and removeAccount to create and remove entities.
call create and remove methods of the Account entity.
Using addCustomerToAccount and removeCustomerFromAccount to manage the account-customer relationship
创建账户之前,先用em的find方法去找有没有这个客户,添加客户到账户之前,也用em的find去找存不存在这个账户或客户,存在之后再用Account类里的addCustomer的方法去将账户和客户连接上。
先去数据库里找存在数据与否,再调用entity里的方法进行操作。
Using getAccountsOfCustomer and getDetails to get the account information.
The CustomerControllerBean Session Bean
A client create a Customer entity by invoking the createCustomer method of the CustomerControllerBean session bean and calls the removeCustomer method to remove a customer (invokes em.remove method on the Customer instance).
Using get methods.
The TxControllerBean Session Bean
In addition to its get methods, this session bean has several methods that change the balances of the bank account: withdraw, deposit, makeCharge, makePayment, transferFunds.
transferFunds method: checks the account type and new balance; subtracts from the balance of one Account instance and adds the same amount to another instance. Both of these steps must complete to ensure data interfrity. If either step falis, the entire operation is rolled back and the balances remain unchanged. The transferFunds method, like all methods in session beans that use container-managed transaction demarcation, hac an implicit Required transaction attribute. That's no need to explicitly docorate the method with a @TransactionAttribute annotation.
Java Persistence Entities
Account
Customer
Tx
purpose of these entities: to provide an object view of these database tables: bank_account, bank_customer, bank_tx.
The enterprise bean container manages all data in the underlying data source, including adding updating and deleting data from the database tables.
Helper Classes
The EJb JAR files include several helper classes that are used by the enterprise beans.
Such as: AccountDetails, CustomerDetails...
Database Tables
Protecting the Enterprise Beans
There are two different roles: bankCustomer and bankAdmin.
不同的角色可以做的事不同,access的session bean也不同
@RolesAllowed
Application Client
bankAdmin登入 查看客户信息 查看账户信息等
在bankAdmin class里,GUI controls,与CustomerTextFields的一些操作,set/fill/clear/reset等,以及对Account的一些操作,调用GUI去改变,更新accounts和customers。
Web Client
-
如果在web端声明EJB:
Building, Packaging, Deploying, and Running the Duke's Bank Application
configuration files for creating the EAR, dukesbank.ear. The EAR consists of the following three modules: dukesbank-application: The application client/dukesbank-ejb: The enterprise beans and persistence entities/dukesbank-war: The web client
在部署之前,database tables就已经被创建和populated了。