Java Reference
In-Depth Information
@Stateless
public class PlaceOrderFacadeImpl
implements PlaceOrderFacade {
@EJB
private RestaurantRepository restaurantRepository;
@EJB
private PlaceOrderFacadeResultFactory resultFactory;
@EJB
private PlaceOrderService service;
public PlaceOrderFacadeImpl() {
}
public PlaceOrderFacadeImpl(
RestaurantRepository restaurantRepository,
PlaceOrderService service,
PlaceOrderFacadeResultFactory resultFactory) {
this.restaurantRepository = restaurantRepository;
this.service = service;
this.resultFactory = resultFactory;
}
The restaurantRepository , resultFactory , and service fields have an @EJB
annotation that tells the EJB container to initialize the field with the referenced
session bean. Note that even though the EJB container initializes the fields using
dependency injection, the bean class must still have a constructor for use by the mock
object tests, which cannot access the private fields. As you can see, PlaceOrder-
FacadeImpl has a constructor that takes the RestaurantRepository , PlaceOrder-
ResultFactory , and PlaceOrderService as parameters and initializes the fields.
Annotating the domain service
The PlaceOrderService , which is the domain service called by the PlaceOrder-
Facade , is configured as a session bean using the @Local and @Stateless annota-
tions. Here is the bean class:
@Stateless
public class PlaceOrderServiceImpl implements
PlaceOrderService {
@EJB
private PendingOrderRepository pendingOrderRepository;
@EJB
private RestaurantRepository restaurantRepository;
public PlaceOrderServiceImpl() {
 
 
Search WWH ::




Custom Search