House Features added and logic for adding options to the owner
[RRRRHHHH_Code] / ruralHouses / src / dataAccess / DB4oManager.java
index 295af73..26fa6f3 100644 (file)
@@ -79,15 +79,23 @@ public class DB4oManager {
        /**
         * @param rh
         */
-       public void storeRuralHouses(RuralHouse rh) {
+       public boolean storeRuralHouses(RuralHouse rh) {
                DB4oManager.openDatabase("open");
+               boolean stored = false;
                ObjectContainer db = DB4oManager.getContainer();
+               RuralHouse house = new RuralHouse(rh.getHouseNumber(), null, null,
+                               null, null);
                try {
-                       db.store(rh);
-                       db.commit();
+                       ObjectSet<Owner> result = db.queryByExample(house);
+                       if (result.isEmpty()) {
+                               db.store(rh);
+                               db.commit();
+                               stored = true;
+                       }
                } finally {
                        db.close();
                }
+               return stored;
        }
 
        /**
@@ -144,8 +152,7 @@ public class DB4oManager {
                DB4oManager.openDatabase("open");
                ObjectContainer db = DB4oManager.getContainer();
                try {
-                       RuralHouse proto = new RuralHouse(0, null, null, null, 0, 0, 0, 0,
-                                       0);
+                       RuralHouse proto = new RuralHouse(0, null, null, null, null);
                        ObjectSet<RuralHouse> result = db.queryByExample(proto);
                        Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
                        while (result.hasNext())
@@ -171,8 +178,8 @@ public class DB4oManager {
                Offer o;
                try {
                        RuralHouse proto = new RuralHouse(ruralHouse.getHouseNumber(),
-                                       null, ruralHouse.getDescription(), ruralHouse.getTown(), 0,
-                                       0, 0, 0, 0);
+                                       null, ruralHouse.getDescription(), ruralHouse.getTown(),
+                                       ruralHouse.getFeatures());
                        ObjectSet<RuralHouse> result = db.queryByExample(proto);
                        RuralHouse rh = (RuralHouse) result.next();
                        o = rh.createOffer(firstDay, lastDay, price);
@@ -194,7 +201,7 @@ public class DB4oManager {
                try {
                        ObjectContainer db = DB4oManager.getContainer();
                        RuralHouse proto = new RuralHouse(rh.getHouseNumber(), null,
-                                       rh.getDescription(), rh.getTown(), 0, 0, 0, 0, 0);
+                                       rh.getDescription(), rh.getTown(), rh.getFeatures());
                        ObjectSet<RuralHouse> result = db.queryByExample(proto);
                        return rh = (RuralHouse) result.next();
                } catch (Exception exc) {
@@ -231,6 +238,24 @@ public class DB4oManager {
                }
        }
 
+       public void removeHouse(int houseNumber) {
+               ObjectContainer db = DB4oManager.getContainer();
+               RuralHouse house = new RuralHouse(houseNumber, null, null, null, null);
+               try {
+                       ObjectSet<RuralHouse> result = db.queryByExample(house);
+                       if (!result.isEmpty()) {
+                               RuralHouse found = (RuralHouse) result.get(0);
+                               db.delete(found);
+                               db.commit();
+                       }
+               } catch (Exception exc) {
+                       exc.printStackTrace();
+               } finally {
+                       db.close();
+               }
+
+       }
+
        /**
         * This method returns the instance of the DB4oManager class
         *