import configuration.ConfigXML;
import domain.Account;
import domain.Booking;
+import domain.HouseFeatures;
import domain.Offer;
//import dataModel.Offer;
import domain.Owner;
private static DB4oManager theDB4oManager = null;
private static DB4oManagerAux theDB4oManagerAux;
+
static ConfigXML c;
private DB4oManager() throws Exception {
try {
Owner jon = new Owner("Jon");
Owner alfredo = new Owner("Alfredo");
- jon.addRuralHouse("Ezkio", "Ezkioko etxea", "Ezkio", 3, 3, 3, 3, 3);
- jon.addRuralHouse("Eskia", "Eskiatzeko etxea", "Jaca", 4, 4, 4, 4, 4);
+ jon.addRuralHouse("Ezkioko", "Ezkioko etxea", "Ezkio", 3, 3, 3, 3, 3);
+ jon.addRuralHouse("Eskiatze", "Eskiatzeko etxea", "Jaca", 4, 4, 4, 4, 4);
jon.setBankAccount("1349 5677 21 2133567777");
alfredo.addRuralHouse("Aitonako", "Casa del abuelo", "Pitillas", 5, 5, 5, 5,
5);
}
}
+ public void deleteDB() {
+
+ if (c.isDatabaseLocal() == false)
+ openSDB();
+ else
+ openDB();
+
+ try {
+ Owner proto = new Owner(null, null);
+ ObjectSet result = db.queryByExample(proto);
+ Vector<Owner> owners = new Vector<Owner>();
+ 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 {
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<Owner> owners = new Vector<Owner>();
- 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
return stored;
}
- public void removeHouse(RuralHouse rh) {
+
+ public void removeHouse(RuralHouse rh, Owner owner) {
if (c.isDatabaseLocal() == false)
openSDB();
ObjectSet<RuralHouse> result = db.queryByExample(rh);
if (!result.isEmpty()) {
RuralHouse found = (RuralHouse) result.get(0);
+// db.delete(found.getOwner());
+ db.store(owner);
db.delete(found);
db.commit();
}
+ }
+
+ public Vector<RuralHouse> getRuralHouses(String town,int nBed , int nKit, int nBath, int nPark, int nLiv){
+ HouseFeatures fea = new HouseFeatures(nBed,nKit,nBath,nLiv,nPark);
+ RuralHouse rh = new RuralHouse(null,null,null,town,fea);
+ if (c.isDatabaseLocal() == false)
+ openSDB();
+ else
+ openDB();
+
+ try{
+ ObjectSet<RuralHouse> result = db.queryByExample(rh);
+ Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>();
+ while(result.hasNext())
+ ruralHouses.add(result.next());
+ db.close();
+ return ruralHouses;
+ } catch (NullPointerException e){
+ return null;
+ }
+
+
+
}
}