Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard

Diff Revisions 6a5d4d ... vs 4f8bcc ... for ruralHouses/src/businessLogic/BookingManager.java

Diff revisions: vs.
  @@ -1,12 +1,13 @@
1 1 package businessLogic;
2 2
3 + import java.rmi.RemoteException;
4 + import java.rmi.server.UnicastRemoteObject;
3 5 import java.util.Date;
4 6 import java.util.Vector;
5 7
6 - import javax.mail.MessagingException;
7 -
8 8 import com.db4o.ObjectContainer;
9 9 import com.db4o.ObjectSet;
10 + import common.BookingInterface;
10 11
11 12 import dataAccess.DB4oManager;
12 13 import domain.Booking;
  @@ -14,14 +15,21 @@
14 15 import domain.RuralHouse;
15 16 import exceptions.OfferCanNotBeBooked;
16 17
17 - public final class BookingManager {
18 18
19 +
20 + public final class BookingManager extends UnicastRemoteObject implements BookingInterface {
21 +
22 + /**
23 + *
24 + */
25 + private static final long serialVersionUID = 1L;
19 26 private int bookingNumber = 0;
20 27 dataAccess.DB4oManager dbMngr;
21 28
22 29 private static BookingManager theBookingManager;
23 30
24 - public BookingManager() {
31 + public BookingManager() throws RemoteException {
32 + super();
25 33 try {
26 34 this.dbMngr = DB4oManager.getInstance();
27 35 } catch (Exception e) {
  @@ -34,52 +42,54 @@
34 42 *
35 43 * @return the book number
36 44 */
37 - public static int getNumber() {
38 - ObjectContainer db = DB4oManager.getContainer();
39 - BookingManager b = getInstance();
40 - b.bookingNumber++;
41 - db.store(b);
42 - db.commit();
43 - return b.bookingNumber;
44 - }
45 45
46 + public int getNumber() throws RemoteException{
47 + ObjectContainer db=DB4oManager.getContainer();
48 + BookingManager b=getInstance();
49 + b.bookingNumber++;
50 + db.store(b);
51 + db.commit();
52 + return b.bookingNumber;
53 + }
54 +
46 55 /**
47 56 * This method returns the instance of the BookingManager class
48 57 *
49 58 * @return the booking manager
59 + * @throws RemoteException
50 60 */
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);
58 - db.commit();
59 - } else
60 - theBookingManager = (BookingManager) result.next();
61 +
62 + public BookingManager getInstance() throws RemoteException {
63 + ObjectContainer db=DB4oManager.getContainer();
64 + BookingManager b = new BookingManager();
65 + ObjectSet<BookingManager> result = db.queryByExample(b);
66 + if (!result.hasNext()){
67 + theBookingManager = new BookingManager();
68 + db.store(theBookingManager);
69 + db.commit();
70 + } else theBookingManager=(BookingManager)result.next();
61 71 return theBookingManager;
62 72 }
63 73
64 - public void removeDenyBooking(Booking b){
74 + public void removeDenyBooking(Booking b) throws RemoteException{
65 75 b.getOffer().getBookings().remove(b);
66 76 this.dbMngr.removeBooking(b);
67 77 }
68 78
69 79
70 - public void acceptBooking(Booking b){
80 + public void acceptBooking(Booking b) throws RemoteException{
71 81 b.getOffer().setBooked(true);
72 82 for(Booking boo : b.getOffer().getBookings()){
73 83 if(!boo.equals(b))
74 84 b.getOffer().getBookings().remove(b);
75 85 }
76 86 this.dbMngr.acceptBooking(b.getOffer());
77 - try {
87 + /*try {
78 88 MailManager.getInstance().Send(b.getClient().getMailAccount(), "Your booking has been accepted","Here should be the bill");
79 89 } catch (MessagingException e) {
80 90 // TODO Auto-generated catch block
81 91 e.printStackTrace();
82 - }
92 + }*/
83 93
84 94 }
85 95 /**
  @@ -91,7 +101,7 @@
91 101 */
92 102 public Vector<Booking> createBooking(RuralHouse ruralHouse, Date firstDate,
93 103 Date lastDate, Client client)
94 - throws OfferCanNotBeBooked {
104 + throws OfferCanNotBeBooked,RemoteException {
95 105
96 106 return dbMngr.createBooking(ruralHouse, firstDate, lastDate,
97 107 client);