Java Reference
In-Depth Information
LISTING 3-2 (continued)
}
package com.devchronicles.facade;
import javax.ejb.Stateless;
@Stateless
public class AccountService {
public boolean getLoan(double amount) {
// check if bank vault has enough
return true;
}
public boolean setCustomerBalance(long id, double amount) {
// set new customer balance
return true;
}
}
You can group these service EJB in a logical collection of related functionality to form an
implementation of the façade pattern, such as in Listing 3‐3.
LISTING 3‐3: Implementation of the stateless façade
package com.devchronicles.facade;
import javax.ejb.Stateless;
import javax.inject.Inject;
@Stateless
public class BankServiceFacade {
@Inject
CustomerService customerService;
@Inject
LoanService loanService;
@Inject
AccountService accountService;
public boolean getLoan(int sessionId, double amount) {
boolean result = false;
long id = customerService.getCustomer(sessionId);
if(customerService.checkId(id)){
if(loanService.checkCreditRating(id, amount)){
if(accountService.getLoan(amount)){
result = accountService.setCustomerBalance(id, amount);
}
}
}
return result;
}
}
Search WWH ::




Custom Search