Java EE tutorial Case Study

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了。

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值