X-Git-Url: https://xp-dev.com/git/RRRRHHHH_Code/blobdiff_plain/4a7ae817ba8bb731d49df10c66118da5a5379017..95c4ffa3b7cff5936ea7766233f63ddc3c3adc69:/ruralHouses/src/dataAccess/DB4oManager.java diff --git a/ruralHouses/src/dataAccess/DB4oManager.java b/ruralHouses/src/dataAccess/DB4oManager.java index 039dd62..40fe83c 100644 --- a/ruralHouses/src/dataAccess/DB4oManager.java +++ b/ruralHouses/src/dataAccess/DB4oManager.java @@ -130,6 +130,29 @@ public class DB4oManager { } } + public void deleteDB() { + + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + + try { + Owner proto = new Owner(null, null); + ObjectSet result = db.queryByExample(proto); + Vector owners = new Vector(); + while (result.hasNext()) { + Owner o = (Owner) result.next(); + System.out.println("Deleted owner: " + o.toString()); + db.delete(o); + } + db.commit(); + } finally { + db.close(); + } + } + + @SuppressWarnings("finally") public Offer createOffer(RuralHouse ruralHouse, Date firstDay, Date lastDay, float price) throws RemoteException, Exception { @@ -162,27 +185,49 @@ public class DB4oManager { return o; } - public void deleteDB() { + @SuppressWarnings("finally") + public Offer modifyOffer(Offer offer) throws RemoteException, Exception { + if (c.isDatabaseLocal() == false) + openSDB(); + else + openDB(); + + try { + + db.store(offer); + db.commit(); + + } catch (com.db4o.ext.ObjectNotStorableException e) { + System.out + .println("Error: com.db4o.ext.ObjectNotStorableException in createOffer"); + } finally { + db.close(); + } + return offer; + } + + @SuppressWarnings("finally") + public void deleteOffer(RuralHouse rh, Offer offer) throws RemoteException, Exception { if (c.isDatabaseLocal() == false) openSDB(); else openDB(); try { - Owner proto = new Owner(null, null); - ObjectSet result = db.queryByExample(proto); - Vector owners = new Vector(); - while (result.hasNext()) { - Owner o = (Owner) result.next(); - System.out.println("Deleted owner: " + o.toString()); - db.delete(o); - } + + db.store(rh); + db.delete(offer); db.commit(); + + } catch (com.db4o.ext.ObjectNotStorableException e) { + System.out + .println("Error: com.db4o.ext.ObjectNotStorableException in createOffer"); } finally { db.close(); } } + /** * This method creates a book with a corresponding parameters