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