The bug found in the presentation that we forgot to review has been fixed
[RRRRHHHH_Code] / ruralHouses / src / dataAccess / DB4oManager.java
index a424473..fd3c1c5 100644 (file)
@@ -35,9 +35,9 @@ public class DB4oManager {
        private static ObjectContainer db;
        private static EmbeddedConfiguration configuration;
        private static ClientConfiguration configurationCS;
-       private int bookingNumber = 0; // if it is "static" then it is not
+       private int bookingNumber = 1; // if it is "static" then it is not
                                                                        // serialized
-       private int offerNumber = 0; // if it is "static" then it is not serialized
+       private int offerNumber = 1; // if it is "static" then it is not serialized
        private static DB4oManager theDB4oManager = null;
 
        private static DB4oManagerAux theDB4oManagerAux;
@@ -45,7 +45,7 @@ public class DB4oManager {
        static ConfigXML c;
 
        private DB4oManager() throws Exception {
-               theDB4oManagerAux = new DB4oManagerAux(0, 0);
+               theDB4oManagerAux = new DB4oManagerAux(1, 1);
                c = ConfigXML.getInstance();
                System.out.println("Creating DB4oManager instance => isDatabaseLocal: "
                                + c.isDatabaseLocal() + " getDatabBaseOpenMode: "
@@ -470,14 +470,19 @@ public class DB4oManager {
                                null);
                try {
                        ObjectSet<RuralHouse> result = db.queryByExample(house);
+                       Owner own = new Owner(rh.getOwner().getName(),rh.getOwner().getBankAccount(),rh.getOwner().getMailAccount());
+                       Owner ow = (Owner) db.queryByExample(own).get(0);
+                       rh.setOwner(ow);
                        if (result.isEmpty()) {
-                               Owner ow = (Owner) db.queryByExample(rh.getOwner()).get(0);
-                               rh.setOwner(ow);
                                ow.addRuralHouse(rh);
                                db.store(rh);
                                db.commit();
                                stored = true;
                        } else {
+                               ow.getRuralHouses().remove(result.get(0));
+                               result.get(0).setOwner(null);
+                               ow.addRuralHouse(rh);
+                               db.store(result.get(0));
                                db.delete(result.get(0));
                                db.store(rh);
                                db.commit();
@@ -620,8 +625,10 @@ public class DB4oManager {
                                        .getOffer().getOfferNumber(), new RuralHouse(b.getOffer()
                                        .getRuralHouse().getHouseName(), null, null, null, null),
                                        null, null, 0), b.getClient(), b.getBookDate());
-                       book.setOffer(null);
-                       db.delete(book);
+                       Booking delete = (Booking) db.queryByExample(book).get(0);
+                       delete.setOffer(null);
+                       db.store(delete);
+                       db.delete(delete);
                        db.commit();
                } catch (Exception e) {
                        e.printStackTrace();
@@ -639,9 +646,9 @@ public class DB4oManager {
 
                try {
                        Offer of = (Offer) db.queryByExample(
-                                       new Offer(o.getOfferNumber(), new RuralHouse(o
+                                       new Offer(0, new RuralHouse(o
                                                        .getRuralHouse().getHouseName(), null, null, null,
-                                                       null), null, null, 0)).get(0);
+                                                       null), o.getFirstDay(), o.getLastDay(), 0)).get(0);
                        Booking proto = new Booking(0, of, null, null);
                        ObjectSet<Booking> result = db.queryByExample(proto);
                        return new Vector<Booking>(result);