Class HotelReservationSessionEJB

  • All Implemented Interfaces:
    HotelReservationSession, HotelReservationSessionLocal, HotelReservationSessionRemote, SessionSynchronization

    public class HotelReservationSessionEJB
    extends Object
    implements HotelReservationSessionLocal, HotelReservationSessionRemote, SessionSynchronization
    This class provides an example of a stateful session bean wrapper around stateless server calls. In this example case, the user wishes to make several reservations. However, the stateless session bean will commit them to the database one at a time. This wrapper shows how someone could temporarily store them on the server while the entire set is being sanity checked. Once they are good to go, a single transaction is started by the commit() method to invoke the stateless session bean for each transaction. We can easily find tons of fault and areas for improvement with the actual business logic. However, the basic concept is that the stateful session bean can perform some of the actions of the stateless session bean outside of a transaction and then commit the changes as one unit when ready. The instance is thrown away no matter what happens. We could just as easily keep it around and add some edit functions to fix the erroneous information that caused the rollback.

    This bean is deployed 3 times; default configuration, using a transaction Required stateless session bean, and using a tranaction RequiresNew stateless session bean. The test client will try all 3. You'll notice that the one with RequiresNew, will not be able to rollback successful reservations because it operates in a separate transaction. The one with tranaction Required allows all to be rolled back because it joins this tranaction.

    This bean is also configured quite a bit from the ejb-jar.xml file; using less annotations then the other stateless session bean example.

    It implements the javax.ejb.SessionSynchronization interface so that it can listen, impact, or react to the state of the active transaction.