Possibility of registering new owners added
[RRRRHHHH_Code] / ruralHouses / src / businessLogic / BookingManager.java
1 package businessLogic;
2
3 import java.util.Date;
4 import java.util.Vector;
5
6 import com.db4o.ObjectContainer;
7 import com.db4o.ObjectSet;
8
9 import dataAccess.DB4oManager;
10 import domain.Booking;
11 import domain.Offer;
12 import domain.Owner;
13 import domain.RuralHouse;
14 import exceptions.OfferCanNotBeBooked;
15
16 public final class BookingManager {
17
18         private int bookingNumber = 0;
19         dataAccess.DB4oManager dbMngr;
20
21         private static BookingManager theBookingManager;
22
23         public BookingManager() {
24                 try {
25                         this.dbMngr = DB4oManager.getInstance();
26                 } catch (Exception e) {
27                         e.printStackTrace();
28                 }
29         }
30
31         /**
32          * This method returns the next Booking number
33          * 
34          * @return the book number
35          */
36         public static int getNumber() {
37                 ObjectContainer db = DB4oManager.getContainer();
38                 BookingManager b = getInstance();
39                 b.bookingNumber++;
40                 db.store(b);
41                 db.commit();
42                 return b.bookingNumber;
43         }
44
45         /**
46          * This method returns the instance of the BookingManager class
47          * 
48          * @return the booking manager
49          */
50         public static BookingManager getInstance() {
51                 ObjectContainer db = DB4oManager.getContainer();
52                 BookingManager b = new BookingManager();
53                 ObjectSet<BookingManager> result = db.queryByExample(b);
54                 if (!result.hasNext()) {
55                         theBookingManager = new BookingManager();
56                         db.store(theBookingManager);
57                         db.commit();
58                 } else
59                         theBookingManager = (BookingManager) result.next();
60                 return theBookingManager;
61         }
62
63         public void removeBooking(Booking B) {
64                 // TODO
65
66         }
67
68
69         /**
70          * This method creates a book with a corresponding parameters
71          * 
72          * @param First
73          *            day, last day, house number and telephone
74          * @return a book
75          */
76         public Booking createBooking(RuralHouse ruralHouse, Date firstDate,
77                         Date lastDate, String bookTelephoneNumber)
78                         throws OfferCanNotBeBooked {
79
80                 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
81                                 bookTelephoneNumber);
82         }
83
84 }