|
@@ -1,16 +1,18 @@ |
1 |
1 |
|
package businessLogic; |
2 |
2 |
|
|
3 |
3 |
|
import java.util.Date; |
|
4 |
+ |
import java.util.Vector; |
4 |
5 |
|
|
5 |
6 |
|
import com.db4o.ObjectContainer; |
6 |
7 |
|
import com.db4o.ObjectSet; |
7 |
8 |
|
|
8 |
9 |
|
import dataAccess.DB4oManager; |
9 |
10 |
|
import domain.Booking; |
|
11 |
+ |
import domain.Offer; |
|
12 |
+ |
import domain.Owner; |
10 |
13 |
|
import domain.RuralHouse; |
11 |
14 |
|
import exceptions.OfferCanNotBeBooked; |
12 |
15 |
|
|
13 |
|
- |
|
14 |
16 |
|
public final class BookingManager { |
15 |
17 |
|
|
16 |
18 |
|
private int bookingNumber = 0; |
|
@@ -25,38 +27,59 @@ |
25 |
27 |
|
e.printStackTrace(); |
26 |
28 |
|
} |
27 |
29 |
|
} |
28 |
|
- |
|
|
30 |
+ |
|
29 |
31 |
|
/** |
30 |
|
- |
* This method returns the next Booking number |
|
32 |
+ |
* This method returns the next Booking number |
31 |
33 |
|
* |
32 |
34 |
|
* @return the book number |
33 |
35 |
|
*/ |
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 |
|
- |
|
|
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 |
+ |
|
43 |
45 |
|
/** |
44 |
|
- |
* This method returns the instance of the BookingManager class |
|
46 |
+ |
* This method returns the instance of the BookingManager class |
45 |
47 |
|
* |
46 |
48 |
|
* @return the booking manager |
47 |
49 |
|
*/ |
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(); |
|
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(); |
57 |
60 |
|
return theBookingManager; |
58 |
61 |
|
} |
59 |
|
- |
|
|
62 |
+ |
|
|
63 |
+ |
public void removeBooking(Booking B) { |
|
64 |
+ |
// TODO |
|
65 |
+ |
|
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
public Vector<Booking> getAllBookings(Owner ow) { |
|
69 |
+ |
Vector<Booking> books = new Vector<Booking>(); |
|
70 |
+ |
for (RuralHouse rh : ow.getRuralHouses()) { |
|
71 |
+ |
Vector<Offer> off = rh.getAllOffers(); |
|
72 |
+ |
for (Offer of : off) { |
|
73 |
+ |
System.out.print(of.toString()); |
|
74 |
+ |
if (of.getBooking() != null) { |
|
75 |
+ |
|
|
76 |
+ |
books.add(of.getBooking()); |
|
77 |
+ |
} |
|
78 |
+ |
} |
|
79 |
+ |
} |
|
80 |
+ |
return books; |
|
81 |
+ |
} |
|
82 |
+ |
|
60 |
83 |
|
/** |
61 |
84 |
|
* This method creates a book with a corresponding parameters |
62 |
85 |
|
* |
|
@@ -64,10 +87,12 @@ |
64 |
87 |
|
* day, last day, house number and telephone |
65 |
88 |
|
* @return a book |
66 |
89 |
|
*/ |
67 |
|
- |
public Booking createBooking(RuralHouse ruralHouse, Date firstDate, Date lastDate, String bookTelephoneNumber) |
|
90 |
+ |
public Booking createBooking(RuralHouse ruralHouse, Date firstDate, |
|
91 |
+ |
Date lastDate, String bookTelephoneNumber) |
68 |
92 |
|
throws OfferCanNotBeBooked { |
69 |
93 |
|
|
70 |
|
- |
return dbMngr.createBooking(ruralHouse,firstDate,lastDate,bookTelephoneNumber); |
|
94 |
+ |
return dbMngr.createBooking(ruralHouse, firstDate, lastDate, |
|
95 |
+ |
bookTelephoneNumber); |
71 |
96 |
|
} |
72 |
|
- |
|
|
97 |
+ |
|
73 |
98 |
|
} |