4 import java.util.Vector;
6 import javax.mail.MessagingException;
8 import com.db4o.ObjectContainer;
9 import com.db4o.ObjectSet;
11 import dataAccess.DB4oManager;
12 import domain.Booking;
14 import domain.RuralHouse;
15 import exceptions.OfferCanNotBeBooked;
17 public final class BookingManager {
19 private int bookingNumber = 0;
20 dataAccess.DB4oManager dbMngr;
22 private static BookingManager theBookingManager;
24 public BookingManager() {
26 this.dbMngr = DB4oManager.getInstance();
27 } catch (Exception e) {
33 * This method returns the next Booking number
35 * @return the book number
37 public static int getNumber() {
38 ObjectContainer db = DB4oManager.getContainer();
39 BookingManager b = getInstance();
43 return b.bookingNumber;
47 * This method returns the instance of the BookingManager class
49 * @return the booking manager
51 public static BookingManager getInstance() {
52 ObjectContainer db = DB4oManager.getContainer();
53 BookingManager b = new BookingManager();
54 ObjectSet<BookingManager> result = db.queryByExample(b);
55 if (!result.hasNext()) {
56 theBookingManager = new BookingManager();
57 db.store(theBookingManager);
60 theBookingManager = (BookingManager) result.next();
61 return theBookingManager;
64 public void removeDenyBooking(Booking b){
65 b.getOffer().getBookings().remove(b);
66 this.dbMngr.removeBooking(b);
70 public void acceptBooking(Booking b){
71 b.getOffer().setBooked(true);
72 for(Booking boo : b.getOffer().getBookings()){
74 b.getOffer().getBookings().remove(b);
76 this.dbMngr.acceptBooking(b.getOffer());
78 MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
79 } catch (MessagingException e) {
80 // TODO Auto-generated catch block
86 * This method creates a book with a corresponding parameters
89 * day, last day, house number and telephone
92 public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
93 Date lastDate, Client client)
94 throws OfferCanNotBeBooked {
96 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,