1 package ejava.examples.txhotel.blimpl;
2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.List;
6
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import ejava.examples.txhotel.bl.HotelReservationException;
11 import ejava.examples.txhotel.bl.HotelReservationSession;
12 import ejava.examples.txhotel.bl.HotelReservationist;
13 import ejava.examples.txhotel.bo.Person;
14 import ejava.examples.txhotel.bo.Reservation;
15
16
17
18
19
20
21 public class HotelReservationSessionImpl implements HotelReservationSession {
22 private static final Logger log = LoggerFactory.getLogger(HotelReservationSessionImpl.class);
23 private List<Reservation> pending = new ArrayList<Reservation>();
24 private HotelReservationist reservationist;
25
26 public void createReservation(Person person, Date startDate, Date endDate)
27 throws HotelReservationException {
28 pending.add(new Reservation(0,0,null,person, startDate, endDate));
29 log.debug("added pending reservation, size=" + pending.size());
30 }
31
32 public void cancelReservations() throws HotelReservationException {
33 }
34
35 public List<Reservation> commit() throws HotelReservationException {
36 log.info("************ creating " + pending.size() + " reservations ***");
37 List<Reservation> commited = new ArrayList<Reservation>();
38 for(Reservation p: pending) {
39 Reservation c = reservationist.createReservation(
40 p.getPerson(), p.getStartDate(), p.getEndDate());
41 log.debug("created reservation:" + c);
42 commited.add(c);
43 }
44 log.debug("returning " + commited.size() + " reservations");
45 return commited;
46 }
47
48 public void setReservationist(HotelReservationist reservationist) {
49 this.reservationist = reservationist;
50 }
51
52 @Override
53 public void close() {
54 }
55 }