Java Reference
In-Depth Information
for (SeatType type : seatTypes) {
for (int ii = 0; ii < type.getQuantity(); ii++)
{
final Seat seat = new Seat();
seat.setBooked(false);
seat.setSeatType(type);
seatDao.persist(seat);
}
}
}
public void bookSeat(long seatId) {
final Seat seat = seatDao.find(seatId);
seat.setBooked(true);
seatDao.persist(seat);
seatEventSrc.fire(seat);
}
public void doCleanUp() {
seatDao.deleteAll();
seatTypeDao.deleteAll();
}
}
Tip
Why has this component been coded as an EJB instead of a CDI Bean?
One of the main advantages of using EJBs is that they are inherently transactional com-
ponents. However, in Java EE 7, we can use CDI Beans with an additional @Transac-
tional annotation. The choice now is up to the developer, but EJBs can still prove use-
ful in some cases, even for local calls; for example, we can easily demarcate security for
them (which we will do in the future chapters).
This service is made up of four methods. The first is the createSeatType method,
which will be used in the first application screen to add a new SeatType object to our
theatre. The next method, createTheatre , will be invoked once we are done with set-
ting up our theatre; so we create the list of seats that will be available for booking in the
next screen.
Search WWH ::




Custom Search